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

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


Improve code coverage

Change-Id: I665859553db834c086e8fcbc0e5290fa1bc304f6
---
M includes/SMW_ParseData.php
M tests/phpunit/MockObjectRepository.php
M tests/phpunit/includes/DataValueFactoryTest.php
3 files changed, 232 insertions(+), 100 deletions(-)

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



diff --git a/includes/SMW_ParseData.php b/includes/SMW_ParseData.php
index 3898cd6..98c8b63 100644
--- a/includes/SMW_ParseData.php
+++ b/includes/SMW_ParseData.php
@@ -10,6 +10,13 @@
  */
 
 /**
+ * @codeCoverageIgnore
+ *
+ * THIS CLASS IS OBSOLETE AND SHOULD NOT BE USED BEYOND SMW 1.8. THIS CLASS
+ * WILL BE REMOVED IN SMW 1.10.
+ *
+ * Use SMW\ParserData instead
+ *
  * Static class for managing semantic data collected during parsing, including
  * some hooks that can be used for updating and storing the data for some
  * article. All methods in this class are stateless: data is stored 
persistently
diff --git a/tests/phpunit/MockObjectRepository.php 
b/tests/phpunit/MockObjectRepository.php
index 747981c..9c2fee1 100644
--- a/tests/phpunit/MockObjectRepository.php
+++ b/tests/phpunit/MockObjectRepository.php
@@ -508,6 +508,10 @@
                        ->method( 'findPropertyTypeID' )
                        ->will( $this->returnValue( $this->builder->setValue( 
'findPropertyTypeID', '_wpg' ) ) );
 
+               $diWikiPage->expects( $this->any() )
+                       ->method( 'getSubobjectName' )
+                       ->will( $this->returnValue( $this->builder->setValue( 
'getSubobjectName', '' ) ) );
+
                return $diWikiPage;
        }
 
diff --git a/tests/phpunit/includes/DataValueFactoryTest.php 
b/tests/phpunit/includes/DataValueFactoryTest.php
index 7e855f6..80ac5ff 100644
--- a/tests/phpunit/includes/DataValueFactoryTest.php
+++ b/tests/phpunit/includes/DataValueFactoryTest.php
@@ -22,7 +22,6 @@
  */
 
 /**
- * Tests for the SMW\DataValueFactory class
  * @covers \SMW\DataValueFactory
  *
  * @ingroup Test
@@ -42,21 +41,6 @@
        }
 
        /**
-        * DataProvider
-        *
-        * @return array
-        */
-       public function dataItemIdDataProvider() {
-               return array(
-                       array( '_txt' , SMWDataItem::TYPE_BLOB ), // #0
-                       array( '_wpg' , SMWDataItem::TYPE_WIKIPAGE ), // #1
-                       array( '_num' , SMWDataItem::TYPE_NUMBER ), // #2
-                       array( '_dat' , SMWDataItem::TYPE_TIME ), // #3
-                       array( '_uri' , SMWDataItem::TYPE_URI ), // #4
-               );
-       }
-
-       /**
         * @test DataValueFactory::getDataItemId
         * @dataProvider dataItemIdDataProvider
         *
@@ -67,38 +51,6 @@
         */
        public function testGetDataItemId( $typeId, $expectedId ) {
                $this->assertEquals( $expectedId, 
DataValueFactory::getDataItemId( $typeId ) );
-       }
-
-       /**
-        * DataProvider
-        *
-        * @return array
-        */
-       public function typeIdValueDataProvider() {
-               return array(
-                       array( '_txt'  , 'Bar'          , 'Bar'          , 
'SMWStringValue' ), // #0
-                       array( '_txt'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWStringValue' ), // #1
-                       array( '_txt'  , '9001'         , '9001'         , 
'SMWStringValue' ), // #2
-                       array( '_txt'  , 1001           , '1001'         , 
'SMWStringValue' ), // #3
-                       array( '_txt'  , '-%&$*'        , '-%&$*'        , 
'SMWStringValue' ), // #4
-                       array( '_txt'  , '_Bar'         , '_Bar'         , 
'SMWStringValue' ), // #5
-                       array( '_txt'  , 'bar'          , 'bar'          , 
'SMWStringValue' ), // #6
-                       array( '-_txt' , 'Bar'          , 'Bar'          , 
'SMWErrorValue' ), // #7
-
-                       array( '_wpg'  , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #8
-                       array( '_wpg'  , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #9
-                       array( '_wpg'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWWikiPageValue' ), // #10
-                       array( '_wpg'  , '9001'         , '9001'         , 
'SMWWikiPageValue' ), // #11
-                       array( '_wpg'  , 1001           , '1001'         , 
'SMWWikiPageValue' ), // #12
-                       array( '_wpg'  , '-%&$*'        , '-%&$*'        , 
'SMWWikiPageValue' ), // #13
-                       array( '_wpg'  , '_Bar'         , 'Bar'          , 
'SMWWikiPageValue' ), // #14
-                       array( '_wpg'  , 'bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #15
-                       array( '-_wpg' , 'Bar'          , 'Bar'          , 
'SMWErrorValue' ), // #16
-
-                       array( '_dat' , '1 Jan 1970'    , '1 Jan 1970'   , 
'SMWTimeValue' ), // #0
-                       array( '_uri' , 'Foo'           , 'Foo'          , 
'SMWURIValue' ), // #0
-                       array( '_num' , 9001            , '9,001'        , 
'SMWNumberValue' ), // #0
-               );
        }
 
        /**
@@ -123,29 +75,6 @@
                        $this->assertInternalType( 'array', 
$dataValue->getErrors() );
                }
 
-       }
-
-       /**
-        * DataProvider
-        *
-        * @return array
-        */
-       public function propertyObjectValueDataProvider() {
-               return array(
-                       array( 'Foo'  , 'Bar'          , 'Bar'          , 
'SMWDataValue' ), // #0
-                       array( 'Foo'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWDataValue' ), // #1
-                       array( 'Foo'  , '9001'         , '9001'         , 
'SMWDataValue' ), // #2
-                       array( 'Foo'  , 1001           , '1001'         , 
'SMWDataValue' ), // #3
-                       array( 'Foo'  , '-%&$*'        , '-%&$*'        , 
'SMWDataValue' ), // #4
-                       array( 'Foo'  , '_Bar'         , 'Bar'          , 
'SMWDataValue' ), // #5
-                       array( 'Foo'  , 'bar'          , 'Bar'          , 
'SMWDataValue' ), // #6
-                       array( '-Foo' , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #7
-
-                       // Will fail with "must be an instance of 
SMWDIProperty, instance of SMWDIError give"
-                       // as propertyDI isn't checked therefore 
addPropertyValue() should be
-                       // used as it will return a proper object
-                       // array( '_Foo' , 'Bar'          , ''             , 
'SMWDIProperty' ), // #8
-               );
        }
 
        /**
@@ -191,25 +120,6 @@
        }
 
        /**
-        * DataProvider
-        *
-        * @return array
-        */
-       public function propertyValueDataProvider() {
-               return array(
-                       array( 'Foo'  , 'Bar'          , 'Bar'          , 
'SMWDataValue' ), // #0
-                       array( 'Foo'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWDataValue' ), // #1
-                       array( 'Foo'  , '9001'         , '9001'         , 
'SMWDataValue' ), // #2
-                       array( 'Foo'  , 1001           , '1001'         , 
'SMWDataValue' ), // #3
-                       array( 'Foo'  , '-%&$*'        , '-%&$*'        , 
'SMWDataValue' ), // #4
-                       array( 'Foo'  , '_Bar'         , 'Bar'          , 
'SMWDataValue' ), // #5
-                       array( 'Foo'  , 'bar'          , 'Bar'          , 
'SMWDataValue' ), // #6
-                       array( '-Foo' , 'Bar'          , ''             , 
'SMWErrorValue' ), // #7
-                       array( '_Foo' , 'Bar'          , ''             , 
'SMWPropertyValue' ), // #8
-               );
-       }
-
-       /**
         * @test DataValueFactory::addPropertyValue
         * @dataProvider propertyValueDataProvider
         *
@@ -249,8 +159,148 @@
        }
 
        /**
-        * DataProvider
+        * @test DataValueFactory::findTypeID
+        * @dataProvider findTypeIdDataProvider
         *
+        * @since 1.9
+        *
+        * @param $typeId
+        * @param $expectedId
+        */
+       public function testFindTypeID( $typeId, $expectedId ) {
+               $this->assertEquals( $expectedId, DataValueFactory::findTypeID( 
$typeId ) );
+       }
+
+       /**
+        * @test DataValueFactory::findTypeID
+        * @dataProvider findTypeIdDataProvider
+        *
+        * @since 1.9
+        *
+        * @param $typeId
+        * @param $expectedId
+        */
+       public function testFindTypeLabel( $textId, $id ) {
+
+               $textId = $textId === 'String' ? 'Text' : $textId;
+
+               $this->assertEquals(
+                       $textId,
+                       DataValueFactory::findTypeLabel( $id ),
+                       'Asserts that findTypeLabel() returns a user label'
+               );
+
+       }
+
+       /**
+        * @test DataValueFactory::getKnownTypeLabels
+        *
+        * @since 1.9
+        *
+        * @param $typeId
+        * @param $expectedId
+        */
+       public function testGetKnownTypeLabels() {
+
+               $this->assertInternalType(
+                       'array',
+                       DataValueFactory::getKnownTypeLabels(),
+                       'Asserts that getKnownTypeLabels() returns an array'
+               );
+
+       }
+
+       /**
+        * @test DataValueFactory::registerDatatypeAlias
+        *
+        * @since 1.9
+        *
+        * @param $typeId
+        * @param $expectedId
+        */
+       public function testRegisterDatatypeAlias() {
+
+               DataValueFactory::registerDatatypeAlias( '_foo', 'Bar' );
+
+               $this->assertEquals(
+                       '_foo',
+                       DataValueFactory::findTypeID( 'Bar' ),
+                       'Asserts that registerDatatypeAlias() registered an 
alias'
+               );
+
+       }
+
+       /**
+        * @test DataValueFactory::newDataItemValue
+        * @dataProvider newDataItemValueDataProvider
+        *
+        * @since 1.9
+        *
+        * @param $typeId
+        * @param $expectedId
+        */
+       public function testNewDataItemValue( $setup ) {
+
+               $dataValue = DataValueFactory::newDataItemValue( 
$setup['dataItem'], $setup['property'], $setup['caption'] );
+
+               $this->assertInstanceOf(
+                       'SMWDataValue',
+                       $dataValue,
+                       'Asserts that newDataItemValue() yields a SMWDatavalue'
+               );
+
+       }
+
+       /**
+        * @return array
+        */
+       public function newDataItemValueDataProvider() {
+
+               $provider = array();
+
+               $dataItem = $this->newMockBuilder()->newObject( 'DIWikiPage' );
+               $property = $this->newMockBuilder()->newObject( 'DIProperty' );
+
+               // #0
+               $provider[] = array(
+                       array(
+                               'dataItem' => $dataItem,
+                               'property' => null,
+                               'caption'  => false
+                       )
+               );
+
+               // #0
+               $provider[] = array(
+                       array(
+                               'dataItem' => $dataItem,
+                               'property' => $property,
+                               'caption'  => false
+                       )
+               );
+
+               // #1
+               $provider[] = array(
+                       array(
+                               'dataItem' => $dataItem,
+                               'property' => null,
+                               'caption'  => 'Foo'
+                       )
+               );
+
+               // #2
+               $provider[] = array(
+                       array(
+                               'dataItem' => $dataItem,
+                               'property' => $property,
+                               'caption'  => 'Bar'
+                       )
+               );
+
+               return $provider;
+       }
+
+       /**
         * @return array
         */
        public function findTypeIdDataProvider() {
@@ -263,19 +313,90 @@
                        array( 'Quantity' , '_qty' ), // #5
                        array( 'Date'     , '_dat' ), // #6
                        array( 'Email'    , '_ema' ), // #7
+                       array( ''         , ''     ), // #8
                );
        }
 
        /**
-        * @test DataValueFactory::findTypeID
-        * @dataProvider findTypeIdDataProvider
-        *
-        * @since 1.9
-        *
-        * @param $typeId
-        * @param $expectedId
+        * @return array
         */
-       public function testFindTypeID( $typeId, $expectedId ) {
-               $this->assertEquals( $expectedId, DataValueFactory::findTypeID( 
$typeId ) );
+       public function dataItemIdDataProvider() {
+               return array(
+                       array( '_txt' , SMWDataItem::TYPE_BLOB ), // #0
+                       array( '_wpg' , SMWDataItem::TYPE_WIKIPAGE ), // #1
+                       array( '_num' , SMWDataItem::TYPE_NUMBER ), // #2
+                       array( '_dat' , SMWDataItem::TYPE_TIME ), // #3
+                       array( '_uri' , SMWDataItem::TYPE_URI ), // #4
+                       array( '_foo' , SMWDataItem::TYPE_NOTYPE ), // #5
+               );
        }
+
+       /**
+        * @return array
+        */
+       public function typeIdValueDataProvider() {
+               return array(
+                       array( '_txt'  , 'Bar'          , 'Bar'          , 
'SMWStringValue' ), // #0
+                       array( '_txt'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWStringValue' ), // #1
+                       array( '_txt'  , '9001'         , '9001'         , 
'SMWStringValue' ), // #2
+                       array( '_txt'  , 1001           , '1001'         , 
'SMWStringValue' ), // #3
+                       array( '_txt'  , '-%&$*'        , '-%&$*'        , 
'SMWStringValue' ), // #4
+                       array( '_txt'  , '_Bar'         , '_Bar'         , 
'SMWStringValue' ), // #5
+                       array( '_txt'  , 'bar'          , 'bar'          , 
'SMWStringValue' ), // #6
+                       array( '-_txt' , 'Bar'          , 'Bar'          , 
'SMWErrorValue' ), // #7
+
+                       array( '_wpg'  , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #8
+                       array( '_wpg'  , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #9
+                       array( '_wpg'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWWikiPageValue' ), // #10
+                       array( '_wpg'  , '9001'         , '9001'         , 
'SMWWikiPageValue' ), // #11
+                       array( '_wpg'  , 1001           , '1001'         , 
'SMWWikiPageValue' ), // #12
+                       array( '_wpg'  , '-%&$*'        , '-%&$*'        , 
'SMWWikiPageValue' ), // #13
+                       array( '_wpg'  , '_Bar'         , 'Bar'          , 
'SMWWikiPageValue' ), // #14
+                       array( '_wpg'  , 'bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #15
+                       array( '-_wpg' , 'Bar'          , 'Bar'          , 
'SMWErrorValue' ), // #16
+
+                       array( '_dat' , '1 Jan 1970'    , '1 Jan 1970'   , 
'SMWTimeValue' ), // #0
+                       array( '_uri' , 'Foo'           , 'Foo'          , 
'SMWURIValue' ), // #0
+                       array( '_num' , 9001            , '9,001'        , 
'SMWNumberValue' ), // #0
+               );
+       }
+
+       /**
+        * @return array
+        */
+       public function propertyValueDataProvider() {
+               return array(
+                       array( 'Foo'  , 'Bar'          , 'Bar'          , 
'SMWDataValue' ), // #0
+                       array( 'Foo'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWDataValue' ), // #1
+                       array( 'Foo'  , '9001'         , '9001'         , 
'SMWDataValue' ), // #2
+                       array( 'Foo'  , 1001           , '1001'         , 
'SMWDataValue' ), // #3
+                       array( 'Foo'  , '-%&$*'        , '-%&$*'        , 
'SMWDataValue' ), // #4
+                       array( 'Foo'  , '_Bar'         , 'Bar'          , 
'SMWDataValue' ), // #5
+                       array( 'Foo'  , 'bar'          , 'Bar'          , 
'SMWDataValue' ), // #6
+                       array( '-Foo' , 'Bar'          , ''             , 
'SMWErrorValue' ), // #7
+                       array( '_Foo' , 'Bar'          , ''             , 
'SMWPropertyValue' ), // #8
+               );
+       }
+
+       /**
+        * @return array
+        */
+       public function propertyObjectValueDataProvider() {
+               return array(
+                       array( 'Foo'  , 'Bar'          , 'Bar'          , 
'SMWDataValue' ), // #0
+                       array( 'Foo'  , 'Bar[[ Foo ]]' , 'Bar[[ Foo ]]' , 
'SMWDataValue' ), // #1
+                       array( 'Foo'  , '9001'         , '9001'         , 
'SMWDataValue' ), // #2
+                       array( 'Foo'  , 1001           , '1001'         , 
'SMWDataValue' ), // #3
+                       array( 'Foo'  , '-%&$*'        , '-%&$*'        , 
'SMWDataValue' ), // #4
+                       array( 'Foo'  , '_Bar'         , 'Bar'          , 
'SMWDataValue' ), // #5
+                       array( 'Foo'  , 'bar'          , 'Bar'          , 
'SMWDataValue' ), // #6
+                       array( '-Foo' , 'Bar'          , 'Bar'          , 
'SMWWikiPageValue' ), // #7
+
+                       // Will fail with "must be an instance of 
SMWDIProperty, instance of SMWDIError give"
+                       // as propertyDI isn't checked therefore 
addPropertyValue() should be
+                       // used as it will return a proper object
+                       // array( '_Foo' , 'Bar'          , ''             , 
'SMWDIProperty' ), // #8
+               );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I665859553db834c086e8fcbc0e5290fa1bc304f6
Gerrit-PatchSet: 1
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