Mwjames has uploaded a new change for review.

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


Change subject: Fix _Foo/-Foo test in ParserData
......................................................................

Fix _Foo/-Foo test in ParserData

_Foo or -Foo caused Call to undefined method SMWDIError::isInverse()

Change-Id: I5ba2de431cfd9c9bbdb8e54466f7b9775bfb3b49
---
M includes/parserhooks/ParserData.php
M tests/phpunit/includes/parserhooks/ParserDataTest.php
M tests/phpunit/includes/parserhooks/SetParserFunctionTest.php
3 files changed, 78 insertions(+), 11 deletions(-)


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

diff --git a/includes/parserhooks/ParserData.php 
b/includes/parserhooks/ParserData.php
index d82c76b..f0aff71 100644
--- a/includes/parserhooks/ParserData.php
+++ b/includes/parserhooks/ParserData.php
@@ -356,7 +356,7 @@
         */
        public function addPropertyValueString( $propertyName, $valueString ) {
                if ( !( $this->semanticData instanceof SMWSemanticData ) ) {
-                       throw new MWException( 'The subject container is not 
initialized' );
+                       throw new MWException( 'The semantic data container is 
not initialized' );
                }
 
                wfProfileIn(  __METHOD__ );
@@ -364,7 +364,7 @@
                $propertyDv = SMWPropertyValue::makeUserProperty( $propertyName 
);
                $propertyDi = $propertyDv->getDataItem();
 
-               if ( !$propertyDi->isInverse() ) {
+               if ( $propertyDi instanceof \SMWDIProperty && 
!$propertyDi->isInverse() ) {
                        $valueDv = SMWDataValueFactory::newPropertyObjectValue( 
$propertyDi, $valueString,
                                false, $this->semanticData->getSubject() );
                        $this->semanticData->addPropertyObjectValue( 
$propertyDi, $valueDv->getDataItem() );
@@ -377,9 +377,10 @@
                                );
                                $this->setError( $valueDv->getErrors() );
                        }
-               } else {
-                       // FIXME Message object from context
+               } else if ( $propertyDi instanceof \SMWDIProperty && 
$propertyDi->isInverse() ) {
                        $this->setError( array( wfMessage( 'smw_noinvannot' 
)->inContentLanguage()->text() ) );
+               } else {
+                       $this->setError( array( wfMessage( 
'smw-property-name-invalid', $propertyName )->inContentLanguage()->text() ) );
                }
 
                wfProfileOut( __METHOD__ );
diff --git a/tests/phpunit/includes/parserhooks/ParserDataTest.php 
b/tests/phpunit/includes/parserhooks/ParserDataTest.php
index d9ec860..3a50012 100644
--- a/tests/phpunit/includes/parserhooks/ParserDataTest.php
+++ b/tests/phpunit/includes/parserhooks/ParserDataTest.php
@@ -6,6 +6,9 @@
 use ParserOutput;
 use Title;
 
+use SMWDataValueFactory;
+use SMWDataItem;
+
 /**
  * Tests for the SMW\ParserData class
  *
@@ -62,7 +65,7 @@
         * @return SMW\ParserData
         */
        private function getInstance( $titleName, ParserOutput $parserOutput ) {
-               //return new ParserData( $this->getTitle( $titleName ), 
$parserOutput );
+               return new ParserData( $this->getTitle( $titleName ), 
$parserOutput );
        }
 
        /**
@@ -70,10 +73,8 @@
         *
         */
        public function testConstructor() {
-               //$instance = $this->getInstance( 'Foo', 
$this->getParserOutput() );
-               //$this->assertInstanceOf( 'SMW\ParserData', $instance );
-
-               $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
+               $instance = $this->getInstance( 'Foo', $this->getParserOutput() 
);
+               $this->assertInstanceOf( 'SMW\ParserData', $instance );
        }
 
        /**
@@ -142,4 +143,51 @@
                $this->markTestIncomplete( 'This test has not been implemented 
yet.' );
        }
 
+       /**
+        * DataProvider
+        *
+        * @return array
+        */
+       public function getPropertyValueStringDataProvider() {
+
+               // property, value, errorCount
+               return array(
+                       array( 'Foo'  , 'Bar', 0 ),
+                       array( '-Foo' , 'Bar', 1 ),
+                       array( '_Foo' , 'Bar', 1 ),
+               );
+       }
+
+       /**
+        * Add property / value string
+        *
+        * @covers SMW\ParserData::addPropertyValueString
+        * @dataProvider getPropertyValueStringDataProvider
+        *
+        * @since 1.9
+        */
+       public function testAddPropertyValueString( $propertyName, $value, 
$error ) {
+               $instance = $this->getInstance( 'Foo', $this->getParserOutput() 
);
+               $instance->addPropertyValueString( $propertyName, $value );
+
+               // Check the returned instance
+               $this->assertInstanceOf( 'SMWSemanticData', 
$instance->getSemanticData() );
+               $this->assertCount( $error, $instance->getErrors() );
+
+               // Check added properties
+               foreach ( $instance->getSemanticData()->getProperties() as $key 
=> $diproperty ){
+
+                       $this->assertInstanceOf( 'SMWDIProperty', $diproperty );
+                       $this->assertContains( $propertyName, 
$diproperty->getLabel() );
+
+                       // Check added property values
+                       foreach ( 
$instance->getSemanticData()->getPropertyValues( $diproperty ) as $dataItem ){
+                               $dataValue = 
SMWDataValueFactory::newDataItemValue( $dataItem, $diproperty );
+                               if ( $dataValue->getDataItem()->getDIType() === 
SMWDataItem::TYPE_WIKIPAGE ){
+                                       $this->assertContains( $value, 
$dataValue->getWikiValue() );
+                               }
+                       }
+               }
+       }
+
 }
diff --git a/tests/phpunit/includes/parserhooks/SetParserFunctionTest.php 
b/tests/phpunit/includes/parserhooks/SetParserFunctionTest.php
index 0aafb54..a286fbd 100644
--- a/tests/phpunit/includes/parserhooks/SetParserFunctionTest.php
+++ b/tests/phpunit/includes/parserhooks/SetParserFunctionTest.php
@@ -108,6 +108,24 @@
                                        'value' => array( 'Bar', '9001' )
                                )
                        ),
+
+                       // Multiple data set with an error record
+
+                       // {{#set:
+                       // |_Foo=9001 --> will raise an error
+                       // |Foo=bar
+                       // }}
+                       array(
+                               'Foo', // Title
+                               array( 'Foo=bar', '_Foo=9001' ), // Parameters
+                               array(
+                                       'errors' => 1,
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => array( 'Foo' ),
+                                       'value' => array( 'Bar' )
+                               )
+                       ),
+
                );
        }
 
@@ -163,9 +181,9 @@
         *
         * @dataProvider getDataProvider
         */
-       public function testParse( $title, array $params ) {
+       public function testParse( $title, array $params, array $expected ) {
                $instance = $this->getInstance( $title, 
$this->getParserOutput() );
-               $this->assertEquals( '', $instance->parse( new 
ParserParameterFormatter( $params ) ) );
+               $this->assertInternalType( 'string', $instance->parse( new 
ParserParameterFormatter( $params ) ) );
        }
 
        /**

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

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