Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/51213


Change subject: Add test to check if all resource files are accessible via http
......................................................................

Add test to check if all resource files are accessible via http

This is to ensure that during phpunit testing any anomaly is
caught before deployement and any inaccessible file is being flagged.

Change-Id: I150d5dc3beac38c0f0f15a4b053274c843186624
---
M SemanticResultFormats.hooks.php
A tests/phpunit/ResourceTest.php
2 files changed, 114 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticResultFormats 
refs/changes/13/51213/1

diff --git a/SemanticResultFormats.hooks.php b/SemanticResultFormats.hooks.php
index 534ff3c..4d93d93 100644
--- a/SemanticResultFormats.hooks.php
+++ b/SemanticResultFormats.hooks.php
@@ -42,6 +42,10 @@
        public static function registerUnitTests( array &$files ) {
                // Keep this in alphabetical order please!
                $testFiles = array(
+
+                       'Resource',
+
+                       // Formats
                        'formats/Array',
                        'formats/Dygraphs',
                        'formats/EventCalendar',
diff --git a/tests/phpunit/ResourceTest.php b/tests/phpunit/ResourceTest.php
new file mode 100644
index 0000000..c4a61af
--- /dev/null
+++ b/tests/phpunit/ResourceTest.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace SRF\Test;
+
+use ResourceLoader;
+use ResourceLoaderModule;
+use ResourceLoaderContext;
+
+/**
+ * Tests for the Resource files
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @since 1.9
+ *
+ * @ingroup SRF
+ * @ingroup Test
+ *
+ * @group SRF
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+class ResourceTest extends \MediaWikiTestCase {
+
+       /**
+        * Helper method to load resources only valid for this extension
+        *
+        */
+       private function load(){
+               global $srfgIP;
+               return include( $srfgIP . "/Resources.php" );
+       }
+
+       /**
+        * DataProvider
+        *
+        */
+       public function moduleDataProvider() {
+               $resourceLoader = new ResourceLoader();
+               $context = ResourceLoaderContext::newDummyContext();
+               $modules = $this->load();
+
+               return array( array( $modules, $resourceLoader, $context ) );
+       }
+
+       /**
+        * Test scripts accessibility
+        *
+        * @dataProvider moduleDataProvider
+        */
+       public function testModulesScriptsFilesAreAccessible( $modules, 
$resourceLoader, $context ){
+
+               foreach ( $modules as $name => $values ){
+
+                       // Get module details
+                       $module = $resourceLoader->getModule( $name );
+
+                       // Get scripts url per module
+                       $scripts = $module->getScriptURLsForDebug( $context );
+
+                       // Check if the url will be accessible by reading the 
first byte of the file
+                       foreach ( $scripts as $url ){
+                               //  Only try read 1 byte
+                               //  Use @ to suppress any warnings
+                               $this->assertTrue( is_string( 
@file_get_contents( $url, 0, null, 0, 1 ) ) );
+                       }
+               }
+       }
+
+       /**
+        * Test styles accessibility
+        *
+        * @dataProvider moduleDataProvider
+        */
+       public function testModulesStylesFilesAreAccessible( $modules, 
$resourceLoader, $context  ){
+
+               foreach ( $modules as $name => $values ){
+
+                       // Get module details
+                       $module = $resourceLoader->getModule( $name );
+
+                       // Get styles url per module
+                       $styles = $module->getStyleURLsForDebug( $context );
+
+                       // Check if the url will be accessible by reading the 
first byte of the file
+                       foreach ( $styles as $urls ){
+                               foreach ( $urls as $url ){
+                                       //  Only try to read 1 byte
+                                       $this->assertTrue( is_string( 
@file_get_contents( $url, 0, null, 0, 1 ) ) );
+                               }
+                       }
+               }
+       }
+
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/51213
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I150d5dc3beac38c0f0f15a4b053274c843186624
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticResultFormats
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to