Mwjames has uploaded a new change for review.

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


Change subject: Add unit tests (SMW\ParserDataTest, SMW\QueryProcessorTest)
......................................................................

Add unit tests (SMW\ParserDataTest, SMW\QueryProcessorTest)

Tests that are not yet active have been marked as incomplete

* SMW\QueryProcessorTest requires SemanticDataTestCase class ([1], [2])
in order to test/mock different queries

## Dependency
[1] https://gerrit.wikimedia.org/r/#/c/52598/
[2] https://gerrit.wikimedia.org/r/#/c/53943/

Change-Id: Ia5f26fa6275893ac3e1aa5e0cfda24d5b168e474
---
M SemanticMediaWiki.hooks.php
D tests/phpunit/includes/QueryProcessorTest.php
A tests/phpunit/includes/parserhooks/ParserDataTest.php
A tests/phpunit/includes/query/QueryProcessorTest.php
4 files changed, 271 insertions(+), 61 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/16/54016/1

diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index e92b8af..ad23786 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -272,7 +272,8 @@
                        'FormatFactory',
                        'Highlighter',
                        'ObservableMessageReporter',
-                       'QueryProcessor',
+
+                       'query/QueryProcessor',
 
                        'dataitems/DI_Blob',
                        'dataitems/DI_Bool',
@@ -283,6 +284,7 @@
                        'export/SMWExpElement',
 
                        'parserhooks/ParserParameter',
+                       'parserhooks/ParserData',
                        'parserhooks/Subobject',
                        'parserhooks/RecurringEvents',
                        'parserhooks/SubobjectParserFunction',
diff --git a/tests/phpunit/includes/QueryProcessorTest.php 
b/tests/phpunit/includes/QueryProcessorTest.php
deleted file mode 100644
index 95c1bf4..0000000
--- a/tests/phpunit/includes/QueryProcessorTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-/**
- * @file
- * @since 1.8
- * @ingroup SMW
- * @ingroup Test
- */
-
-namespace SMW\Test;
-use SMWQueryProcessor;
-
-/**
- * Tests for the SMWQueryProcessor class.
- *
- * @since 1.8
- *
- * @ingroup SMW
- * @ingroup Test
- *
- * @group SMW
- * @group SMWExtension
- * @group SMWQueries
- * @group SMWQueryProcessorTest
- *
- * @author Nischay Nahata
- */
-class SMWQueryProcessorTest extends\ MediaWikiTestCase {
-
-       public function createQueryDataProvider() {
-               return array(
-                       array( '[[Modification date::+]]|?Modification 
date|sort=Modification date|order=desc' ),
-               );
-       }
-
-       /**
-       * @dataProvider createQueryDataProvider
-       */
-       public function testCreateQuery( $query ) {
-               // TODO: this prevents doing [[Category:Foo||bar||baz]], must 
document.
-               $rawParams = explode( '|', $query );
-
-               list( $queryString, $parameters, $printouts ) = 
SMWQueryProcessor::getComponentsFromFunctionParams( $rawParams, false );
-
-               SMWQueryProcessor::addThisPrintout( $printouts, $parameters );
-               $parameters = SMWQueryProcessor::getProcessedParams( 
$parameters, $printouts );
-
-               $this->assertInstanceOf(
-                       '\SMWQuery',
-                       SMWQueryProcessor::createQuery(
-                               $queryString,
-                               $parameters,
-                               SMWQueryProcessor::SPECIAL_PAGE,
-                               '',
-                               $printouts
-                       ),
-                       "Result should be instance of SMWQuery."
-               );
-       }
-
-}
\ No newline at end of file
diff --git a/tests/phpunit/includes/parserhooks/ParserDataTest.php 
b/tests/phpunit/includes/parserhooks/ParserDataTest.php
new file mode 100644
index 0000000..d9ec860
--- /dev/null
+++ b/tests/phpunit/includes/parserhooks/ParserDataTest.php
@@ -0,0 +1,145 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\ParserData;
+use ParserOutput;
+use Title;
+
+/**
+ * Tests for the SMW\ParserData class
+ *
+ * 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 ParserDataTest extends \MediaWikiTestCase {
+
+       /**
+        * Helper method to get title object
+        *
+        * @return Title
+        */
+       private function getTitle( $title ){
+               return Title::newFromText( $title );
+       }
+
+       /**
+        * Helper method to get ParserOutput object
+        *
+        * @return ParserOutput
+        */
+       private function getParserOutput(){
+               return new ParserOutput();
+       }
+
+       /**
+        * Helper method
+        *
+        * @return SMW\ParserData
+        */
+       private function getInstance( $titleName, ParserOutput $parserOutput ) {
+               //return new ParserData( $this->getTitle( $titleName ), 
$parserOutput );
+       }
+
+       /**
+        * Test instance
+        *
+        */
+       public function testConstructor() {
+               //$instance = $this->getInstance( 'Foo', 
$this->getParserOutput() );
+               //$this->assertInstanceOf( 'SMW\ParserData', $instance );
+
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Returns Title object
+        *
+        * @covers SMW\ParserData::getTitle
+        *
+        * @since 1.9
+        */
+       public function testGetTitle() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Returns ParserOutput object
+        *
+        * @covers SMW\ParserData::getOutput
+        *
+        * @since 1.9
+        */
+       public function testGetOutput() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Update ParserOoutput with processed semantic data
+        *
+        * @covers SMW\ParserData::updateOutput
+        *
+        * @since 1.9
+        */
+       public function testUpdateOutput() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Get semantic data
+        *
+        * @covers SMW\ParserData::getData
+        *
+        * @since 1.9
+        */
+       public function testGetData() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Stores semantic data to the database
+        *
+        * @covers SMW\ParserData::storeData
+        *
+        * @since 1.9
+        */
+       public function testStoreData() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Returns an report about activities that occurred during processing
+        *
+        * @covers SMW\ParserData::getReport
+        *
+        * @since 1.9
+        */
+       public function testGetReport() {
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+}
diff --git a/tests/phpunit/includes/query/QueryProcessorTest.php 
b/tests/phpunit/includes/query/QueryProcessorTest.php
new file mode 100644
index 0000000..48a7862
--- /dev/null
+++ b/tests/phpunit/includes/query/QueryProcessorTest.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\QueryProcessor;
+
+/**
+ * Tests for the SMW\QueryProcessor class
+ *
+ * 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
+ * @group SMWQuery
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+class QueryProcessorTest extends \MediaWikiTestCase {
+
+       /**
+        * DataProvider
+        *
+        * @return array
+        */
+       public function getDataProvider() {
+               return array(
+
+                       // #0
+                       array(
+                               array(
+                                       'outputMode' => SMW_OUTPUT_WIKI,
+                                       'queryContext' => 
QueryProcessor::INLINE_QUERY,
+                                               'showMode' => false,
+                                       'query' => '[[Modification 
date::+]]|?Modification date|sort=Modification date|order=desc'
+                               )
+                       ),
+               );
+       }
+
+       /**
+        * Helper ...
+        *
+        * @return array
+        */
+       public function toArray( $string ){
+               return preg_split( "/(?<=[^\|])\|(?=[^\|])/", $string );
+       }
+
+       /**
+        * Helper method
+        *
+        * @return SMW\QueryProcessor
+        */
+       private function getInstance( $outputMode, $queryContext, $showMode ) {
+               //return new QueryProcessor( $outputMode, $queryContext, 
$showMode  );
+       }
+
+       /**
+        * Test instance
+        *
+        * @dataProvider getDataProvider
+        *
+        * @since 1.9
+        */
+       public function testConstructor( array $setup ) {
+               //$instance = $this->getInstance( $setup['outputMode'], 
$setup['queryContext'], $setup['showMode'] );
+               //$this->assertInstanceOf( 'SMW\QueryProcessor', $instance );
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Test getQuery()
+        *
+        * @covers SMW\QueryProcessor::getQuery
+        * @dataProvider getDataProvider
+        *
+        * @since 1.9
+        */
+       public function testGetQuery( array $setup ) {
+               //$instance = $this->getInstance( $setup['outputMode'], 
$setup['queryContext'], $setup['showMode'] );
+               //$instance->map( $this->toArray( $setup['query'] ) );
+               //$this->assertInstanceOf( 'SMWQuery', $instance->getQuery() );
+
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+       /**
+        * Test getResult()
+        *
+        * @covers SMW\QueryProcessor::getResult
+        * @dataProvider getDataProvider
+        *
+        * @since 1.9
+        */
+       public function testGetResult( array $setup ) {
+               //$instance = $this->getInstance( $setup['outputMode'], 
$setup['queryContext'], $setup['showMode'] );
+               //$instance->map( $this->toArray( $setup['query'] ) );
+               //$this->assertTrue( is_string( $instance->getResult() ) );
+
+               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5f26fa6275893ac3e1aa5e0cfda24d5b168e474
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

Reply via email to