Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -1,16 +1,23 @@
<?php
//define('OBS_DEBUG', 1);
//define('OBS_DEBUG', 2);
$base_dir = realpath(__DIR__ . '/..');
$config['install_dir'] = $base_dir;
include(__DIR__ . '/../includes/defaults.inc.php');
//include(dirname(__FILE__) . '/../config.php'); // Do not include user editable config here
include(__DIR__ . "/../includes/polyfill.inc.php");
include(__DIR__ . "/../includes/autoloader.inc.php");
include(__DIR__ . "/../includes/debugging.inc.php");
require_once(__DIR__ ."/../includes/constants.inc.php");
include(__DIR__ . '/../includes/common.inc.php');
include(__DIR__ . '/data/test_definitions.inc.php'); // Fake definitions for testing
include(__DIR__ . '/../includes/definitions.inc.php');
include(__DIR__ . '/../includes/functions.inc.php');
if (is_file(__DIR__ . '/data/config.php')) {
include(__DIR__ . '/data/config.php'); // I.e. for API keys
}
/**
* @backupGlobals disabled
@ -223,73 +230,174 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
);
}
/**
* @dataProvider providerIntAdd
* @group numbers
*/
public function testIntAdd($a, $b, $result)
{
$this->assertSame($result, int_add($a, $b));
}
public function providerIntAdd()
{
// $a = "18446742978492891134"; $b = "0"; $sum = gmp_add($a, $b); echo gmp_strval($sum) . "\n"; // Result: 18446742978492891134
// $a = "18446742978492891134"; $b = "0"; $sum = $a + $b; printf("%.0f\n", $sum); // Result: 18446742978492891136
if (OBS_MATH === 'php')
{
// Fallback (inaccurate math)
$array = array(
array( '18446742978492891134', '0', '18446742978492891136'),
array('-18446742978492891134', '0', '-18446742978492891136'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782272'),
array('-18446742978492891134', '18446742978492891134', '0'),
);
} else {
// Accurate math
$array = array(
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782268'),
array('-18446742978492891134', '18446742978492891134', '0'),
);
/**
* @dataProvider providerIntAdd
* @group numbers
*/
public function testIntAdd($a, $b, $result) {
$this->assertSame($result, int_add($a, $b));
}
return $array;
}
/**
* @dataProvider providerIntSub
* @group numbers
*/
public function testIntSub($a, $b, $result)
{
$this->assertSame($result, int_sub($a, $b));
}
public function providerIntAdd() {
// $a = "18446742978492891134"; $b = "0"; $sum = gmp_add($a, $b); echo gmp_strval($sum) . "\n"; // Result: 18446742978492891134
// $a = "18446742978492891134"; $b = "0"; $sum = $a + $b; printf("%.0f\n", $sum); // Result: 18446742978492891136
// Accurate math
return [
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '36893485956985782268'),
array('-18446742978492891134', '18446742978492891134', '0'),
public function providerIntSub()
{
if (OBS_MATH === 'php')
{
// Fallback (inaccurate math)
$array = array(
array( '18446742978492891134', '0', '18446742978492891136'),
array('-18446742978492891134', '0', '-18446742978492891136'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782272'),
// Floats
[ '1111111111111111111111111.6', 0, '1111111111111111111111112' ],
[ 0, '1111111111111111111111111.6', '1111111111111111111111112' ],
[ '18446742978492891134.3', '18446742978492891134.6', '36893485956985782269' ],
);
} else {
// Accurate math
$array = array(
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782268'),
);
// numbers with comma
[ '7,619,627.6010', 0, '7619628' ],
[ 0, '7,619,627.6010', '7619628' ],
];
}
/**
* @dataProvider providerIntSub
* @group numbers
*/
public function testIntSub($a, $b, $result) {
$this->assertSame($result, int_sub($a, $b));
}
public function providerIntSub() {
// Accurate math
return [
array( '18446742978492891134', '0', '18446742978492891134'),
array('-18446742978492891134', '0', '-18446742978492891134'),
array( '18446742978492891134', '18446742978492891134', '0'),
array('-18446742978492891134', '18446742978492891134', '-36893485956985782268'),
// Floats
[ '1111111111111111111111111.6', 0, '1111111111111111111111112' ],
[ 0, '1111111111111111111111111.6', '-1111111111111111111111112' ],
[ '-18446742978492891134.3', '18446742978492891134.6', '-36893485956985782269' ],
// numbers with comma
[ '7,619,627.6010', 0, '7619628' ],
[ 0, '7,619,627.6010', '-7619628' ],
];
}
/**
* @dataProvider providerFloatDiv
* @group numbers
*/
public function testFloatDiv($a, $b, $result) {
if (method_exists($this, 'assertEqualsWithDelta')) {
$this->assertEqualsWithDelta($result, float_div($a, $b), 0.00001);
} else {
$this->assertSame($result, float_div($a, $b));
}
}
public function providerFloatDiv() {
// Accurate math
return [
[ '18446742978492891134', '0', 0 ],
[ '-18446742978492891134', '0', 0 ],
[ '18446742978492891134', '18446742978492891134', 1.0 ],
[ '-18446742978492891134', '18446742978492891134', -1.0 ],
// Floats
[ '1111111111111111111111111.6', 0, 0 ],
[ 0, '1111111111111111111111111.6', 0 ],
[ '18446742978492891134.3', '18446742978492891134.6', 1.0 ],
// numbers with comma
[ '7,619,627.6010', 0, 0 ],
[ 0, '7,619,627.6010', 0 ],
[ '1,192.0036', 6.3, 189.20692 ]
];
}
/**
* @dataProvider providerFloatPow
* @group numbers
*/
public function testFloatPow($a, $b, $result) {
if (method_exists($this, 'assertEqualsWithDelta')) {
$this->assertEqualsWithDelta($result, float_pow($a, $b), 0.00001);
} else {
$this->assertSame($result, float_pow($a, $b));
}
}
public function providerFloatPow() {
// Accurate math
return [
[ '18446742978492891134', '0', 1.0 ],
[ '-18446742978492891134', '0', 1.0 ],
[ '0', '18446742978492891134', 0 ],
[ '0', '-18446742978492891134', 0 ],
// negative power
[ 0, -1, 0 ],
[ 0, -1.1, 0 ],
// Floats
[ '11.6', 0, 1.0 ],
[ 0, '11.6', 0 ],
[ '34.3', '4.6', 11543910.531516898 ],
// numbers with comma
[ '7,619,627.6010', 0, 1.0 ],
[ 0, '7,619,627.6010', 0 ],
[ '1,192.0036', 1.3, 9980.696216867238 ]
];
}
/**
* @dataProvider providerHexToFloat
* @group numbers
*/
public function testHexToFloat($hex, $result)
{
$this->assertSame($result, hex2float($hex));
}
public function providerHexToFloat()
{
// Accurate math
$array = [
[ '429241f0', 73.1287841796875 ],
];
return $array;
}
/**
* @dataProvider providerIeeeIntToFloat
* @group numbers
*/
public function testIeeeIntToFloat($int, $result)
{
$this->assertSame($result, ieeeint2float($int));
}
public function providerIeeeIntToFloat()
{
$array = [
[ 1070575314, 1.6225225925445557 ],
[ 2998520959, -2.1629828594882383E-8 ],
[ '1070575314', 1.6225225925445557 ],
[ hexdec('429241f0'), 73.1287841796875 ],
[ 0, 0.0 ],
];
return $array;
}
return $array;
}
/**
* @dataProvider providerIsHexString
@ -297,7 +405,7 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
*/
public function testIsHexString($string, $result)
{
$this->assertSame($result, isHexString($string));
$this->assertSame($result, is_hex_string($string));
}
public function providerIsHexString()
@ -329,6 +437,8 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
array('Input 1', '496e7075742031'),
array('J}4=', '4a7d343d'),
array('Simple String', '53696d706c6520537472696e67'),
array('PC$rnu', '504324726e75'),
array('Pärnu', '50c3a4726e75'),
);
return $results;
}
@ -584,6 +694,44 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
return $results;
}
/**
* @dataProvider providerGetBitsStateArray
* @group states_bits
*/
/* WiP
public function testGetBitsStateArray($hex, $mib, $object, $result)
{
$this->assertSame($result, get_bits_state_array($hex, $mib, $object));
}
public function providerGetBitsStateArray()
{
$results = array(
array('40 00', 'CISCO-STACK-MIB', 'portAdditionalOperStatus', [ 1 => 'connected' ]), // CISCO-STACK-MIB::portAdditionalOperStatus.1.1 = BITS: 40 00 connected(1)
);
return $results;
}
*/
/**
* @dataProvider providerGetBitsStateArray2
* @group states_bits
*/
/* WiP
public function testGetBitsStateArray2($hex, $def, $result)
{
$this->assertSame($result, get_bits_state_array($hex, NULL, NULL, $def));
}
public function providerGetBitsStateArray2()
{
$results = array(
array('40 00', [], [ 1 => 'connected' ]), // CISCO-STACK-MIB::portAdditionalOperStatus.1.1 = BITS: 40 00 connected(1)
);
return $results;
}
*/
/**
* @dataProvider providerPriorityStringToNumeric
*/
@ -910,44 +1058,44 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
return $array;
}
/**
* @dataProvider providerGetIpType
* @group ip
*/
public function testGetIpType($ip, $result)
{
$this->assertSame($result, get_ip_type($ip));
}
public function providerGetIpType()
{
return array(
array('0.0.0.0', 'unspecified'),
array('::', 'unspecified'),
array('10.255.255.255/32', 'private'), // Do not set /31 and /32 as broadcast!
array('10.255.255.255/31', 'private'), // Do not set /31 and /32 as broadcast!
array('10.255.255.255/8', 'broadcast'),
array('127.0.0.1', 'loopback'),
array('::1', 'loopback'),
array('0:0:0:0:0:0:0:1/128', 'loopback'),
array('10.12.0.3', 'private'),
array('172.16.1.1', 'private'),
array('192.168.0.3', 'private'),
array('fdf8:f53b:82e4::53', 'private'),
array('0:0:0:0:0:ffff:c000:22f', 'ipv4mapped'),
array('::ffff:192.0.2.47', 'ipv4mapped'),
array('77.222.50.30', 'unicast'),
array('2a02:408:7722:5030::5030', 'unicast'),
array('169.254.2.47', 'link-local'),
array('fe80::200:5aee:feaa:20a2', 'link-local'),
array('2001:0000:4136:e378:8000:63bf:3fff:fdd2', 'teredo'),
array('198.18.0.1', 'benchmark'),
array('2001:0002:0:6C::430', 'benchmark'),
array('2001:10:240:ab::a', 'orchid'),
array('1:0002:6c::430', 'reserved'),
array('ff02::1:ff8b:4d51/0', 'multicast'),
);
}
/**
* @dataProvider providerGetIpType
* @group ip
*/
public function testGetIpType($ip, $result) {
$this->assertSame($result, get_ip_type($ip));
}
public function providerGetIpType() {
return [
[ '0.0.0.0', 'unspecified' ],
[ '::', 'unspecified' ],
[ '10.255.255.255/32', 'private' ], // Do not set /31 and /32 as broadcast!
[ '10.255.255.255/31', 'private' ], // Do not set /31 and /32 as broadcast!
[ '10.255.255.255/8', 'broadcast' ],
[ '127.0.0.1', 'loopback' ],
[ '::1', 'loopback' ],
[ '0:0:0:0:0:0:0:1/128', 'loopback' ],
[ '10.12.0.3', 'private' ],
[ '172.16.1.1', 'private' ],
[ '192.168.0.3', 'private' ],
[ 'fdf8:f53b:82e4::53', 'private' ],
[ '100.80.76.30', 'cgnat' ],
[ '100.105.0.49', 'cgnat' ],
[ '0:0:0:0:0:ffff:c000:22f', 'ipv4mapped' ],
[ '::ffff:192.0.2.47', 'ipv4mapped' ],
[ '77.222.50.30', 'unicast' ],
[ '2a02:408:7722:5030::5030', 'unicast' ],
[ '169.254.2.47', 'link-local' ],
[ 'fe80::200:5aee:feaa:20a2', 'link-local' ],
[ '2001:0000:4136:e378:8000:63bf:3fff:fdd2', 'teredo' ],
[ '198.18.0.1', 'benchmark' ],
[ '2001:0002:0:6C::430', 'benchmark' ],
[ '2001:10:240:ab::a', 'orchid' ],
[ '1:0002:6c::430', 'reserved' ],
[ 'ff02::1:ff8b:4d51/0', 'multicast' ],
];
}
/**
* @dataProvider providerMatchNetwork
@ -971,7 +1119,7 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
"10.11.30.0/23", "10.11.32.0/24", "10.11.33.0/24", "10.11.34.0/24", "10.11.41.0/24", "10.11.42.0/24",
"10.11.43.0/24", "10.11.51.0/24", "10.11.52.0/24", "10.11.53.0/24", "10.11.61.0/24", "10.11.62.0/24");
$results = array(
return array(
// Only IPv4 nets
array(TRUE, '127.0.0.1', $nets1),
array(FALSE, '1.1.1.1', $nets1), // not in ranges
@ -1006,12 +1154,51 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
// Are you stupid? YES :)
array(FALSE, '172.16.6.6', $nets6),
array(FALSE, 'FE80:FFFF:0:FFFF:129:144:52:38', $nets6),
// Issue test
// Issues test
array(FALSE, '10.52.25.254', $nets8),
array(TRUE, '10.52.25.254', [ '!217.66.159.18' ]),
array(FALSE, '217.66.159.18', [ '!217.66.159.18' ]),
array(TRUE, '217.66.159.18', [ '217.66.159.18' ]),
);
return $results;
}
/**
* @dataProvider providerStringQuoted
* @group string
*/
/* WIP
public function testStringQuoted($string, $result)
{
$this->assertSame($result, is_string_quoted($string));
}
public function providerStringQuoted()
{
return array(
array('\"sdfslfkm s\'fdsf" a;lm aamjn ', FALSE),
array('sdfslfkm s\'fdsf" a;lm aamjn \"', FALSE),
array('sdfslfkm s\'fdsf" a;lm aamjn ', FALSE),
array('\"sdfslfkm s\'fdsf" a;lm aamjn \"', TRUE),
array('"sdfslfkm s\'fdsf" a;lm aamjn "', TRUE),
array('"\"sdfslfkm s\'fdsf" a;lm aamjn \""', TRUE),
array('\'\"sdfslfkm s\'fdsf" a;lm aamjn \"\'', TRUE),
array(' \'\"sdfslfkm s\'fdsf" a;lm aamjn \"\' ', TRUE),
array('"""sdfslfkm s\'fdsf" a;lm aamjn """', TRUE),
array('"""sdfslfkm s\'fdsf" a;lm aamjn """"""""', TRUE),
array('"""""""sdfslfkm s\'fdsf" a;lm aamjn """', TRUE),
// escaped quotes
array('\"Mike Stupalov\" <mike@observium.org>', FALSE),
// utf-8
array('Avenue Léon, België ', FALSE),
array('\"Avenue Léon, België \"', TRUE),
array('"Винни пух и все-все-все "', TRUE),
// multilined
array(' \'\"\"sdfslfkm s\'fdsf"
a;lm aamjn \"\"\' ', TRUE),
);
}
*/
/**
* @dataProvider providerStringTransform
* @group string
@ -1222,55 +1409,53 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
$array3),
);
}
/**
* @dataProvider providerIsPingable
* @group network
*/
public function testIsPingable($result, $hostname, $try_a = TRUE)
{
if (!is_executable($GLOBALS['config']['fping']))
{
// CentOS 6.8
$GLOBALS['config']['fping'] = '/usr/sbin/fping';
$GLOBALS['config']['fping6'] = '/usr/sbin/fping6';
}
$flags = OBS_DNS_ALL;
if (!$try_a) { $flags ^= OBS_DNS_A; }
$ping = is_pingable($hostname, $flags);
$ping = is_numeric($ping) && $ping > 0; // Function return random float number
$this->assertSame($result, $ping);
}
public function providerIsPingable()
{
$array = array(
array(TRUE, 'localhost'),
array(TRUE, '127.0.0.1'),
array(FALSE, 'yohoho.i.butylka.roma'),
array(FALSE, '127.0.0.1', FALSE), // Try ping IPv4 with IPv6 disabled
);
$cmd = $GLOBALS['config']['fping6'] . " -c 1 -q ::1 2>&1";
exec($cmd, $output, $return); // Check if we have IPv6 support in current system
if ($return === 0)
{
// IPv6 only
//$array[] = array(TRUE, 'localhost', FALSE);
$array[] = array(TRUE, '::1', FALSE);
$array[] = array(FALSE, '::ffff', FALSE);
foreach (array('localhost', 'ip6-localhost') as $hostname)
{
// Debian used ip6-localhost instead localhost.. lol
$ip = gethostbyname6($hostname, OBS_DNS_AAAA);
if ($ip)
{
$array[] = array(TRUE, $hostname, FALSE);
//var_dump($hostname);
break;
/**
* @dataProvider providerIsPingable
* @group network
*/
public function testIsPingable($hostname, $result, $try_a = TRUE) {
if (!is_executable($GLOBALS['config']['fping'])) {
// CentOS 6.8
$GLOBALS['config']['fping'] = '/usr/sbin/fping';
$GLOBALS['config']['fping6'] = '/usr/sbin/fping6';
}
}
if ($try_a) {
$ping = is_pingable($hostname);
} else {
$ping = is_pingable($hostname, 'ipv6');
}
$ping = is_numeric($ping) && $ping > 0; // Function returns random float number
$this->assertSame($result, $ping);
}
public function providerIsPingable() {
$array = [
[ 'localhost', TRUE ],
[ '127.0.0.1', TRUE ],
[ 'yohoho.i.butylka.roma', FALSE ],
[ '127.0.0.1', FALSE, FALSE ], // Try ping IPv4 with IPv6 only
];
$cmd = $GLOBALS['config']['fping6'] . " -c 1 -q ::1 2>&1";
exec($cmd, $output, $return); // Check if we have IPv6 support in a current system
if ($return === 0) {
// IPv6 only
$array[] = [ '::1', TRUE, FALSE ];
$array[] = [ '::ffff', FALSE, FALSE ];
foreach ([ 'localhost', 'ip6-localhost' ] as $hostname) {
// Debian used ip6-localhost instead localhost.. lol
if ($ip = gethostbyname6($hostname, 'ipv6')) {
$array[] = [ $hostname, TRUE, FALSE ];
//var_dump($hostname);
break;
}
}
}
return $array;
}
return $array;
}
/**
* @dataProvider providerCalculateMempoolProperties
@ -1341,6 +1526,194 @@ class IncludesFunctionsTest extends \PHPUnit\Framework\TestCase
);
return $results;
}
/**
* @dataProvider providerGetGeolocation
* @group geo
*/
public function testGetGeolocation($address, $result, $api = 'geocodefarm', $geo_db = [], $dns_only = FALSE)
{
if ($api === 'geocodefarm' || $api === 'openstreetmap' ||
!empty($GLOBALS['config']['geo_api'][$api]['key'])) {
$GLOBALS['config']['geocoding']['dns'] = $dns_only;
$GLOBALS['config']['geocoding']['api'] = $api;
$test = get_geolocation($address, $geo_db, $dns_only);
unset($test['location_updated'], $test['location_status']);
$this->assertSame($result, $test);
}
}
public function providerGetGeolocation()
{
$array = [];
// DNS LOC (reverse)
$location = 'qwerty';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'San Francisco', 'location_county' => 'Unknown', 'location_state' => 'California', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'geocodefarm';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'Mission District', 'location_county' => 'San Francisco', 'location_state' => 'CA', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_country' => 'United States', 'location_state' => 'California', 'location_county' => 'San Francisco', 'location_city' => 'SoMa' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'mapquest';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'San Francisco', 'location_county' => 'San Francisco', 'location_state' => 'CA', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
$api = 'bing';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.7749289, 'location_lon' => -122.4194178,
'location_city' => 'Mission District', 'location_county' => 'San Francisco', 'location_state' => 'California', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api, [ 'hostname' => 'loc-degree.observium.dev' ], TRUE ]; // reverse, dns only
// Location (reverse)
$location = 'Some location [47.616380;-122.341673]';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.61638, 'location_lon' => -122.341673,
'location_city' => 'Seattle', 'location_county' => 'King', 'location_state' => 'Washington', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api ];
$location = 'Some location|\'47.616380\'|\'-122.341673\'';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.61638, 'location_lon' => -122.341673,
'location_city' => 'Seattle', 'location_county' => 'King', 'location_state' => 'Washington', 'location_country' => 'United States' ];
$array[] = [ $location, $result, $api ];
// First request (forward)
$location = 'Badenerstrasse 569, Zurich, Switzerland';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.3832766, 'location_lon' => 8.4955511,
'location_city' => 'Zurich', 'location_county' => 'District Zurich', 'location_state' => 'Zurich', 'location_country' => 'Switzerland' ];
$array[] = [ $location, $result, $api ];
$location = 'Nikhef, Amsterdam, NL';
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lon' => 4.892557, 'location_lat' => 52.373057,
'location_country' => 'Netherlands', 'location_state' => 'North Holland', 'location_county' => 'North Holland', 'location_city' => 'Amsterdam' ];
$array[] = [ $location, $result, $api ];
$location = 'Korea_Seoul';
$api = 'mapquest';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.55886, 'location_lon' => 126.99989,
'location_city' => 'Seoul', 'location_county' => 'South Korea', 'location_state' => 'Unknown', 'location_country' => 'South Korea' ];
$array[] = [ $location, $result, $api ];
// Second request (forward)
$location = 'ZRH2, Badenerstrasse 569, Zurich, Switzerland';
$api = 'openstreetmap';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 47.3832766, 'location_lon' => 8.4955511,
'location_city' => 'Zurich', 'location_county' => 'District Zurich', 'location_state' => 'Zurich', 'location_country' => 'Switzerland' ];
$array[] = [ $location, $result, $api ];
$location = 'Rack: NK-76 - Nikhef, Amsterdam, NL';
$api = 'yandex';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lon' => 4.892557, 'location_lat' => 52.373057,
'location_country' => 'Netherlands', 'location_state' => 'North Holland', 'location_county' => 'North Holland', 'location_city' => 'Amsterdam' ];
$array[] = [ $location, $result, $api ];
$location = 'Korea_Seoul';
$api = 'bing';
$result = [ 'location' => $location, 'location_geoapi' => $api,
'location_lat' => 37.5682945, 'location_lon' => 126.9977875,
'location_city' => 'Seoul', 'location_county' => 'Unknown', 'location_state' => 'Seoul', 'location_country' => 'South Korea' ];
$array[] = [ $location, $result, $api ];
return $array;
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithValidConditions()
{
$conditions = [
'column1 = "value1"',
'',
' ',
'column2 > 10'
];
$additional_conditions = [
'column3 < 50',
'column4 LIKE "%example%"'
];
$expected = ' WHERE column1 = "value1" AND column2 > 10 AND column3 < 50 AND column4 LIKE "%example%"';
$result = generate_where_clause($conditions, $additional_conditions);
$this->assertEquals($expected, $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithOnlyEmptyConditions()
{
$conditions = [
'',
' ',
"\t",
"\n"
];
$result = generate_where_clause($conditions);
//$this->assertNull($result);
$this->assertEquals('', $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithSingleCondition()
{
$conditions = [
'column1 = "value1"'
];
$expected = ' WHERE column1 = "value1"';
$result = generate_where_clause($conditions);
$this->assertEquals($expected, $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithNoConditions()
{
$conditions = [];
$result = generate_where_clause($conditions);
//$this->assertNull($result);
$this->assertEquals('', $result);
}
/**
* @group sql
*/
public function testGenerateWhereClauseWithOnlyAdditionalConditions()
{
$conditions = [];
$additional_conditions = [
'column1 = "value1"',
'column2 > 10'
];
$expected = ' WHERE column1 = "value1" AND column2 > 10';
$result = generate_where_clause($conditions, $additional_conditions);
$this->assertEquals($expected, $result);
}
}
// EOF