Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/65006
Change subject: Move test registration (PHPUnit, QUnit) into separate files
......................................................................
Move test registration (PHPUnit, QUnit) into separate files
Separate functional from operationl registration process
Change-Id: I9764a78a75e8904097a3cab80abf6cb2cceca620
---
M SemanticMediaWiki.hooks.php
M SemanticMediaWiki.php
A SemanticMediawiki.phpunit.tests.php
A SemanticMediawiki.qunit.tests.php
M includes/Setup.php
M tests/phpunit/includes/HooksTest.php
A tests/phpunit/includes/UnitTestsListTest.php
7 files changed, 289 insertions(+), 196 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/06/65006/1
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 7be5ac8..5cc64d4 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -230,130 +230,6 @@
}
/**
- * Hook to add PHPUnit test cases.
- * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
- *
- * @since 1.8
- *
- * @param array $files
- *
- * @return boolean
- */
- public static function registerUnitTests( array &$files ) {
- $testFiles = array(
- 'Defines',
- 'GlobalFunctions',
- 'FormatFactory',
- 'Highlighter',
- 'ObservableMessageReporter',
- 'ParserData',
- 'Subobject',
- 'RecurringEvents',
- 'Infolink',
- 'Hooks',
- 'DataValueFactory',
- 'Settings',
- 'ParserTextProcessor',
- 'Factbox',
-
- 'formatters/ParserParameterFormatter',
-
- 'api/ApiSMWInfo',
- 'api/ApiAsk',
-
- 'query/QueryProcessor',
-
- 'dataitems/DI_Blob',
- 'dataitems/DI_Bool',
- 'dataitems/DI_Number',
- 'dataitems/DI_GeoCoord',
- 'dataitems/DISerializer',
- 'dataitems/DIConcept',
-
- 'export/SMWExpElement',
-
- 'parserhooks/SubobjectParserFunction',
- 'parserhooks/RecurringEventsParserFunction',
- 'parserhooks/AskParserFunction',
- 'parserhooks/ShowParserFunction',
- 'parserhooks/ConceptParserFunction',
- 'parserhooks/DeclareParserFunction',
- 'parserhooks/DocumentationParserFunction',
- 'parserhooks/InfoParserFunction',
- 'parserhooks/SetParserFunction',
-
- 'query/QueryData',
-
- 'printers/ResultPrinters',
- 'printers/AggregatablePrinter',
-
- 'resources/Resources',
-
- 'specials/Specials',
-
- // Keep store tests near the end, since they are slower
due to database access.
- 'storage/Store',
-
- 'storage/sqlstore/PropertyStatisticsTable',
- );
-
- foreach ( $testFiles as $file ) {
- $files[] = dirname( __FILE__ ) .
'/tests/phpunit/includes/' . $file . 'Test.php';
- }
-
- return true;
- }
-
- /**
- * Add new JavaScript/QUnit testing modules
- * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
- *
- * @since 1.9
- *
- * @param array $testModules array of JavaScript testing modules
- * @param ResourceLoader $resourceLoader object
- *
- * @return boolean
- */
- public static function registerQUnitTests( array &$testModules,
ResourceLoader &$resourceLoader ) {
- $testModules['qunit']['ext.smw.tests'] = array(
- 'scripts' => array(
- 'tests/qunit/smw/ext.smw.test.js',
-
'tests/qunit/smw/util/ext.smw.util.tooltip.test.js',
-
- // dataItem tests
-
'tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.uri.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.time.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.property.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.unknown.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.number.test.js',
-
'tests/qunit/smw/data/ext.smw.dataItem.text.test.js',
-
- // dataValues
-
'tests/qunit/smw/data/ext.smw.dataValue.quantity.test.js',
-
- // Api / Query
- 'tests/qunit/smw/data/ext.smw.data.test.js',
- 'tests/qunit/smw/api/ext.smw.api.test.js',
- 'tests/qunit/smw/query/ext.smw.query.test.js',
- ),
- 'dependencies' => array(
- 'ext.smw',
- 'ext.smw.tooltip',
- 'ext.smw.query',
- 'ext.smw.data',
- 'ext.smw.api'
- ),
- 'position' => 'top',
- 'localBasePath' => __DIR__,
- 'remoteExtPath' => 'SemanticMediaWiki',
- );
-
- return true;
- }
-
- /**
* Hook: GetPreferences adds user preference
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
*
diff --git a/SemanticMediaWiki.php b/SemanticMediaWiki.php
index b51f532..3f131ea 100644
--- a/SemanticMediaWiki.php
+++ b/SemanticMediaWiki.php
@@ -109,4 +109,13 @@
'alt' => 'Powered by Semantic MediaWiki',
);
-$smwgNamespace = parse_url( $wgServer, PHP_URL_HOST );
\ No newline at end of file
+$smwgNamespace = parse_url( $wgServer, PHP_URL_HOST );
+
+// Register PHPUnit tests
+$wgHooks['UnitTestsList'][] = require_once __DIR__ . '/' .
'SemanticMediawiki.phpunit.tests.php';
+
+// Register QUnit tests
+$wgHooks['ResourceLoaderTestModules'][] = function ( array &$testModules,
\ResourceLoader &$resourceLoader ) {
+ $testModules['qunit']['ext.smw.tests'] = include( __DIR__ . '/' .
'SemanticMediawiki.qunit.tests.php' );
+ return true;
+};
diff --git a/SemanticMediawiki.phpunit.tests.php
b/SemanticMediawiki.phpunit.tests.php
new file mode 100644
index 0000000..896e174
--- /dev/null
+++ b/SemanticMediawiki.phpunit.tests.php
@@ -0,0 +1,96 @@
+<?php
+
+/**
+ * File that contains registration for the PHPUnit tests
+ *
+ * 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
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup SMW
+ * @codeCoverageIgnore
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+return call_user_func( function() {
+ $files = array();
+
+ $testFiles = array(
+ 'Defines',
+ 'GlobalFunctions',
+ 'FormatFactory',
+ 'Highlighter',
+ 'ObservableMessageReporter',
+ 'ParserData',
+ 'Subobject',
+ 'RecurringEvents',
+ 'Infolink',
+ 'Hooks',
+ 'DataValueFactory',
+ 'Settings',
+ 'ParserTextProcessor',
+ 'Factbox',
+ 'UnitTestsList',
+
+ 'formatters/ParserParameterFormatter',
+
+ 'api/ApiSMWInfo',
+ 'api/ApiAsk',
+
+ 'query/QueryProcessor',
+
+ 'dataitems/DI_Blob',
+ 'dataitems/DI_Bool',
+ 'dataitems/DI_Number',
+ 'dataitems/DI_GeoCoord',
+ 'dataitems/DISerializer',
+ 'dataitems/DIConcept',
+
+ 'export/SMWExpElement',
+
+ 'parserhooks/SubobjectParserFunction',
+ 'parserhooks/RecurringEventsParserFunction',
+ 'parserhooks/AskParserFunction',
+ 'parserhooks/ShowParserFunction',
+ 'parserhooks/ConceptParserFunction',
+ 'parserhooks/DeclareParserFunction',
+ 'parserhooks/DocumentationParserFunction',
+ 'parserhooks/InfoParserFunction',
+ 'parserhooks/SetParserFunction',
+
+ 'query/QueryData',
+
+ 'printers/ResultPrinters',
+ 'printers/AggregatablePrinter',
+
+ 'resources/Resources',
+
+ 'specials/Specials',
+
+ // Keep store tests near the end, since they are slower due to
database access.
+ 'storage/Store',
+
+ 'storage/sqlstore/PropertyStatisticsTable',
+ );
+
+ foreach ( $testFiles as $file ) {
+ $files[] = __DIR__ . '/tests/phpunit/includes/' . $file .
'Test.php';
+ }
+
+ return $files;
+} );
diff --git a/SemanticMediawiki.qunit.tests.php
b/SemanticMediawiki.qunit.tests.php
new file mode 100644
index 0000000..d77a58e
--- /dev/null
+++ b/SemanticMediawiki.qunit.tests.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * File that contains registration for the QUnit tests
+ *
+ * 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
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup SMW
+ * @codeCoverageIgnore
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+return call_user_func( function() {
+ return array(
+ 'scripts' => array(
+ 'tests/qunit/smw/ext.smw.test.js',
+ 'tests/qunit/smw/util/ext.smw.util.tooltip.test.js',
+
+ // dataItem tests
+
'tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js',
+ 'tests/qunit/smw/data/ext.smw.dataItem.uri.test.js',
+ 'tests/qunit/smw/data/ext.smw.dataItem.time.test.js',
+
'tests/qunit/smw/data/ext.smw.dataItem.property.test.js',
+ 'tests/qunit/smw/data/ext.smw.dataItem.unknown.test.js',
+ 'tests/qunit/smw/data/ext.smw.dataItem.number.test.js',
+ 'tests/qunit/smw/data/ext.smw.dataItem.text.test.js',
+
+ // dataValues
+
'tests/qunit/smw/data/ext.smw.dataValue.quantity.test.js',
+
+ // Api / Query
+ 'tests/qunit/smw/data/ext.smw.data.test.js',
+ 'tests/qunit/smw/api/ext.smw.api.test.js',
+ 'tests/qunit/smw/query/ext.smw.query.test.js',
+ ),
+ 'dependencies' => array(
+ 'ext.smw',
+ 'ext.smw.tooltip',
+ 'ext.smw.query',
+ 'ext.smw.data',
+ 'ext.smw.api'
+ ),
+ 'position' => 'top',
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => 'SemanticMediaWiki',
+ );
+
+} );
diff --git a/includes/Setup.php b/includes/Setup.php
index 4afc4f0..2eb10ec 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -82,10 +82,6 @@
// Alter the structured navigation links in SkinTemplates
$wgHooks['SkinTemplateNavigation'][] =
'SMWHooks::onSkinTemplateNavigation';
- //UnitTests
- $wgHooks['UnitTestsList'][] = 'SMWHooks::registerUnitTests';
- $wgHooks['ResourceLoaderTestModules'][] =
'SMWHooks::registerQUnitTests';
-
// Statistics
$wgHooks['SpecialStatsAddExtra'][] = 'SMWHooks::onSpecialStatsAddExtra';
diff --git a/tests/phpunit/includes/HooksTest.php
b/tests/phpunit/includes/HooksTest.php
index dd373df..b3245b4 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -68,17 +68,6 @@
}
/**
- * Helper method that returns a normalized path
- *
- * @since 1.9
- *
- * @return string
- */
- private function normalizePath( $path ) {
- return str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR,
$path );
- }
-
- /**
* Helper method that returns a random string
*
* @since 1.9
@@ -342,62 +331,6 @@
$result = SMWHooks::onResourceLoaderGetConfigVars( $vars );
$this->assertTrue( $result );
- }
-
- /**
- * @test SMWHooks::registerUnitTests
- *
- * Files are normally registered manually in registerUnitTests(). This
test
- * will compare registered files with the files available in the
- * test directory.
- *
- * @since 1.9
- */
- public function testRegisterUnitTests() {
- $registeredFiles = array();
- $result = SMWHooks::registerUnitTests( $registeredFiles );
-
- $this->assertTrue( $result );
- $this->assertNotEmpty( $registeredFiles );
-
- // Get all the *.php files
- // @see
http://php.net/manual/en/class.recursivedirectoryiterator.php
- $testFiles = new \RegexIterator(
- new \RecursiveIteratorIterator( new
\RecursiveDirectoryIterator( __DIR__ ) ),
- '/^.+\.php$/i',
- \RecursiveRegexIterator::GET_MATCH
- );
-
- // Array contains files that are excluded from verification
because
- // those files do not contain any executable tests and
therefore are
- // not registered (such as abstract classes, mock classes etc.)
- $excludedFiles = array(
- 'dataitems/DataItem',
- 'printers/ResultPrinter'
- );
-
- // Normalize excluded files
- foreach ( $excludedFiles as &$registeredFile ) {
- $registeredFile = $this->normalizePath( __DIR__ . '/' .
$registeredFile . 'Test.php' );
- }
-
- // Normalize registered files
- foreach ( $registeredFiles as &$registeredFile ) {
- $registeredFile = $this->normalizePath( $registeredFile
);
- }
-
- // Compare directory files with registered files
- foreach ( $testFiles as $fileName => $object ){
- $fileName = $this->normalizePath( $fileName );
-
- if ( !in_array( $fileName, $excludedFiles ) ) {
- $this->assertContains(
- $fileName,
- $registeredFiles,
- 'Missing registration for ' . $fileName
- );
- }
- }
}
/**
diff --git a/tests/phpunit/includes/UnitTestsListTest.php
b/tests/phpunit/includes/UnitTestsListTest.php
new file mode 100644
index 0000000..d45e865
--- /dev/null
+++ b/tests/phpunit/includes/UnitTestsListTest.php
@@ -0,0 +1,118 @@
+<?php
+
+namespace SMW\Test;
+
+/**
+ * Tests for the UnitTestsList hooks
+ *
+ * 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
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup SMW
+ * @ingroup Test
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * This class is testing implemented UnitTestsList hooks and cross-checks
+ * available files against the registration list
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class UnitTestsListTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * Returns the name of the class to be tested
+ *
+ * @return string|false
+ */
+ public function getClass() {
+ return false;
+ }
+
+ /**
+ * Helper method that returns a normalized path
+ *
+ * @since 1.9
+ *
+ * @return string
+ */
+ private function normalizePath( $path ) {
+ return str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR,
$path );
+ }
+
+ /**
+ * @test SMWHooks::registerUnitTests
+ *
+ * Files are normally registered manually in registerUnitTests(). This
test
+ * will compare registered files with the files available in the
+ * test directory.
+ *
+ * @since 1.9
+ */
+ public function testUnitTestsList() {
+ $registeredFiles = include( __DIR__ .
'/../../../SemanticMediawiki.phpunit.tests.php' );
+
+ $this->assertInternalType( 'array', $registeredFiles );
+ $this->assertNotEmpty( $registeredFiles );
+
+ // Get all the *.php files
+ // @see
http://php.net/manual/en/class.recursivedirectoryiterator.php
+ $testFiles = new \RegexIterator(
+ new \RecursiveIteratorIterator( new
\RecursiveDirectoryIterator( __DIR__ ) ),
+ '/^.+\.php$/i',
+ \RecursiveRegexIterator::GET_MATCH
+ );
+
+ // Array contains files that are excluded from verification
because
+ // those files do not contain any executable tests and
therefore are
+ // not registered (such as abstract classes, mock classes etc.)
+ $excludedFiles = array(
+ 'dataitems/DataItem',
+ 'printers/ResultPrinter'
+ );
+
+ // Normalize excluded files
+ foreach ( $excludedFiles as &$registeredFile ) {
+ $registeredFile = $this->normalizePath( __DIR__ . '/' .
$registeredFile . 'Test.php' );
+ }
+
+ // Normalize registered files
+ foreach ( $registeredFiles as &$registeredFile ) {
+ $registeredFile = $this->normalizePath( $registeredFile
);
+ }
+
+ // Compare directory files with registered files
+ foreach ( $testFiles as $fileName => $object ){
+ $fileName = $this->normalizePath( $fileName );
+
+ if ( !in_array( $fileName, $excludedFiles ) ) {
+ $this->assertContains(
+ $fileName,
+ $registeredFiles,
+ 'Missing registration for ' . $fileName
+ );
+ }
+ }
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/65006
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9764a78a75e8904097a3cab80abf6cb2cceca620
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