Page MenuHomeIn-Portal Phabricator

D541.id.diff
No OneTemporary

File Metadata

Created
Tue, Sep 23, 11:27 AM

D541.id.diff

Index: branches/5.2.x/core/tests/Unit/kernel/globalsTest.php
===================================================================
--- branches/5.2.x/core/tests/Unit/kernel/globalsTest.php
+++ branches/5.2.x/core/tests/Unit/kernel/globalsTest.php
@@ -9,22 +9,58 @@
{
/**
- * @dataProvider netMatchDataProvider
+ * @dataProvider netMatchDataOnlineProvider
*/
- public function testNetMatch($network, $ip, $expected)
+ 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));
}
- public static function netMatchDataProvider()
+ protected function hasInternetConnectivity()
{
- $ip_from_host = gethostbyname('www.in-portal.org');
+ // Use IP of the "www.google.com" 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);
+
+ if ( $fp ) {
+ fclose($fp);
+
+ return true;
+ }
+ return false;
+ }
+
+ public static function netMatchDataOnlineProvider()
+ {
return array(
// Hosts.
- array('www.in-portal.org', $ip_from_host, true),
- array('www.yahoo.com', $ip_from_host, false),
+ '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),
Index: branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php
===================================================================
--- branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php
+++ branches/5.2.x/core/tests/Unit/kernel/utility/DebuggerUtilTest.php
@@ -5,22 +5,58 @@
{
/**
- * @dataProvider netMatchDataProvider
+ * @dataProvider netMatchDataOnlineProvider
*/
- public function testNetMatch($network, $ip, $expected)
+ 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));
}
- public static function netMatchDataProvider()
+ protected function hasInternetConnectivity()
{
- $ip_from_host = gethostbyname('www.in-portal.org');
+ // Use IP of the "www.google.com" 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);
+
+ if ( $fp ) {
+ fclose($fp);
+ return true;
+ }
+
+ return false;
+ }
+
+ public static function netMatchDataOnlineProvider()
+ {
return array(
// Hosts.
- array('www.in-portal.org', $ip_from_host, true),
- array('www.yahoo.com', $ip_from_host, false),
+ '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),

Event Timeline