Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1167400
D541.id.diff
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
Tue, Sep 23, 11:27 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Wed, Sep 24, 11:27 AM (14 h, 24 m)
Engine
blob
Format
Raw Data
Handle
756168
Attached To
D541: INP-1924 - Immediately skip tests, that doesn't work without an Internet Connection
D541.id.diff
View Options
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
Log In to Comment