Mwjames has uploaded a new change for review.

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


Change subject: SMW\ParserTextProcessor add test and improve CRAP index
......................................................................

SMW\ParserTextProcessor add test and improve CRAP index

CRAP index before 44 and after 35 the change

Change-Id: I86cb6d1d7c55cbaaffd369fe1606eb1d6f7e426d
---
M includes/ParserTextProcessor.php
M tests/phpunit/includes/ParserTextProcessorTest.php
2 files changed, 109 insertions(+), 2 deletions(-)


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

diff --git a/includes/ParserTextProcessor.php b/includes/ParserTextProcessor.php
index d6df79b..0df3193 100644
--- a/includes/ParserTextProcessor.php
+++ b/includes/ParserTextProcessor.php
@@ -379,7 +379,9 @@
                if ( method_exists( $this->parserData->getOutput(), 
'setExtensionData' ) ) {
                        $this->parserData->getOutput()->setExtensionData( 
'smwmagicwords', $words );
                } else {
+                       // @codeCoverageIgnoreStart
                        $this->parserData->getOutput()->mSMWMagicWords = $words;
+                       // @codeCoverageIgnoreEnd
                }
 
                return $words;
diff --git a/tests/phpunit/includes/ParserTextProcessorTest.php 
b/tests/phpunit/includes/ParserTextProcessorTest.php
index 671442b..1ce42c3 100644
--- a/tests/phpunit/includes/ParserTextProcessorTest.php
+++ b/tests/phpunit/includes/ParserTextProcessorTest.php
@@ -178,6 +178,25 @@
                                        'propertyValue' => array()
                                )
                        ),
+
+                       // #4 NS_HELP enabled but no properties or links at all
+                       array(
+                               NS_HELP,
+                               array(
+                                       'smwgNamespacesWithSemanticLinks' => 
array( NS_HELP => true ),
+                                       'smwgLinksInValues' => false,
+                                       'smwgInlineErrors' => true,
+                               ),
+                               'Lorem ipsum dolor sit &$% consectetuer auctor 
at quis' .
+                               ' Suspendisse tincidunt semper facilisi dolor 
Aenean.',
+                               array(
+                                       'resultText'    => 'Lorem ipsum dolor 
sit &$% consectetuer auctor at quis' .
+                                               ' Suspendisse tincidunt semper 
facilisi dolor Aenean.',
+                                       'propertyCount' => 0,
+                                       'propertyLabel' => array(),
+                                       'propertyValue' => array()
+                               )
+                       ),
                );
        }
 
@@ -250,13 +269,12 @@
         * @param array $expected
         */
        public function testStripMagicWords( $namespace, $text, array $expected 
) {
-               $reflection = new ReflectionClass( $this->getClass() );
-
                $parserOutput = $this->getParserOutput();
                $title = $this->getTitle( $namespace );
                $instance = $this->getInstance( $title, $parserOutput );
 
                // Make protected method accessible
+               $reflection = new ReflectionClass( $this->getClass() );
                $method = $reflection->getMethod( 'stripMagicWords' );
                $method->setAccessible( true );
 
@@ -305,4 +323,91 @@
                $this->assertInstanceOf( 'SMWSemanticData', 
$parserData->getData() );
                $this->assertSemanticData( $parserData->getData(), $expected );
        }
+
+       /**
+        * @test ParserTextProcessor::setRedirect
+        *
+        * @since 1.9
+        */
+       public function testSetRedirect() {
+               $namespace = NS_MAIN;
+
+               // Mock Title object to avoid DB access
+               $mockTitle = $this->getMock( 'Title' );
+
+               // Attach isRedirect method
+               $mockTitle->expects( $this->any() )
+                       ->method( 'isRedirect' )
+                       ->will( $this->returnValue( true )
+               );
+
+               // Attach getNamespace method
+               $mockTitle->expects( $this->any() )
+                       ->method( 'getNamespace' )
+                       ->will( $this->returnValue( $namespace )
+               );
+
+               // Create text processor instance
+               $parserOutput = $this->getParserOutput();
+               $title = $this->getTitle( $namespace );
+               $settings = array(
+                       'smwgNamespacesWithSemanticLinks' => array( $namespace 
=> true )
+               );
+
+               $parserData = $this->getParserData( $title, $parserOutput );
+               $instance = new ParserTextProcessor(
+                       $parserData,
+                       $this->getSettings( $settings )
+               );
+
+               // Make protected methods accessible
+               $reflection = new ReflectionClass( $this->getClass() );
+
+               $method = $reflection->getMethod( 'isSemanticEnabled' );
+               $method->setAccessible( true );
+               $method->invoke( $instance, $mockTitle );
+
+               $method = $reflection->getMethod( 'setRedirect' );
+               $method->setAccessible( true );
+               $result = $method->invoke( $instance, $mockTitle );
+
+               // Build expected results from a successful setRedirect 
execution
+               $expected['propertyCount'] = 1;
+               $expected['propertyKey'] = '_REDI';
+               $expected['propertyValue'] = ':' . $title->getText();
+
+               // Check the returned instance
+               $this->assertInstanceOf( 'SMWSemanticData', 
$parserData->getData() );
+               $this->assertSemanticData( $parserData->getData(), $expected );
+       }
+
+       /**
+        * @test ParserTextProcessor::process
+        *
+        * @since 1.9
+        */
+       public function testProcess() {
+               $parserOutput =  $this->getParserOutput();
+               $title = $this->getTitle();
+               $instance = $this->getInstance( $title, $parserOutput );
+
+               // Make protected methods accessible
+               $reflection = new ReflectionClass( $this->getClass() );
+
+               $method = $reflection->getMethod( 'process' );
+               $method->setAccessible( true );
+
+               $result = $method->invoke( $instance, array() );
+               $this->assertEmpty( $result );
+
+               $result = $method->invoke( $instance, array( 'Test::foo', 'SMW' 
, 'lula' ) );
+               $this->assertEmpty( $result );
+
+               $result = $method->invoke( $instance, array( 'Test::bar', 'SMW' 
, 'on' ) );
+               $this->assertEmpty( $result );
+
+               $result = $method->invoke( $instance, array( 'Test::lula', 
'SMW' , 'off' ) );
+               $this->assertEmpty( $result );
+       }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I86cb6d1d7c55cbaaffd369fe1606eb1d6f7e426d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to