jenkins-bot has submitted this change and it was merged.

Change subject: Subobject clean-up work in constructor
......................................................................


Subobject clean-up work in constructor

Follow-up from some other changes which always was a thorn in my side
therefore doing this change now to make this interface a bit
more "compos mentis"

Code coverage: 100%
CRAP: 15 (down from 17)

Change-Id: Icc1c7287fec8c3022fe016e985f748eef4dfd7ed
---
M includes/Setup.php
M includes/Subobject.php
A includes/exceptions/InvalidSemanticDataException.php
M includes/parserhooks/SubobjectParserFunction.php
M tests/phpunit/includes/SubobjectTest.php
M tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php
6 files changed, 519 insertions(+), 370 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Setup.php b/includes/Setup.php
index fb53ae4..a761fc2 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -153,9 +153,10 @@
        $wgAutoloadClasses['SMW\CacheHandler']           = $incDir . 
'/handlers/CacheHandler.php';
 
        // Exceptions
-       $wgAutoloadClasses['SMW\StoreInstanceException']      = $incDir . 
'/exceptions/StoreInstanceException.php';
-       $wgAutoloadClasses['SMW\SettingsArgumentException']   = $incDir . 
'/exceptions/SettingsArgumentException.php';
-       $wgAutoloadClasses['SMW\PredefinedPropertyException'] = $incDir . 
'/exceptions/PredefinedPropertyException.php';
+       $wgAutoloadClasses['SMW\StoreInstanceException']       = $incDir . 
'/exceptions/StoreInstanceException.php';
+       $wgAutoloadClasses['SMW\SettingsArgumentException']    = $incDir . 
'/exceptions/SettingsArgumentException.php';
+       $wgAutoloadClasses['SMW\PredefinedPropertyException']  = $incDir . 
'/exceptions/PredefinedPropertyException.php';
+       $wgAutoloadClasses['SMW\InvalidSemanticDataException'] = $incDir . 
'/exceptions/InvalidSemanticDataException.php';
 
        // Article pages
        $apDir = $smwgIP . 'includes/articlepages/';
diff --git a/includes/Subobject.php b/includes/Subobject.php
index 8d8e655..ea3e332 100644
--- a/includes/Subobject.php
+++ b/includes/Subobject.php
@@ -2,9 +2,13 @@
 
 namespace SMW;
 
+use SMWContainerSemanticData;
+use SMWDIContainer;
+use SMWDIWikiPage;
+use SMWDataValue;
+use SMWDIProperty;
+
 use Title;
-use MWException, ContextSource, IContextSource, RequestContext;
-use SMWPropertyValue, SMWDataValueFactory, SMWDIProperty, SMWDIWikiPage, 
SMWContainerSemanticData, SMWDIContainer;
 
 /**
  * Class to interact with a 'subobject'
@@ -34,58 +38,64 @@
 
 /**
  * Class to interact with a 'subobject'
+ *
  * @ingroup SMW
  */
-class Subobject extends ContextSource {
+class Subobject {
 
-       /**
-        * @var Title
-        */
+       /** @var Title */
         protected $title;
 
-       /**
-        * @var string
-        */
-        protected $subobjectName;
+       /** @var string */
+        protected $identifier;
 
-       /**
-        * @var SMWContainerSemanticData
-        */
+       /** @var SMWContainerSemanticData */
         protected $semanticData;
 
-       /**
-        * @var string[]
-        */
+       /** @var array */
        protected $errors = array();
 
        /**
-        * Constructor
-        *
         * @since 1.9
         *
-        * @param Title $subject
-        * @param string|null $subobjectName
-        * @param \IContextSource|null $context
-        *
+        * @param Title $title
         */
-       public function __construct( Title $title, $subobjectName = null, 
IContextSource $context = null ) {
-               if ( !$context ) {
-                       $context = RequestContext::getMain();
-               }
-               $this->setContext( $context );
+       public function __construct( Title $title ) {
                $this->title = $title;
-               $this->setSemanticData( $subobjectName );
        }
 
        /**
-        * Returns the subobject name
+        * Convenience method for immediate object instantiation that creates a
+        * subobject for a given title and identifier
+        *
+        * @par Example:
+        * @code
+        *  $subobject = Subobject::newFromId( 'Foo', 'Bar' );
+        *  $subobject->addPropertyValue( $dataValue )
+        * @endcode
+        *
+        * @since 1.9
+        *
+        * @param Title $title
+        * @param string|false $identifier
+        *
+        * @return Subobject
+        */
+       public static function newFromId( Title $title, $identifier = false ) {
+               $instance = new self( $title );
+               $instance->setSemanticData( $identifier );
+               return $instance;
+       }
+
+       /**
+        * Returns the subobject Id
         *
         * @since 1.9
         *
         * @return string
         */
-       public function getName() {
-               return $this->subobjectName;
+       public function getId() {
+               return $this->identifier;
        }
 
        /**
@@ -94,6 +104,7 @@
         * @since 1.9
         *
         * @param string
+        *
         * @return string
         */
        public function getAnonymousIdentifier( $string ) {
@@ -101,7 +112,7 @@
        }
 
        /**
-        * Return errors that happen during the insert procedure
+        * Returns an array of collected errors
         *
         * @since 1.9
         *
@@ -112,29 +123,45 @@
        }
 
        /**
-        * Sets the semantic data container for a subobject wikipage object
+        * Add errors that appeared during internal processing
         *
         * @since 1.9
         *
-        * @param string $subobjectName
-        *
-        * @return SMWContainerSemanticData
+        * @param array $error
         */
-       public function setSemanticData( $subobjectName ) {
-               if ( $subobjectName !== '' ) {
-                       $this->subobjectName = $subobjectName;
-
-                       $diSubWikiPage = new SMWDIWikiPage( 
$this->title->getDBkey(),
-                               $this->title->getNamespace(), 
$this->title->getInterwiki(),
-                               $subobjectName );
-
-                       return $this->semanticData = new 
SMWContainerSemanticData( $diSubWikiPage );
-               }
-               return '';
+       protected function addError( array $error ) {
+               $this->errors = array_merge( $this->errors, $error );
        }
 
        /**
-        * Returns semantic data container for a subject
+        * Initializes the semantic data container for a given identifier
+        * and its invoked subject
+        *
+        * @since 1.9
+        *
+        * @param string $identifier
+        *
+        * @return SMWContainerSemanticData
+        */
+       public function setSemanticData( $identifier ) {
+
+               if ( $identifier != '' ) {
+                       $this->identifier = $identifier;
+
+                       $diSubWikiPage = new SMWDIWikiPage(
+                               $this->title->getDBkey(),
+                               $this->title->getNamespace(),
+                               $this->title->getInterwiki(),
+                               $identifier
+                       );
+
+                       return $this->semanticData = new 
SMWContainerSemanticData( $diSubWikiPage );
+               }
+
+       }
+
+       /**
+        * Returns semantic data container for a subobject
         *
         * @since 1.9
         *
@@ -145,7 +172,7 @@
        }
 
        /**
-        * Returns subobject property data item
+        * Returns the property data item for the subobject
         *
         * @since 1.9
         *
@@ -156,7 +183,7 @@
        }
 
        /**
-        * Returns semantic data container for a subobject
+        * Returns the container data item for the subobject
         *
         * @since 1.9
         *
@@ -167,37 +194,46 @@
        }
 
        /**
-        * Add property / value to the semantic data container
+        * Adds a data value object to the semantic data container
+        *
+        * @par Example:
+        * @code
+        *  $dataValue = DataValueFactory::newPropertyValue( $userProperty, 
$userValue )
+        *
+        *  Subobject::newFromId( 'Foo', 'Bar' )->addPropertyValue( $dataValue )
+        * @endcode
         *
         * @since 1.9
         *
-        * @param string $propertyName
-        * @param string $valueString
+        * @param DataValue $dataValue
+        *
+        * @throws InvalidSemanticDataException
         */
-       public function addPropertyValue( $propertyName, $valueString ) {
+       public function addPropertyValue( SMWDataValue $dataValue ) {
+
                if ( !( $this->semanticData instanceof SMWContainerSemanticData 
) ) {
-                       throw new MWException( 'The semantic data container is 
not initialized' );
+                       throw new InvalidSemanticDataException( 'The semantic 
data container is not initialized' );
                }
 
-               $propertyDv = SMWPropertyValue::makeUserProperty( $propertyName 
);
-               $propertyDi = $propertyDv->getDataItem();
+               wfProfileIn( __METHOD__ );
 
-               if ( $propertyDi instanceof \SMWDIProperty && 
!$propertyDi->isInverse() ) {
-                       $valueDv = SMWDataValueFactory::newPropertyObjectValue( 
$propertyDi, $valueString,
-                               false, $this->semanticData->getSubject() );
-                       $this->semanticData->addPropertyObjectValue( 
$propertyDi, $valueDv->getDataItem() );
-
-                       // Take note of the error for storage (do this here and 
not in storage, thus avoiding duplicates).
-                       if ( !$valueDv->isValid() ) {
-                               $this->semanticData->addPropertyObjectValue( 
new SMWDIProperty( SMWDIProperty::TYPE_ERROR ),
-                                       $propertyDi->getDiWikiPage() );
-                               $this->errors = array_merge( $this->errors, 
$valueDv->getErrors() );
+               if ( $dataValue->getProperty() instanceof SMWDIProperty ) {
+                       if ( $dataValue->isValid() ) {
+                               $this->semanticData->addPropertyObjectValue(
+                                       $dataValue->getProperty(),
+                                       $dataValue->getDataItem()
+                               );
+                       } else {
+                               $this->semanticData->addPropertyObjectValue(
+                                       new SMWDIProperty( 
SMWDIProperty::TYPE_ERROR ),
+                                       
$dataValue->getProperty()->getDiWikiPage()
+                               );
+                               $this->addError( $dataValue->getErrors() );
                        }
-               } else if ( $propertyDi instanceof \SMWDIProperty && 
$propertyDi->isInverse() ) {
-                       $this->errors[] = wfMessage( 'smw_noinvannot' 
)->inContentLanguage()->text();
                } else {
-                       // FIXME Get message object
-                       $this->errors[] = wfMessage( 
'smw-property-name-invalid', $propertyName )->inContentLanguage()->text();
+                       $this->addError( $dataValue->getErrors() );
                }
+
+               wfProfileOut( __METHOD__ );
        }
 }
diff --git a/includes/exceptions/InvalidSemanticDataException.php 
b/includes/exceptions/InvalidSemanticDataException.php
new file mode 100644
index 0000000..210ea44
--- /dev/null
+++ b/includes/exceptions/InvalidSemanticDataException.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace SMW;
+
+use MWException;
+
+/**
+ * Exception for an invalid semantic data object
+ *
+ * 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 Exception
+ *
+ * @author mwjames
+ */
+
+/**
+ * Exception for an invalid semantic data object
+ *
+ * @ingroup Exception
+ * @codeCoverageIgnore
+ */
+class InvalidSemanticDataException extends MWException {}
\ No newline at end of file
diff --git a/includes/parserhooks/SubobjectParserFunction.php 
b/includes/parserhooks/SubobjectParserFunction.php
index e7c32cb..eb544c3 100644
--- a/includes/parserhooks/SubobjectParserFunction.php
+++ b/includes/parserhooks/SubobjectParserFunction.php
@@ -27,7 +27,6 @@
  * @since 1.9
  *
  * @file
- * @ingroup SMW
  * @ingroup ParserFunction
  *
  * @licence GNU GPL v2+
@@ -37,7 +36,6 @@
 /**
  * Class that provides the {{#subobject}} parser function
  *
- * @ingroup SMW
  * @ingroup ParserFunction
  */
 class SubobjectParserFunction {
@@ -97,7 +95,12 @@
                // Add property / values to the subobject instance
                foreach ( $parameters as $property => $values ){
                        foreach ( $values as $value ) {
-                               $this->subobject->addPropertyValue( $property, 
$value );
+                               $this->subobject->addPropertyValue(
+                                       DataValueFactory::newPropertyValue(
+                                               $property,
+                                               $value
+                                       )
+                               );
                        }
                }
        }
diff --git a/tests/phpunit/includes/SubobjectTest.php 
b/tests/phpunit/includes/SubobjectTest.php
index 386dd84..687b5a7 100644
--- a/tests/phpunit/includes/SubobjectTest.php
+++ b/tests/phpunit/includes/SubobjectTest.php
@@ -2,9 +2,10 @@
 
 namespace SMW\Test;
 
+use SMW\DataValueFactory;
 use SMW\Subobject;
-use SMWDIProperty;
 
+use SMWDIProperty;
 use Title;
 
 /**
@@ -28,7 +29,6 @@
  * @since 1.9
  *
  * @file
- * @ingroup SMW
  * @ingroup Test
  *
  * @licence GNU GPL v2+
@@ -39,7 +39,7 @@
  * Tests for the Subobject class
  * @covers \SMW\Subobject
  *
- * @ingroup SMW
+ * @ingroup Test
  *
  * @group SMW
  * @group SMWExtension
@@ -56,128 +56,39 @@
        }
 
        /**
-        * Provides sample data of combinations used in connection with a
-        * Subobject instance
+        * Helper method that returns a DataValue object
         *
-        * @return array
+        * @since 1.9
+        *
+        * @param $propertyName
+        * @param $value
+        *
+        * @return SMWDataValue
         */
-       public function getDataProvider() {
-               $diPropertyError = new SMWDIProperty( SMWDIProperty::TYPE_ERROR 
);
-               return array(
-                       // #0
-                       array(
-                               array(
-                                       'identifier' => 'Bar',
-                                       'property' => array( 'Foo' => 'bar' )
-                               ),
-                               array(
-                                       'name' => 'Bar',
-                                       'errors' => 0,
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'Foo',
-                                       'propertyValue' => 'Bar'
-                               )
-                       ),
-
-                       // #1
-                       array(
-                               array(
-                                       'identifier' => 'bar',
-                                       'property' => array( 'FooBar' => 'bar 
Foo' )
-                               ),
-                               array(
-                                       'name' => 'bar',
-                                       'errors' => 0,
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'FooBar',
-                                       'propertyValue' => 'Bar Foo',
-                               )
-                       ),
-
-                       // #2
-                       array(
-                               array(
-                                       'identifier' => 'foo',
-                                       'property' => array( 9001 => 1001 )
-                               ),
-                               array( // Expected results
-                                       'name' => 'foo',
-                                       'errors' => 0,
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => array( 9001 ),
-                                       'propertyValue' => array( 1001 ),
-                               )
-                       ),
-
-                       // #3
-                       array(
-                               array(
-                                       'identifier' => 'foo bar',
-                                       'property' => array( 1001 => 9001, 
'Foo' => 'Bar' )
-                               ),
-                               array( // Expected results
-                                       'name' => 'foo bar',
-                                       'errors' => 0,
-                                       'propertyCount' => 2,
-                                       'propertyLabel' => array( 1001, 'Foo' ),
-                                       'propertyValue' => array( 9001, 'Bar' ),
-                               )
-                       ),
-
-                       // #4 Property with leading underscore will raise error
-                       array(
-                               array(
-                                       'identifier' => 'bar',
-                                       'property' => array( '_FooBar' => 'bar 
Foo' )
-                               ),
-                               array(
-                                       'name' => 'bar',
-                                       'errors' => 1,
-                                       'propertyCount' => 0,
-                                       'propertyLabel' => '',
-                                       'propertyValue' => '',
-                               )
-                       ),
-
-                       // #5 Inverse property will raise error
-                       array(
-                               array(
-                                       'identifier' => 'bar',
-                                       'property' => array( '-FooBar' => 'bar 
Foo' )
-                               ),
-                               array(
-                                       'name' => 'bar',
-                                       'errors' => 1,
-                                       'propertyCount' => 0,
-                                       'propertyLabel' => '',
-                                       'propertyValue' => '',
-                               )
-                       ),
-
-                       // #6 Improper value for wikipage property will add an 
'Has improper value for'
-                       array(
-                               array(
-                                       'identifier' => 'bar',
-                                       'property' => array( 'Foo' => '' )
-                               ),
-                               array(
-                                       'name' => 'bar',
-                                       'errors' => 1,
-                                       'propertyCount' => 2,
-                                       'propertyLabel' => array( 
$diPropertyError->getLabel(), 'Foo' ),
-                                       'propertyValue' => 'Foo',
-                               )
-                       ),
-               );
+       private function getDataValue( $propertyName, $value ){
+               return DataValueFactory::newPropertyValue( $propertyName, 
$value );
        }
 
        /**
         * Helper method that returns a Subobject object
         *
+        * @since 1.9
+        *
+        * @param $title
+        * @param $id
+        *
         * @return Subobject
         */
-       private function getInstance( Title $title, $name = '') {
-               return new Subobject( $title, $name );
+       private function getInstance( Title $title, $id = '' ) {
+
+               $instance = new Subobject( $title );
+
+               if ( $id === '' && $id !== null ) {
+                       $id = $instance->getAnonymousIdentifier( 
$this->getRandomString() );
+               }
+
+               $instance->setSemanticData( $id );
+               return $instance;
        }
 
        /**
@@ -186,36 +97,61 @@
         * @since 1.9
         */
        public function testConstructor() {
+
                $instance = $this->getInstance( $this->getTitle() );
                $this->assertInstanceOf( $this->getClass(), $instance );
+
+       }
+
+       /**
+        * @test Subobject::newFromId
+        *
+        * @since 1.9
+        */
+       public function testNewFromId() {
+
+               $id = 'Foo';
+               $instance = Subobject::newFromId( $this->getTitle(), $id );
+
+               $this->assertInstanceOf( $this->getClass(), $instance );
+               $this->assertEquals( $id, $instance->getId() );
+
        }
 
        /**
         * @test Subobject::setSemanticData
-        * @dataProvider getDataProvider
         *
         * @since 1.9
-        *
-        * @param array $setup
         */
-       public function testSetSemanticData( array $setup ) {
-               $subobject = $this->getInstance( $this->getTitle() );
+       public function testSetSemanticData() {
 
-               $instance = $subobject->setSemanticData( $setup['identifier'] );
-               $this->assertInstanceOf( '\SMWContainerSemanticData', $instance 
);
+               $instance = $this->getInstance( $this->getTitle() );
+
+               $this->assertInstanceOf( '\SMWContainerSemanticData',
+                       $instance->setSemanticData( $this->getRandomString() )
+               );
+               $this->assertEmpty( $instance->setSemanticData( '' ) );
+
        }
 
        /**
-        * @test Subobject::getName
+        * @test Subobject::getId
         * @dataProvider getDataProvider
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @param array $test
+        * @param array $expected
+        * @param array $info
         */
-       public function testGetName( array $setup, array $expected ) {
-               $subobject = $this->getInstance( $this->getTitle(), 
$setup['identifier'] );
-               $this->assertEquals( $expected['name'], $subobject->getName() );
+       public function testGetId( array $test, array $expected, array $info ) {
+
+               $subobject = $this->getInstance( $this->getTitle(), 
$test['identifier'] );
+               // For an anonymous identifier we only use the first character 
as comparison
+               $id = $expected['identifier'] === '_' ? substr( 
$subobject->getId(), 0, 1 ) : $subobject->getId();
+
+               $this->assertEquals( $expected['identifier'], $id, $info['msg'] 
);
+
        }
 
        /**
@@ -224,11 +160,13 @@
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @param array $test
         */
-       public function testGetProperty( array $setup ) {
-               $subobject = $this->getInstance( $this->getTitle(), 
$setup['identifier'] );
+       public function testGetProperty( array $test ) {
+
+               $subobject = $this->getInstance( $this->getTitle(), 
$test['identifier'] );
                $this->assertInstanceOf( '\SMWDIProperty', 
$subobject->getProperty() );
+
        }
 
        /**
@@ -237,38 +175,39 @@
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @param array $test
         * @param array $expected
+        * @param array $info
         */
-       public function testAddPropertyValue( array $setup, array $expected ) {
-               $subobject = $this->getInstance( $this->getTitle(), 
$setup['identifier'] );
+       public function testAddPropertyValue( array $test, array $expected, 
array $info ) {
 
-               foreach ( $setup['property'] as $property => $value ){
-                       $subobject->addPropertyValue( $property, $value );
+               $subobject = $this->getInstance( $this->getTitle(), 
$test['identifier'] );
+
+               foreach ( $test['properties'] as $property => $value ){
+                       $subobject->addPropertyValue(
+                               $this->getDataValue( $property, $value )
+                       );
                }
 
-               // Check errors
-               $this->assertCount( $expected['errors'], 
$subobject->getErrors() );
-
-               $this->assertInstanceOf( 'SMWSemanticData', 
$subobject->getSemanticData() );
+               $this->assertCount( $expected['errors'], 
$subobject->getErrors(), $info['msg'] );
+               $this->assertInstanceOf( 'SMWSemanticData', 
$subobject->getSemanticData(), $info['msg'] );
                $this->assertSemanticData( $subobject->getSemanticData(), 
$expected );
+
        }
 
        /**
-        * @test Subobject::addPropertyValue (test exception)
-        * @dataProvider getDataProvider
+        * @test Subobject::addPropertyValue
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @throws InvalidSemanticDataException
         */
-       public function testAddPropertyValueStringException( array $setup ) {
-               $this->setExpectedException( 'MWException' );
-               $subobject = $this->getInstance( $this->getTitle() );
+       public function testAddPropertyValueStringException() {
 
-               foreach ( $setup['property'] as $property => $value ){
-                       $subobject->addPropertyValue( $property, $value );
-               }
+               $this->setExpectedException( 
'\SMW\InvalidSemanticDataException' );
+               $subobject = new Subobject(  $this->getTitle() );
+               $subobject->addPropertyValue( $this->getDataValue( 'Foo', 'Bar' 
) );
+
        }
 
        /**
@@ -277,13 +216,19 @@
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @param array $test
+        * @param array $expected
+        * @param array $info
         */
-       public function testGetAnonymousIdentifier( array $setup ) {
+       public function testGetAnonymousIdentifier( array $test, array 
$expected, array $info ) {
+
                $subobject = $this->getInstance( $this->getTitle() );
-               // Looking for the _ instead of comparing the hash key as it
-               // can change with the method applied (md4, sha1 etc.)
-               $this->assertContains( '_', $subobject->getAnonymousIdentifier( 
$setup['identifier'] ) );
+               $this->assertEquals(
+                       '_',
+                       substr( $subobject->getAnonymousIdentifier( 
$test['identifier'] ), 0, 1 ),
+                       $info['msg']
+               );
+
        }
 
        /**
@@ -292,10 +237,138 @@
         *
         * @since 1.9
         *
-        * @param array $setup
+        * @param array $test
+        * @param array $expected
+        * @param array $info
         */
-       public function testGetContainer( array $setup ) {
-               $subobject = $this->getInstance( $this->getTitle(), 
$setup['identifier'] );
-               $this->assertInstanceOf( '\SMWDIContainer', 
$subobject->getContainer() );
+       public function testGetContainer( array $test, array $expected, array 
$info  ) {
+
+               $subobject = $this->getInstance( $this->getTitle(), 
$test['identifier'] );
+               $this->assertInstanceOf( '\SMWDIContainer',     
$subobject->getContainer(), $info['msg'] );
+
+       }
+
+       /**
+        * Provides sample data of combinations used in connection with a
+        * Subobject instance
+        *
+        * @return array
+        */
+       public function getDataProvider() {
+               $diPropertyError = new SMWDIProperty( SMWDIProperty::TYPE_ERROR 
);
+               return array(
+
+                       // #0
+                       array(
+                               array(
+                                       'identifier' => 'Bar',
+                                       'properties' => array( 'Foo' => 'bar' )
+                               ),
+                               array(
+                                       'errors' => 0,
+                                       'identifier' => 'Bar',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'Foo',
+                                       'propertyValue' => 'Bar',
+                               ),
+                               array( 'msg'  => 'Failed asserting conditions 
for a named identifier' )
+                       ),
+
+                       // #1
+                       array(
+                               array(
+                                       'identifier' => '',
+                                       'properties' => array( 'FooBar' => 'bar 
Foo' )
+                               ),
+                               array(
+                                       'errors' => 0,
+                                       'identifier' => '_',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'FooBar',
+                                       'propertyValue' => 'Bar Foo',
+                               ),
+                               array( 'msg'  => 'Failed asserting conditions 
for an anon identifier' )
+                       ),
+
+                       // #2
+                       array(
+                               array(
+                                       'identifier' => 'foo',
+                                       'properties' => array( 9001 => 1001 )
+                               ),
+                               array(
+                                       'errors' => 0,
+                                       'identifier' => 'foo',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => array( 9001 ),
+                                       'propertyValue' => array( 1001 ),
+                               ),
+                               array( 'msg'  => 'Failed asserting conditions' )
+                       ),
+
+                       // #3
+                       array(
+                               array(
+                                       'identifier' => 'foo bar',
+                                       'properties' => array( 1001 => 9001, 
'Foo' => 'Bar' )
+                               ),
+                               array(
+                                       'errors' => 0,
+                                       'identifier' => 'foo bar',
+                                       'propertyCount' => 2,
+                                       'propertyLabel' => array( 1001, 'Foo' ),
+                                       'propertyValue' => array( 9001, 'Bar' ),
+                               ),
+                               array( 'msg'  => 'Failed asserting conditions' )
+                       ),
+
+                       // #4
+                       array(
+                               array(
+                                       'identifier' => 'bar',
+                                       'properties' => array( '_FooBar' => 
'bar Foo' )
+                               ),
+                               array(
+                                       'errors' => 1,
+                                       'identifier' => 'bar',
+                                       'propertyCount' => 0,
+                                       'propertyLabel' => '',
+                                       'propertyValue' => '',
+                               ),
+                               array( 'msg'  => 'Failed asserting that a 
property with a leading underscore would produce an error' )
+                       ),
+
+                       // #5
+                       array(
+                               array(
+                                       'identifier' => 'bar',
+                                       'properties' => array( '-FooBar' => 
'bar Foo' )
+                               ),
+                               array(
+                                       'errors' => 1,
+                                       'identifier' => 'bar',
+                                       'propertyCount' => 0,
+                                       'propertyLabel' => '',
+                                       'propertyValue' => '',
+                               ),
+                               array( 'msg'  => 'Failed asserting that an 
inverse property would produce an error' )
+                       ),
+
+                       // #6
+                       array(
+                               array(
+                                       'identifier' => 'bar',
+                                       'properties' => array( 'Foo' => '' )
+                               ),
+                               array(
+                                       'identifier' => 'bar',
+                                       'errors' => 1,
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => array( 
$diPropertyError->getLabel() ),
+                                       'propertyValue' => 'Foo',
+                               ),
+                               array( 'msg'  => 'Failed asserting that an 
improper value for a _wpg property would add "Has improper value for"' )
+                       )
+               );
        }
 }
diff --git a/tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php 
b/tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php
index 07cef5b..d88bf68 100644
--- a/tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php
+++ b/tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php
@@ -12,7 +12,7 @@
 use ParserOutput;
 
 /**
- * Tests for the SMW\SubobjectParserFunction class
+ * Tests for the SubobjectParserFunction 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
@@ -39,7 +39,7 @@
  */
 
 /**
- * Tests for the SMW\SubobjectParserFunction class
+ * Tests for the SubobjectParserFunction class
  * @covers \SMW\SubobjectParserFunction
  *
  * @ingroup Test
@@ -56,133 +56,6 @@
         */
        public function getClass() {
                return '\SMW\SubobjectParserFunction';
-       }
-
-       /**
-        * Provides data sample normally found in connection with the 
{{#subobject}}
-        * parser function. The first array contains parametrized input value 
while
-        * the second array contains expected return results for the 
instantiated
-        * object.
-        *
-        * @return array
-        */
-       public function getSubobjectDataProvider() {
-               // Get the right language for an error object
-               $diPropertyError = new SMWDIProperty( SMWDIProperty::TYPE_ERROR 
);
-
-               return array(
-
-                       // Anonymous identifier
-                       // {{#subobject:
-                       // |Foo=bar
-                       // }}
-                       array(
-                               array( '', 'Foo=bar' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => '_',
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'Foo',
-                                       'propertyValue' => 'Bar'
-                               )
-                       ),
-
-                       // Anonymous identifier
-                       // {{#subobject:-
-                       // |Foo=1001 9009
-                       // }}
-                       array(
-                               array( '-', 'Foo=1001 9009' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => '_',
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'Foo',
-                                       'propertyValue' => '1001 9009'
-                               )
-                       ),
-
-                       // Named identifier
-                       // {{#subobject:FooBar
-                       // |FooBar=Bar foo
-                       // }}
-                       array(
-                               array( 'FooBar', 'FooBar=Bar foo' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => 'FooBar',
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'FooBar',
-                                       'propertyValue' => 'Bar foo'
-                               )
-                       ),
-
-                       // Named identifier
-                       // {{#subobject:Foo bar
-                       // |Foo=Help:Bar
-                       // }}
-                       array(
-                               array( 'Foo bar', 'Foo=Help:Bar' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => 'Foo_bar',
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'Foo',
-                                       'propertyValue' => 'Help:Bar'
-                               )
-                       ),
-
-                       // Named identifier
-                       // {{#subobject: Foo bar foo
-                       // |Bar=foo Bar
-                       // }}
-                       array(
-                               array( ' Foo bar foo ', 'Bar=foo Bar' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => 'Foo_bar_foo',
-                                       'propertyCount' => 1,
-                                       'propertyLabel' => 'Bar',
-                                       'propertyValue' => 'Foo Bar'
-                               )
-                       ),
-
-                       // Named identifier
-                       // {{#subobject: Foo bar foo
-                       // |状況=超やばい
-                       // 
|Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject
-                       // }}
-                       array(
-                               array(
-                                       ' Foo bar foo ',
-                                       '状況=超やばい',
-                                       
'Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject' ),
-                               array(
-                                       'errors' => false,
-                                       'name' => 'Foo_bar_foo',
-                                       'propertyCount' => 2,
-                                       'propertyLabel' => array( '状況', 'Bar' ),
-                                       'propertyValue' => array( '超やばい', 
'Http://www.semantic-mediawiki.org/w/index.php?title=Subobject' )
-                               )
-                       ),
-
-                       // Returns an error due to wrong declaration (see 
Modification date)
-
-                       // {{#subobject: Foo bar foo
-                       // |Bar=foo Bar
-                       // |Modification date=foo Bar
-                       // }}
-                       array(
-                               array( ' Foo bar foo ', 'Modification date=foo 
Bar' ),
-                               array(
-                                       'errors' => true,
-                                       'name' => 'Foo_bar_foo',
-                                       'propertyCount' => 2,
-                                       'propertyLabel' => array( 'Modification 
date', $diPropertyError->getLabel() ),
-                                       'propertyValue' => array( 'Foo Bar', 
'Modification date' )
-                               )
-                       ),
-               );
        }
 
        /**
@@ -234,11 +107,8 @@
        public function testParse( array $params, array $expected ) {
                $instance = $this->getInstance( $this->getTitle(), 
$this->getParserOutput() );
                $result = $instance->parse( $this->getParserParameterFormatter( 
$params ) );
-               if ( $result !== '' ){
-                       $this->assertTrue( $expected['errors'] );
-               } else {
-                       $this->assertFalse( $expected['errors'] );
-               }
+               $this->assertEquals( $result !== '' , $expected['errors'] );
+
        }
 
        /**
@@ -253,7 +123,7 @@
        public function testInstantiatedSubobject( array $params, array 
$expected ) {
                $instance = $this->getInstance( $this->getTitle(), 
$this->getParserOutput() );
                $instance->parse( $this->getParserParameterFormatter( $params ) 
);
-               $this->assertContains( $expected['name'], 
$instance->getSubobject()->getName() );
+               $this->assertContains( $expected['identifier'], 
$instance->getSubobject()->getId() );
        }
 
        /**
@@ -298,4 +168,131 @@
                $result = SubobjectParserFunction::render( $parser );
                $this->assertInternalType( 'string', $result );
        }
+
+       /**
+        * Provides data sample normally found in connection with the 
{{#subobject}}
+        * parser function. The first array contains parametrized input value 
while
+        * the second array contains expected return results for the 
instantiated
+        * object.
+        *
+        * @return array
+        */
+       public function getSubobjectDataProvider() {
+               // Get the right language for an error object
+               $diPropertyError = new SMWDIProperty( SMWDIProperty::TYPE_ERROR 
);
+
+               return array(
+
+                       // Anonymous identifier
+                       // {{#subobject:
+                       // |Foo=bar
+                       // }}
+                       array(
+                               array( '', 'Foo=bar' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => '_',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'Foo',
+                                       'propertyValue' => 'Bar'
+                               )
+                       ),
+
+                       // Anonymous identifier
+                       // {{#subobject:-
+                       // |Foo=1001 9009
+                       // }}
+                       array(
+                               array( '-', 'Foo=1001 9009' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => '_',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'Foo',
+                                       'propertyValue' => '1001 9009'
+                               )
+                       ),
+
+                       // Named identifier
+                       // {{#subobject:FooBar
+                       // |FooBar=Bar foo
+                       // }}
+                       array(
+                               array( 'FooBar', 'FooBar=Bar foo' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => 'FooBar',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'FooBar',
+                                       'propertyValue' => 'Bar foo'
+                               )
+                       ),
+
+                       // Named identifier
+                       // {{#subobject:Foo bar
+                       // |Foo=Help:Bar
+                       // }}
+                       array(
+                               array( 'Foo bar', 'Foo=Help:Bar' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => 'Foo_bar',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'Foo',
+                                       'propertyValue' => 'Help:Bar'
+                               )
+                       ),
+
+                       // Named identifier
+                       // {{#subobject: Foo bar foo
+                       // |Bar=foo Bar
+                       // }}
+                       array(
+                               array( ' Foo bar foo ', 'Bar=foo Bar' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => 'Foo_bar_foo',
+                                       'propertyCount' => 1,
+                                       'propertyLabel' => 'Bar',
+                                       'propertyValue' => 'Foo Bar'
+                               )
+                       ),
+
+                       // Named identifier
+                       // {{#subobject: Foo bar foo
+                       // |状況=超やばい
+                       // 
|Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject
+                       // }}
+                       array(
+                               array(
+                                       ' Foo bar foo ',
+                                       '状況=超やばい',
+                                       
'Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject' ),
+                               array(
+                                       'errors' => false,
+                                       'identifier' => 'Foo_bar_foo',
+                                       'propertyCount' => 2,
+                                       'propertyLabel' => array( '状況', 'Bar' ),
+                                       'propertyValue' => array( '超やばい', 
'Http://www.semantic-mediawiki.org/w/index.php?title=Subobject' )
+                               )
+                       ),
+
+                       // Returns an error due to wrong declaration (see 
Modification date)
+
+                       // {{#subobject: Foo bar foo
+                       // |Bar=foo Bar
+                       // |Modification date=foo Bar
+                       // }}
+                       array(
+                               array( ' Foo bar foo ', 'Bar=foo Bar', 
'Modification date=foo Bar' ),
+                               array(
+                                       'errors' => true,
+                                       'identifier' => 'Foo_bar_foo',
+                                       'propertyCount' => 2,
+                                       'propertyLabel' => array( 'Bar', 
$diPropertyError->getLabel() ),
+                                       'propertyValue' => array( 'Foo Bar', 
'Modification date' )
+                               )
+                       ),
+               );
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icc1c7287fec8c3022fe016e985f748eef4dfd7ed
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to