Addshore has uploaded a new change for review.

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

Change subject: Simplify use of Result::getResultData in ResultBuilderTest
......................................................................

Simplify use of Result::getResultData in ResultBuilderTest

Change-Id: Id1978037486264095390c5ff863051db849a97ff
---
M repo/tests/phpunit/includes/api/ResultBuilderTest.php
1 file changed, 176 insertions(+), 204 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/28/224428/1

diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php 
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
index 8dba655..f2d607c 100644
--- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -119,11 +119,9 @@
                $result = $this->getDefaultResult();
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->markSuccess( $param );
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( array( 'success' => $expected ), $data );
        }
 
@@ -177,135 +175,138 @@
 
                $entityRevision = new EntityRevision( $item, 33, 
'20131126202923' );
 
-               $expected = array( 'entities' => array( 'Q1230000' => array(
-                       'pageid' => 123, //mocked
-                       'ns' => 456, //mocked
-                       'title' => 'MockPrefixedText', //mocked
-                       'id' => 'Q123098',
-                       'type' => 'item',
-                       'lastrevid' => 33,
-                       'modified' => '2013-11-26T20:29:23Z',
-                       'redirects' => array(
-                               'from' => 'Q1230000',
-                               'to' => 'Q123098',
-                       ),
-                       'aliases' => array(
-                               'en' => array(
-                                       array(
-                                               'language' => 'en',
-                                               'value' => 'bar'
+               $expected = array(
+                       'entities' => array(
+                               'Q1230000' => array(
+                                       'pageid' => 123, //mocked
+                                       'ns' => 456, //mocked
+                                       'title' => 'MockPrefixedText', //mocked
+                                       'id' => 'Q123098',
+                                       'type' => 'item',
+                                       'lastrevid' => 33,
+                                       'modified' => '2013-11-26T20:29:23Z',
+                                       'redirects' => array(
+                                               'from' => 'Q1230000',
+                                               'to' => 'Q123098',
                                        ),
-                                       array(
-                                               'language' => 'en',
-                                               'value' => 'baz'
-                                       )
-                               ),
-                               'zh' => array(
-                                       array(
-                                               'language' => 'zh',
-                                               'value' => '????????',
-                                       ),
-                               ),
-                       ),
-                       'descriptions' => array(
-                               'pt' => array(
-                                       'language' => 'pt',
-                                       'value' => 'ptDesc'
-                               ),
-                               'pl' => array(
-                                       'language' => 'pl',
-                                       'value' => 'Longer Description For An 
Item'
-                               ),
-                       ),
-                       'labels' => array(
-                               'de' => array(
-                                       'language' => 'de',
-                                       'value' => 'foo'
-                               ),
-                               'zh_classical' => array(
-                                       'language' => 'zh_classical',
-                                       'value' => 'Longer Label'
-                               ),
-                       ),
-                       'claims' => array(
-                               'P65' => array(
-                                       array(
-                                               'id' => 'imaguid',
-                                               'mainsnak' => array(
-                                                       'snaktype' => 
'somevalue',
-                                                       'property' => 'P65'
+                                       'aliases' => array(
+                                               'en' => array(
+                                                       array(
+                                                               'language' => 
'en',
+                                                               'value' => 'bar'
+                                                       ),
+                                                       array(
+                                                               'language' => 
'en',
+                                                               'value' => 'baz'
+                                                       )
                                                ),
-                                               'type' => 'statement',
-                                               'qualifiers' => array(
-                                                       'P65' => array(
-                                                               array(
-                                                                       'hash' 
=> '210b00274bf03247a89de918f15b12142ebf9e56',
-                                                                       
'snaktype' => 'somevalue',
-                                                                       
'property' => 'P65',
-                                                               ),
-                                                               array(
-                                                                       'hash' 
=> 'e95e866e7fa1c18bd06dae9b712cb99545107eb8',
-                                                                       
'snaktype' => 'value',
-                                                                       
'property' => 'P65',
-                                                                       
'datavalue' => array(
-                                                                               
'value' => 'string!',
-                                                                               
'type' => 'string',
-                                                                       ),
-                                                                       
'datatype' => 'DtIdFor_P65',
-                                                               ),
+                                               'zh' => array(
+                                                       array(
+                                                               'language' => 
'zh',
+                                                               'value' => 
'????????',
                                                        ),
                                                ),
-                                               'rank' => 'normal',
-                                               'qualifiers-order' => array(
-                                                       'P65'
+                                       ),
+                                       'descriptions' => array(
+                                               'pt' => array(
+                                                       'language' => 'pt',
+                                                       'value' => 'ptDesc'
                                                ),
-                                               'references' => array(
+                                               'pl' => array(
+                                                       'language' => 'pl',
+                                                       'value' => 'Longer 
Description For An Item'
+                                               ),
+                                       ),
+                                       'labels' => array(
+                                               'de' => array(
+                                                       'language' => 'de',
+                                                       'value' => 'foo'
+                                               ),
+                                               'zh_classical' => array(
+                                                       'language' => 
'zh_classical',
+                                                       'value' => 'Longer 
Label'
+                                               ),
+                                       ),
+                                       'claims' => array(
+                                               'P65' => array(
                                                        array(
-                                                               'hash' => 
'bdc5f7185904d6d3219e13b7443571dda8c4bee8',
-                                                               'snaks' => 
array(
+                                                               'id' => 
'imaguid',
+                                                               'mainsnak' => 
array(
+                                                                       
'snaktype' => 'somevalue',
+                                                                       
'property' => 'P65'
+                                                               ),
+                                                               'type' => 
'statement',
+                                                               'qualifiers' => 
array(
                                                                        'P65' 
=> array(
                                                                                
array(
+                                                                               
        'hash' => '210b00274bf03247a89de918f15b12142ebf9e56',
                                                                                
        'snaktype' => 'somevalue',
-                                                                               
        'property' => 'P65'
-                                                                               
)
-                                                                       ),
-                                                                       'P68' 
=> array(
+                                                                               
        'property' => 'P65',
+                                                                               
),
                                                                                
array(
-                                                                               
        'snaktype' => 'somevalue',
-                                                                               
        'property' => 'P68'
+                                                                               
        'hash' => 'e95e866e7fa1c18bd06dae9b712cb99545107eb8',
+                                                                               
        'snaktype' => 'value',
+                                                                               
        'property' => 'P65',
+                                                                               
        'datavalue' => array(
+                                                                               
                'value' => 'string!',
+                                                                               
                'type' => 'string',
+                                                                               
        ),
+                                                                               
        'datatype' => 'DtIdFor_P65',
+                                                                               
),
+                                                                       ),
+                                                               ),
+                                                               'rank' => 
'normal',
+                                                               
'qualifiers-order' => array(
+                                                                       'P65'
+                                                               ),
+                                                               'references' => 
array(
+                                                                       array(
+                                                                               
'hash' => 'bdc5f7185904d6d3219e13b7443571dda8c4bee8',
+                                                                               
'snaks' => array(
+                                                                               
        'P65' => array(
+                                                                               
                array(
+                                                                               
                        'snaktype' => 'somevalue',
+                                                                               
                        'property' => 'P65'
+                                                                               
                )
+                                                                               
        ),
+                                                                               
        'P68' => array(
+                                                                               
                array(
+                                                                               
                        'snaktype' => 'somevalue',
+                                                                               
                        'property' => 'P68'
+                                                                               
                )
+                                                                               
        ),
+                                                                               
),
+                                                                               
'snaks-order' => array(
+                                                                               
        'P65',
+                                                                               
        'P68'
                                                                                
)
                                                                        ),
                                                                ),
-                                                               'snaks-order' 
=> array(
-                                                                       'P65', 
'P68'
-                                                               )
-                                                       ),
+                                                       )
                                                ),
-                                       )
+                                       ),
+                                       'sitelinks' => array(
+                                               'enwiki' => array(
+                                                       'site' => 'enwiki',
+                                                       'title' => 'Berlin',
+                                                       'badges' => array( 
'Q333' )
+                                               ),
+                                               'zh_classicalwiki' => array(
+                                                       'site' => 
'zh_classicalwiki',
+                                                       'title' => 
'User:Addshore',
+                                                       'badges' => array()
+                                               ),
+                                       ),
                                ),
+                               '_element' => 'entity',
                        ),
-                       'sitelinks' => array(
-                               'enwiki' => array(
-                                       'site' => 'enwiki',
-                                       'title' => 'Berlin',
-                                       'badges' => array( 'Q333' )
-                               ),
-                               'zh_classicalwiki' => array(
-                                       'site' => 'zh_classicalwiki',
-                                       'title' => 'User:Addshore',
-                                       'badges' => array()
-                               ),
-                       ),
-               ) ) );
+               );
 
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addEntityRevision( 'Q1230000', $entityRevision, 
new SerializationOptions(), $props );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -357,13 +358,11 @@
                                        ),
                                ),
                        ),
+                       '_element' => 'entity',
                ) );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -417,11 +416,8 @@
                        '_element' => 'entity'
                ) );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => $indexedMode ? 'bc' : 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -436,11 +432,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addBasicEntityInformation( $entityId, 'entity' 
);
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -468,11 +461,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addLabels( $labels, $path );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -500,11 +490,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addDescriptions( $descriptions, $path );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -544,11 +531,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addAliases( $aliases, $path );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -581,11 +565,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addSiteLinks( $siteLinks, $path );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -609,11 +590,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addClaims( $claims, $path );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -625,11 +603,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addClaim( $statement );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -720,11 +695,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addReference( $reference );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -744,11 +716,8 @@
                        $resultBuilder->addMissingEntity( $key, $missingDetails 
);
                }
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -764,7 +733,8 @@
                                                        'site' => 'enwiki',
                                                        'title' => 'Berlin',
                                                        'missing' => '',
-                                               )
+                                               ),
+                                               '_element' => 'entity',
                                        ),
                                )
                        ),
@@ -777,7 +747,8 @@
                                                'Q77' => array(
                                                        'id' => 'Q77',
                                                        'missing' => '',
-                                               )
+                                               ),
+                                               '_element' => 'entity',
                                        ),
                                )
                        ),
@@ -790,7 +761,8 @@
                                                'Q77' => array(
                                                        'foo' => 'bar',
                                                        'missing' => '',
-                                               )
+                                               ),
+                                               '_element' => 'entity',
                                        ),
                                )
                        ),
@@ -810,7 +782,8 @@
                                                        'site' => 'dewiki',
                                                        'title' => 'Foo',
                                                        'missing' => '',
-                                               )
+                                               ),
+                                               '_element' => 'entity',
                                        ),
                                )
                        ),
@@ -834,11 +807,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addNormalizedTitle( $from, $to );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -859,11 +829,8 @@
                $resultBuilder = $this->getResultBuilder( $result );
                $resultBuilder->addRevisionIdFromStatusToResult( $mockStatus, 
'entity' );
 
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertEquals( $expected, $data );
        }
 
@@ -912,11 +879,8 @@
                $builder = $this->getResultBuilder( $result, null, $indexed );
 
                $builder->setList( $path, $name, $values, $tag );
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertResultStructure( $expected, $data );
        }
 
@@ -979,11 +943,8 @@
                $builder = $this->getResultBuilder( $result, null, $indexed );
 
                $builder->setValue( $path, $name, $value );
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertResultStructure( $expected, $data );
        }
 
@@ -1010,31 +971,34 @@
 
        public function provideAppendValue() {
                return array(
-                       'null path' => array( null, null, 'value', 'letter', 
false, array( 'value' ) ),
+                       'null path' => array( null, null, 'value', 'letter', 
false,
+                               array( 'value', '_element' => 'letter' ),
+                       ),
 
                        'empty path' => array( array(), null, 'value', 
'letter', false,
-                               array( 'value' )
+                               array( 'value', '_element' => 'letter' )
                        ),
 
                        'string path' => array( 'ROOT', null, 'value', 
'letter', false,
                                array(
-                                       'ROOT' => array( 'value' )
+                                       'ROOT' => array( 'value', '_element' => 
'letter' )
                                ) ),
 
                        'actual path' => array( array( 'one', 'two' ), null, 
array( 'X' => 'x', 'Y' => 'y' ), 'letter', false,
                                array(
                                        'one' => array(
-                                               'two' => array( array( 'X' => 
'x', 'Y' => 'y' ) ) )
+                                               'two' => array( array( 'X' => 
'x', 'Y' => 'y' ), '_element' => 'letter' ),
+                                       )
                                ) ),
 
                        'int key' => array( 'ROOT', -2, 'value', 'letter', 
false,
                                array(
-                                       'ROOT' => array( -2 => 'value' )
+                                       'ROOT' => array( -2 => 'value', 
'_element' => 'letter' ),
                                ) ),
 
                        'string key' => array( 'ROOT', 'Q7', 'value', 'letter', 
false,
                                array(
-                                       'ROOT' => array( 'Q7' => 'value' )
+                                       'ROOT' => array( 'Q7' => 'value', 
'_element' => 'letter' ),
                                ) ),
 
                        'null key indexed' => array( 'ROOT', null, 'value', 
'letter', true,
@@ -1062,11 +1026,8 @@
                $builder = $this->getResultBuilder( $result, null, $indexed );
 
                $builder->appendValue( $path, $key, $value, $tag );
-               $data = $result->getResultData( null, array(
-                       'BC' => array(),
-                       'Types' => array(),
-                       'Strip' => $indexed ? 'bc' : 'all',
-               ) );
+               $data = $result->getResultData();
+               $this->removeElementsWithKeysRecursively( $data, array( '_type' 
) );
                $this->assertResultStructure( $expected, $data );
        }
 
@@ -1109,4 +1070,15 @@
                $this->assertEquals( array_keys( $expected ), array_keys( 
$actual ), "Keys of $path:" );
        }
 
+       private function removeElementsWithKeysRecursively( array &$array, 
array $unwantedKeys ) {
+               foreach ( $unwantedKeys as $unwantedKey ) {
+                       unset( $array[$unwantedKey] );
+                       foreach ( $array as &$value ) {
+                               if ( is_array( $value ) ) {
+                                       
$this->removeElementsWithKeysRecursively( $value, array( $unwantedKey ) );
+                               }
+                       }
+               }
+       }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1978037486264095390c5ff863051db849a97ff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

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

Reply via email to