Mwjames has uploaded a new change for review.

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


Change subject: Improve code coverage
......................................................................

Improve code coverage

Change-Id: Ib9d2b8c40df6c26160e8d609c10a1260dd773b8f
---
M includes/parserhooks/AskParserFunction.php
M includes/parserhooks/ShowParserFunction.php
M tests/phpunit/SemanticMediaWikiTestCase.php
M tests/phpunit/includes/SemanticDataTest.php
M tests/phpunit/includes/SimpleDictionaryTest.php
M tests/phpunit/includes/parserhooks/AskParserFunctionTest.php
M tests/phpunit/includes/parserhooks/ConceptParserFunctionTest.php
M tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php
8 files changed, 236 insertions(+), 128 deletions(-)


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

diff --git a/includes/parserhooks/AskParserFunction.php 
b/includes/parserhooks/AskParserFunction.php
index 15ec0d2..8bbf59e 100644
--- a/includes/parserhooks/AskParserFunction.php
+++ b/includes/parserhooks/AskParserFunction.php
@@ -92,8 +92,8 @@
         *
         * @return AskParserFunction
         */
-       public function useShowMode() {
-               $this->showMode = true;
+       public function setShowMode( $mode ) {
+               $this->showMode = $mode;
                return $this;
        }
 
diff --git a/includes/parserhooks/ShowParserFunction.php 
b/includes/parserhooks/ShowParserFunction.php
index 3da62c6..f99c71c 100644
--- a/includes/parserhooks/ShowParserFunction.php
+++ b/includes/parserhooks/ShowParserFunction.php
@@ -74,7 +74,7 @@
         */
        public function parse( array $rawParams ) {
                $ask = new AskParserFunction( $this->parserData, 
$this->queryData, $this->msgFormatter );
-               return $ask->useShowMode()->parse( $rawParams );
+               return $ask->setShowMode( true )->parse( $rawParams );
        }
 
        /**
diff --git a/tests/phpunit/SemanticMediaWikiTestCase.php 
b/tests/phpunit/SemanticMediaWikiTestCase.php
index 42def34..39cdaa7 100644
--- a/tests/phpunit/SemanticMediaWikiTestCase.php
+++ b/tests/phpunit/SemanticMediaWikiTestCase.php
@@ -127,6 +127,17 @@
         * @return User
         */
        protected function getUser() {
+               return $this->newMockUser();
+       }
+
+       /**
+        * Helper method that returns a User object
+        *
+        * @since 1.9
+        *
+        * @return User
+        */
+       protected function newMockUser() {
                return new MockSuperUser();
        }
 
diff --git a/tests/phpunit/includes/SemanticDataTest.php 
b/tests/phpunit/includes/SemanticDataTest.php
index 83c7238..5cf940d 100644
--- a/tests/phpunit/includes/SemanticDataTest.php
+++ b/tests/phpunit/includes/SemanticDataTest.php
@@ -165,6 +165,17 @@
                        )
                );
 
+               // #6 Error (Known predefined property)
+               $provider[] = array(
+                       array(
+                               DataValueFactory::newPropertyValue( 
'Modification date', 'Bar' ),
+                       ),
+                       array(
+                               'error'         => 1,
+                               'propertyCount' => 0,
+                       )
+               );
+
                return $provider;
        }
 
diff --git a/tests/phpunit/includes/SimpleDictionaryTest.php 
b/tests/phpunit/includes/SimpleDictionaryTest.php
index 056d4ff..9e7963e 100644
--- a/tests/phpunit/includes/SimpleDictionaryTest.php
+++ b/tests/phpunit/includes/SimpleDictionaryTest.php
@@ -127,7 +127,18 @@
 
                // Remove
                $instance->remove( $setup['key'] );
-               $this->assertFalse( $instance->has( $setup['key'] ) );
+
+               $this->assertFalse(
+                       $instance->has( $setup['key'] ),
+                       'asserts that detach/removal will result alwasy in 
false'
+               );
+
+               $instance->remove( $setup['key'] );
+
+               $this->assertFalse(
+                       $instance->has( $setup['key'] ),
+                       'asserts that detach/removal will result alwasy in 
false'
+               );
 
        }
 
diff --git a/tests/phpunit/includes/parserhooks/AskParserFunctionTest.php 
b/tests/phpunit/includes/parserhooks/AskParserFunctionTest.php
index 4d02cd7..d52c2c4 100644
--- a/tests/phpunit/includes/parserhooks/AskParserFunctionTest.php
+++ b/tests/phpunit/includes/parserhooks/AskParserFunctionTest.php
@@ -52,7 +52,15 @@
         *
         * @return AskParserFunction
         */
-       private function getInstance( Title $title, ParserOutput $parserOutput 
= null, Settings $settings = null ) {
+       private function newInstance( Title $title = null, ParserOutput 
$parserOutput = null, Settings $settings = null ) {
+
+               if ( $title === null ) {
+                       $title = $this->newTitle();
+               }
+
+               if ( $parserOutput === null ) {
+                       $parserOutput = $this->newParserOutput();
+               }
 
                if ( $settings === null ) {
                        $settings = $this->newSettings();
@@ -72,8 +80,7 @@
         * @since 1.9
         */
        public function testConstructor() {
-               $instance = $this->getInstance( $this->newTitle(), 
$this->newParserOutput() );
-               $this->assertInstanceOf( $this->getClass(), $instance );
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
        }
 
        /**
@@ -87,7 +94,7 @@
         */
        public function testParse( array $params, array $expected ) {
 
-               $instance = $this->getInstance( $this->newTitle(), 
$this->newParserOutput() );
+               $instance = $this->newInstance( $this->newTitle(), 
$this->newParserOutput() );
                $result  = $instance->parse( $params );
                $this->assertInternalType( 'string', $result );
 
@@ -102,17 +109,47 @@
 
                $title    = $this->newTitle();
                $message  = new MessageFormatter( $title->getPageLanguage() );
-               $expected = $message->addFromKey( 'smw_iq_disabled' 
)->getHtml();
 
-               $instance = $this->getInstance( $title , 
$this->newParserOutput() );
+               $instance = $this->newInstance( $title , 
$this->newParserOutput() );
 
-               // Make protected method accessible
-               $reflection = new ReflectionClass( $this->getClass() );
-               $method = $reflection->getMethod( 'disabled' );
+               $reflector = $this->newReflector();
+               $method = $reflector->getMethod( 'disabled' );
                $method->setAccessible( true );
 
                $result = $method->invoke( $instance );
-               $this->assertEquals( $expected , $result );
+
+               $this->assertEquals(
+                       $message->addFromKey( 'smw_iq_disabled' )->getHtml(),
+                       $result,
+                       'asserts a resutling disabled error message'
+               );
+
+       }
+
+       /**
+        * @test AskParserFunction::setShowMode
+        *
+        * @since 1.9
+        */
+       public function testSetShowMode() {
+
+               $instance = $this->newInstance();
+
+               $reflector = $this->newReflector();
+               $showMode = $reflector->getProperty( 'showMode' );
+               $showMode->setAccessible( true );
+
+               $this->assertFalse(
+                        $showMode->getValue( $instance ),
+                       'asserts that showMode is false by default'
+               );
+
+               $instance->setShowMode( true );
+
+               $this->assertTrue(
+                       $showMode->getValue( $instance ),
+                       'asserts that showMode is true'
+               );
 
        }
 
@@ -131,7 +168,7 @@
                $title        = $this->newTitle();
 
                // Initialize and parse
-               $instance = $this->getInstance( $title, $parserOutput, 
$this->newSettings( $settings ) );
+               $instance = $this->newInstance( $title, $parserOutput, 
$this->newSettings( $settings ) );
                $instance->parse( $params );
 
                // Get semantic data from the ParserOutput
diff --git a/tests/phpunit/includes/parserhooks/ConceptParserFunctionTest.php 
b/tests/phpunit/includes/parserhooks/ConceptParserFunctionTest.php
index e1d5b78..31f991e 100644
--- a/tests/phpunit/includes/parserhooks/ConceptParserFunctionTest.php
+++ b/tests/phpunit/includes/parserhooks/ConceptParserFunctionTest.php
@@ -40,70 +40,20 @@
        }
 
        /**
-        * Provides data sample, the first array contains parametrized input
-        * value while the second array contains expected return results for the
-        * instantiated object.
-        *
-        * @return array
-        */
-       public function getDataProvider() {
-               return array(
-
-                       // #0
-                       // {{#concept: [[Modification date::+]]
-                       // }}
-                       array(
-                               array(
-                                       '[[Modification date::+]]'
-                               ),
-                               array(
-                                       'result' => true,
-                                       'propertyCount' => 1,
-                                       'conceptQuery'  => '[[Modification 
date::+]]',
-                                       'conceptDocu'   => '',
-                                       'conceptSize'   => 1,
-                                       'conceptDepth'  => 1,
-                               )
-                       ),
-
-                       // #1
-                       // {{#concept: [[Modification date::+]]
-                       // |Foooooooo
-                       // }}
-                       array(
-                               array(
-                                       '[[Modification date::+]]',
-                                       'Foooooooo'
-                               ),
-                               array(
-                                       'result' => true,
-                                       'propertyCount' => 1,
-                                       'conceptQuery'  => '[[Modification 
date::+]]',
-                                       'conceptDocu'   => 'Foooooooo',
-                                       'conceptSize'   => 1,
-                                       'conceptDepth'  => 1,
-                               )
-                       )
-               );
-       }
-
-       /**
-        * NameSpaceDataProvider
-        *
-        * @return array
-        */
-       public function getNameSpaceDataProvider() {
-               return array(
-                       array( NS_MAIN, NS_HELP, SMW_NS_CONCEPT )
-               );
-       }
-
-       /**
         * Helper method that returns a instance
         *
         * @return ConceptParserFunction
         */
-       private function getInstance( Title $title, ParserOutput $parserOutput 
= null ) {
+       private function newInstance( Title $title = null, ParserOutput 
$parserOutput = null ) {
+
+               if ( $title === null ) {
+                       $title = $this->newTitle( SMW_NS_CONCEPT );
+               }
+
+               if ( $parserOutput === null ) {
+                       $parserOutput = $this->newParserOutput();
+               }
+
                return new ConceptParserFunction(
                        $this->getParserData( $title, $parserOutput ),
                        new MessageFormatter( $title->getPageLanguage() )
@@ -126,64 +76,58 @@
         * @since 1.9
         */
        public function testConstructor() {
-               $instance = $this->getInstance(
-                       $this->newTitle( SMW_NS_CONCEPT ),
-                       $this->getParserOutput()
-               );
-               $this->assertInstanceOf( $this->getClass(), $instance );
-       }
-
-       /**
-        * @test ConceptParserFunction::__construct (Test instance exception)
-        *
-        * @since 1.9
-        */
-       public function testConstructorException() {
-               $this->setExpectedException( 'PHPUnit_Framework_Error' );
-               $instance = $this->getInstance( $this->newTitle( SMW_NS_CONCEPT 
) );
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
        }
 
        /**
         * @test ConceptParserFunction::parse (Test error on wrong namespace)
-        * @dataProvider getNameSpaceDataProvider
+        * @dataProvider namespaceDataProvider
         *
         * @since 1.9
         *
         * @param $namespace
         */
        public function testErrorOnNamespace( $namespace ) {
-               $title = $this->newTitle( $namespace );
-               $errorMessage = $this->getMessageText( $title, 
'smw_no_concept_namespace' );
-               $instance = $this->getInstance( $title, 
$this->getParserOutput() );
 
-               $this->assertEquals( $errorMessage, $instance->parse( array() ) 
);
+               $title = $this->newTitle( $namespace );
+               $instance = $this->newInstance( $title, 
$this->newParserOutput() );
+
+               $this->assertEquals(
+                       $this->getMessageText( $title, 
'smw_no_concept_namespace' ),
+                       $instance->parse( array() ),
+                       'asserts that an error is raised due to a wrong 
namespace'
+               );
+
        }
 
        /**
         * @test ConceptParserFunction::parse (Test error on double 
{{#concept}} use)
-        * @dataProvider getDataProvider
+        * @dataProvider queryDataProvider
         *
         * @since 1.9
         *
         * @param $params
         */
        public function testErrorOnDoubleParse( array $params ) {
-               $title = $this->newTitle( SMW_NS_CONCEPT );
-               $errorMessage = $this->getMessageText( $title, 
'smw_multiple_concepts' );
 
-               $instance = $this->getInstance( $title, 
$this->getParserOutput() );
+               $title = $this->newTitle( SMW_NS_CONCEPT );
+
+               $instance = $this->newInstance( $title, 
$this->newParserOutput() );
                $instance->parse( $params );
 
                // First call
                $instance->parse( $params );
 
-               // Second call raises the error
-               $this->assertEquals( $errorMessage, $instance->parse( $params ) 
);
+               $this->assertEquals(
+                       $this->getMessageText( $title, 'smw_multiple_concepts' 
),
+                       $instance->parse( $params ),
+                       'assert that the second call raises an error'
+               );
        }
 
        /**
         * @test ConceptParserFunction::parse
-        * @dataProvider getDataProvider
+        * @dataProvider queryDataProvider
         *
         * @since 1.9
         *
@@ -191,19 +135,29 @@
         * @param $expected
         */
        public function testParse( array $params, array $expected ) {
-               $parserOutput =  $this->getParserOutput();
+
+               $parserOutput =  $this->newParserOutput();
                $title = $this->newTitle( SMW_NS_CONCEPT );
 
                // Initialize and parse
-               $instance = $this->getInstance( $title, $parserOutput );
+               $instance = $this->newInstance( $title, $parserOutput );
                $instance->parse( $params );
 
                // Re-read data from stored parserOutput
                $parserData = $this->getParserData( $title, $parserOutput );
 
                // Check the returned instance
-               $this->assertInstanceOf( 'SMWSemanticData', 
$parserData->getData() );
-               $this->assertCount( $expected['propertyCount'], 
$parserData->getData()->getProperties() );
+               $this->assertInstanceOf(
+                       '\SMW\SemanticData',
+                       $parserData->getData(),
+                       'assert that the returning instance if of type 
SemanticData'
+               );
+
+               $this->assertCount(
+                       $expected['propertyCount'],
+                       $parserData->getData()->getProperties(),
+                       'asserts the expected amount of properties available 
through getProperties()'
+               );
 
                // Confirm concept property
                foreach ( $parserData->getData()->getProperties() as $key => 
$diproperty ){
@@ -226,8 +180,95 @@
         * @since 1.9
         */
        public function testStaticRender() {
-               $parser = $this->getParser( $this->newTitle(), $this->getUser() 
);
+
+               $parser = $this->newParser( $this->newTitle(), 
$this->newMockUser() );
                $result = ConceptParserFunction::render( $parser );
-               $this->assertInternalType( 'string', $result );
+
+               $this->assertInternalType(
+                       'string',
+                       $result,
+                       'asserts that the returning result is always of type 
string'
+               );
        }
+
+       /**
+        * Provides data sample, the first array contains parametrized input
+        * value while the second array contains expected return results for the
+        * instantiated object.
+        *
+        * @return array
+        */
+       public function queryDataProvider() {
+
+               $provider = array();
+
+               // #0
+               // {{#concept: [[Modification date::+]]
+               // }}
+               $provider[] = array(
+                       array(
+                               '[[Modification date::+]]'
+                       ),
+                       array(
+                               'result' => true,
+                               'propertyCount' => 1,
+                               'conceptQuery'  => '[[Modification date::+]]',
+                               'conceptDocu'   => '',
+                               'conceptSize'   => 1,
+                               'conceptDepth'  => 1,
+                       )
+               );
+
+               // #1
+               // {{#concept: [[Modification date::+]]
+               // |Foooooooo
+               // }}
+               $provider[] = array(
+                       array(
+                               '[[Modification date::+]]',
+                               'Foooooooo'
+                       ),
+                       array(
+                               'result' => true,
+                               'propertyCount' => 1,
+                               'conceptQuery'  => '[[Modification date::+]]',
+                               'conceptDocu'   => 'Foooooooo',
+                               'conceptSize'   => 1,
+                               'conceptDepth'  => 1,
+                       )
+               );
+
+               // #2 (includes Parser object)
+               $provider[] = array(
+                       array(
+                               $this->newParser( $this->newTitle(), 
$this->newMockUser() ),
+                               '[[Modification date::+]]',
+                               'Foooooooo'
+                       ),
+                       array(
+                               'result' => true,
+                               'propertyCount' => 1,
+                               'conceptQuery'  => '[[Modification date::+]]',
+                               'conceptDocu'   => 'Foooooooo',
+                               'conceptSize'   => 1,
+                               'conceptDepth'  => 1,
+                       )
+               );
+
+               return $provider;
+
+       }
+
+       /**
+        * NameSpaceDataProvider
+        *
+        * @return array
+        */
+       public function namespaceDataProvider() {
+               return array(
+                       array( NS_MAIN ),
+                       array( NS_HELP )
+               );
+       }
+
 }
diff --git a/tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php 
b/tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php
index 93639c1..0f4e29c 100644
--- a/tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php
+++ b/tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php
@@ -50,7 +50,15 @@
         *
         * @return ShowParserFunction
         */
-       private function getInstance( Title $title, ParserOutput $parserOutput 
= null ) {
+       private function newInstance( Title $title = null, ParserOutput 
$parserOutput = null ) {
+
+               if ( $title === null ) {
+                       $title = $this->newTitle();
+               }
+
+               if ( $parserOutput === null ) {
+                       $parserOutput = $this->newParserOutput();
+               }
 
                $settings = $this->newSettings();
 
@@ -68,23 +76,12 @@
         * @since 1.9
         */
        public function testConstructor() {
-               $instance = $this->getInstance( $this->newTitle(), 
$this->newParserOutput() );
-               $this->assertInstanceOf( $this->getClass(), $instance );
-       }
-
-       /**
-        * @test ShowParserFunction::__construct (Test instance exception)
-        *
-        * @since 1.9
-        */
-       public function testConstructorException() {
-               $this->setExpectedException( 'PHPUnit_Framework_Error' );
-               $instance =  $this->getInstance( $this->getTitle() );
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
        }
 
        /**
         * @test ShowParserFunction::parse
-        * @dataProvider getDataProvider
+        * @dataProvider queryDataProvider
         *
         * @since 1.9
         *
@@ -93,7 +90,7 @@
         */
        public function testParse( array $params, array $expected ) {
 
-               $instance = $this->getInstance( $this->newTitle(), 
$this->newParserOutput() );
+               $instance = $this->newInstance( $this->newTitle(), 
$this->newParserOutput() );
                $result   = $instance->parse( $params, true );
 
                if (  $expected['output'] === '' ) {
@@ -106,7 +103,7 @@
 
        /**
         * @test ShowParserFunction::parse (Test $GLOBALS['smwgQEnabled'] = 
false)
-        * @dataProvider getDataProvider
+        * @dataProvider queryDataProvider
         *
         * @since 1.9
         */
@@ -116,7 +113,7 @@
                $message  = new MessageFormatter( $title->getPageLanguage() );
                $expected = $message->addFromKey( 'smw_iq_disabled' 
)->getHtml();
 
-               $instance = $this->getInstance( $title, 
$this->getParserOutput() );
+               $instance = $this->newInstance( $title, 
$this->getParserOutput() );
 
                // Make protected method accessible
                $reflection = new ReflectionClass( $this->getClass() );
@@ -129,7 +126,7 @@
 
        /**
         * @test ShowParserFunction::parse (Test generated query data)
-        * @dataProvider getDataProvider
+        * @dataProvider queryDataProvider
         *
         * @since 1.9
         *
@@ -142,7 +139,7 @@
                $title        = $this->newTitle();
 
                // Initialize and parse
-               $instance = $this->getInstance( $title, $parserOutput );
+               $instance = $this->newInstance( $title, $parserOutput );
                $instance->parse( $params );
 
                // Get semantic data from the ParserOutput
@@ -178,7 +175,7 @@
         *
         * @return array
         */
-       public function getDataProvider() {
+       public function queryDataProvider() {
 
                $provider = array();
 

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

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