Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51273
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 testing any anomaly is caught before
deployement and an inaccessible file is being flagged.
Change-Id: Id74144945cbc1a3405f53c5cc8d5925671b02ef7
---
M SemanticMediaWiki.hooks.php
A tests/phpunit/resources/ResourcesTest.php
2 files changed, 113 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/73/51273/1
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 6d62288..309f0d4 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -287,6 +287,8 @@
'printers/ResultPrinters',
+ 'resources/Resources',
+
// Keep store tests near the end, since they are slower
due to database access.
'storage/Store',
diff --git a/tests/phpunit/resources/ResourcesTest.php
b/tests/phpunit/resources/ResourcesTest.php
new file mode 100644
index 0000000..33934eb
--- /dev/null
+++ b/tests/phpunit/resources/ResourcesTest.php
@@ -0,0 +1,111 @@
+<?php
+
+namespace SMW\Test;
+
+use ResourceLoader;
+use ResourceLoaderModule;
+use ResourceLoaderContext;
+
+/**
+ * Tests for resource definitions and 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 SMW
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+class ResourcesTest extends \MediaWikiTestCase {
+
+ /**
+ * Helper method to load resources only valid for this extension
+ *
+ */
+ private function load(){
+ global $smwgIP, $smwgScriptPath;
+ return include( $smwgIP . "/resources/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/51273
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id74144945cbc1a3405f53c5cc8d5925671b02ef7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits