[TASK] Skip tests that rely on internet connection 45/23445/5
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 29 Aug 2013 09:54:36 +0000 (11:54 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 29 Aug 2013 16:24:35 +0000 (18:24 +0200)
Some tests in GeneralUtilityTest rely on a working internet
connection and fail if offline. Skip those tests if no needed.

Change-Id: Ia5e828cee6a834b971ad8d9c7da0598867a275f8
Resolves: #51496
Releases: 6.2
Reviewed-on: https://review.typo3.org/23445
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index d88df8f..4a89ffb 100644 (file)
@@ -57,6 +57,22 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
        }
 
+       /**
+        * Helper method to test for an existing internet connection.
+        * Some tests are skipped if there is no working uplink.
+        *
+        * @return boolean $isConnected
+        */
+       public function isConnected() {
+               $isConnected = FALSE;
+               $connected = @fsockopen('typo3.org', 80);
+               if ($connected) {
+                       $isConnected = TRUE;
+                       fclose($connected);
+               }
+               return $isConnected;
+       }
+
        ///////////////////////////
        // Tests concerning _GP
        ///////////////////////////
@@ -2565,10 +2581,14 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        ///////////////////////////
        // Tests concerning getUrl
        ///////////////////////////
+
        /**
         * @test
         */
        public function getUrlWithAdditionalRequestHeadersProvidesHttpHeaderOnError() {
+               if (!$this->isConnected()) {
+                       $this->markTestSkipped('No internet connection detected');
+               }
                $url = 'http://typo3.org/i-do-not-exist-' . time();
                $report = array();
                Utility\GeneralUtility::getUrl($url, 0, array(), $report);
@@ -2579,6 +2599,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getUrlProvidesWithoutAdditionalRequestHeadersHttpHeaderOnError() {
+               if (!$this->isConnected()) {
+                       $this->markTestSkipped('No internet connection detected');
+               }
                $url = 'http://typo3.org/i-do-not-exist-' . time();
                $report = array();
                Utility\GeneralUtility::getUrl($url, 0, FALSE, $report);
@@ -4172,4 +4195,4 @@ text with a ' . $urlMatch . '$|s'),
 
 }
 
-?>
\ No newline at end of file
+?>