Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1403638
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 25, 8:06 AM
Size
9 KB
Mime Type
text/x-diff
Expires
Fri, Feb 27, 8:06 AM (1 d, 9 h)
Engine
blob
Format
Raw Data
Handle
899371
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/5.2.x/core/tests/Unit/kernel/globalsTest.php
===================================================================
--- branches/5.2.x/core/tests/Unit/kernel/globalsTest.php (revision 16869)
+++ branches/5.2.x/core/tests/Unit/kernel/globalsTest.php (revision 16870)
@@ -1,184 +1,184 @@
<?php
/**
* The class name must match the file name for Phabricator-invoked PHPUnit to run this test.
*
* TODO: Once "globals.php" file is renamed we can rename this class/filename as well.
*/
class globalsTest extends AbstractTestCase // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
{
/**
* @dataProvider netMatchDataOnlineProvider
*/
public function testNetMatchOnline($network, $expected)
{
static $ip;
if ( !$this->hasInternetConnectivity() ) {
$this->markTestSkipped('No Internet Connection.');
}
if ( $ip === null ) {
$ip = gethostbyname('www.in-portal.org');
}
$this->assertSame($expected, kUtil::netMatch($network, $ip));
}
protected function hasInternetConnectivity()
{
- // Use IP of the "www.google.com" hostname to avoid DNS query, that might fail.
+ // Use IP of the Cloudflare DNS hostname to avoid DNS query, that might fail.
$error_code = $error_message = null;
- $fp = @fsockopen('142.250.74.36', 443, $error_code, $error_message, 5);
+ $fp = @fsockopen('1.1.1.1', 443, $error_code, $error_message, 5);
if ( $fp ) {
fclose($fp);
return true;
}
return false;
}
public static function netMatchDataOnlineProvider()
{
return array(
// Hosts.
'matched' => array('www.in-portal.org', true),
'unmatched' => array('www.yahoo.com', false),
);
}
/**
* @dataProvider netMatchDataOfflineProvider
*/
public function testNetMatchOffline($network, $ip, $expected)
{
$this->assertSame($expected, kUtil::netMatch($network, $ip));
}
public static function netMatchDataOfflineProvider()
{
return array(
// IPv4 address vs IPv4 network.
array('1.2.3.4', '1.2.3.4', true),
array('1.2.3.4', '1.2.3.5', false),
array('1.2.3.32-1.2.3.54', '1.2.3.40', true),
array('1.2.3.32-1.2.3.54', '1.2.3.64', false),
array('1.2.3.32/27', '1.2.3.35', true),
array('1.2.3.32/27', '1.2.3.64', false),
array('1.2.3/27', '1.2.3.5', true),
array('1.2.3/27', '1.2.3.33', false),
array('1.2.3.32/255.255.255.224', '1.2.3.35', true),
array('1.2.3.32/255.255.255.224', '1.2.3.64', false),
array('1.2.3.32/27', '1.2.3.4.6', false),
// IPv6 address vs IPv6 network.
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9893', true),
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9895', false),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9894', true),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9896', false),
array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe8::9895', true),
array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe9::9895', false),
// IPv6 address vs IPv4 network.
array('1.2.3.4', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32-1.2.3.54', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32/255.255.255.224', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
// IPv4 address vs IPv6 network.
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '1.2.3.4', false),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '1.2.3.4', false),
array('971a:6ff4:3fe8::9893/64', '1.2.3.4', false),
);
}
/**
* @dataProvider validKg2PoundsDataProvider
*/
public function testValidKg2Pounds($kg, $pounds_only, $expected_pounds, $expected_ounces)
{
list($pounds, $ounces) = kUtil::Kg2Pounds($kg, $pounds_only);
$this->assertSame($expected_pounds, $pounds);
$this->assertSame($expected_ounces, $ounces);
}
public static function validKg2PoundsDataProvider()
{
return array(
'pounds_only=false' => array(0.68039, false, 1.0, 8.0),
'pounds_only=true' => array(0.68039, true, 1.5, 0),
);
}
public function testExceptionKg2Pounds()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The $kg argument isn\'t a number.');
kUtil::Kg2Pounds(null);
}
/**
* @dataProvider validPounds2KgDataProvider
*/
public function testValidPounds2Kg($pounds, $ounces, $expected)
{
$this->assertSame($expected, kUtil::Pounds2Kg($pounds, $ounces));
}
public static function validPounds2KgDataProvider()
{
return array(
'pounds <> 0, ounces <> 0' => array(1.0, 8.0, 0.68039),
'pounds <> 0, ounces = 0' => array(1.5, 0.0, 0.68039),
'pounds = 0, ounces <> 0' => array(0.0, 8.0, 0.2268),
'pounds = 0, ounces = 0' => array(0.0, 0.0, 0.0),
);
}
/**
* @dataProvider exceptionPounds2KgDataProvider
*/
public function testExceptionPounds2Kg($pounds, $ounces)
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Either the $pounds or $ounces argument isn\'t a number.');
kUtil::Pounds2Kg($pounds, $ounces);
}
public static function exceptionPounds2KgDataProvider()
{
return array(
'pounds non-numeric, ounces numeric' => array(null, 8),
'pounds numeric, ounces non-numeric' => array(1, null),
'both pounds and ounces non-numeric' => array(null, null),
);
}
/**
* @dataProvider convertPathToRelativeDataProvider
*/
public function testConvertPathToRelative($absolute_path, $prefix, $expected_relative_path)
{
$this->assertSame($expected_relative_path, kUtil::convertPathToRelative($absolute_path, $prefix));
}
public static function convertPathToRelativeDataProvider()
{
return array(
'double full path (without prefix)' => array(FULL_PATH . FULL_PATH, '', FULL_PATH),
'top folder (without prefix)' => array(FULL_PATH . '/test', '', '/test'),
'subfolder (without prefix)' => array(FULL_PATH . '/test/subfolder', '', '/test/subfolder'),
'unrelated folder (without prefix)' => array('/other/test/subfolder', '', '/other/test/subfolder'),
'double full path (with prefix)' => array(FULL_PATH . FULL_PATH, '...', '...' . FULL_PATH),
'top folder (with prefix)' => array(FULL_PATH . '/test', '...', '.../test'),
'subfolder (with prefix)' => array(FULL_PATH . '/test/subfolder', '...', '.../test/subfolder'),
'unrelated folder (with prefix)' => array('/other/test/subfolder', '...', '/other/test/subfolder'),
);
}
}
Index: branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php
===================================================================
--- branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php (revision 16869)
+++ branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php (revision 16870)
@@ -1,95 +1,95 @@
<?php
class DebuggerUtilTest extends AbstractTestCase
{
/**
* @dataProvider netMatchDataOnlineProvider
*/
public function testNetMatchOnline($network, $expected)
{
static $ip;
if ( !$this->hasInternetConnectivity() ) {
$this->markTestSkipped('No Internet Connection.');
}
if ( $ip === null ) {
$ip = gethostbyname('www.in-portal.org');
}
$this->assertSame($expected, DebuggerUtil::netMatch($network, $ip));
}
protected function hasInternetConnectivity()
{
- // Use IP of the "www.google.com" hostname to avoid DNS query, that might fail.
+ // Use IP of the Cloudflare DNS hostname to avoid DNS query, that might fail.
$error_code = $error_message = null;
- $fp = @fsockopen('142.250.74.36', 443, $error_code, $error_message, 5);
+ $fp = @fsockopen('1.1.1.1', 443, $error_code, $error_message, 5);
if ( $fp ) {
fclose($fp);
return true;
}
return false;
}
public static function netMatchDataOnlineProvider()
{
return array(
// Hosts.
'matched' => array('www.in-portal.org', true),
'unmatched' => array('www.yahoo.com', false),
);
}
/**
* @dataProvider netMatchDataOfflineProvider
*/
public function testNetMatchOffline($network, $ip, $expected)
{
$this->assertSame($expected, DebuggerUtil::netMatch($network, $ip));
}
public static function netMatchDataOfflineProvider()
{
return array(
// IPv4 address vs IPv4 network.
array('1.2.3.4', '1.2.3.4', true),
array('1.2.3.4', '1.2.3.5', false),
array('1.2.3.32-1.2.3.54', '1.2.3.40', true),
array('1.2.3.32-1.2.3.54', '1.2.3.64', false),
array('1.2.3.32/27', '1.2.3.35', true),
array('1.2.3.32/27', '1.2.3.64', false),
array('1.2.3/27', '1.2.3.5', true),
array('1.2.3/27', '1.2.3.33', false),
array('1.2.3.32/255.255.255.224', '1.2.3.35', true),
array('1.2.3.32/255.255.255.224', '1.2.3.64', false),
array('1.2.3.32/27', '1.2.3.4.6', false),
// IPv6 address vs IPv6 network.
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9893', true),
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9895', false),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9894', true),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9896', false),
array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe8::9895', true),
array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe9::9895', false),
// IPv6 address vs IPv4 network.
array('1.2.3.4', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32-1.2.3.54', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
array('1.2.3.32/255.255.255.224', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
// IPv4 address vs IPv6 network.
array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '1.2.3.4', false),
array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '1.2.3.4', false),
array('971a:6ff4:3fe8::9893/64', '1.2.3.4', false),
);
}
}
Event Timeline
Log In to Comment