jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/343543 )
Change subject: Don't create property in item namespace in ReferencedEntitiesDataUpdaterTest ...................................................................... Don't create property in item namespace in ReferencedEntitiesDataUpdaterTest This can pollute the test database and cause issues with other tests (e.g. SpecialItemsWithoutSitelinksTest) which run later when running all tests together. Since we are inserting pages for this test, we need to give the title a valid namespace for the entity types we are creating. Bug: T160855 Change-Id: Id1e45c304469857c1b06aacd098c710b6bf32045 --- M repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php 1 file changed, 49 insertions(+), 51 deletions(-) Approvals: WMDE-leszek: Looks good to me, approved jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, but someone else must approve diff --git a/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php b/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php index e6220c7..6ad9375 100644 --- a/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php +++ b/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php @@ -16,6 +16,7 @@ use Wikibase\DataModel\Statement\StatementList; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Repo\ParserOutput\ReferencedEntitiesDataUpdater; +use Wikibase\Repo\WikibaseRepo; /** * @covers Wikibase\Repo\ParserOutput\ReferencedEntitiesDataUpdater @@ -30,11 +31,17 @@ const UNIT_PREFIX = 'unit:'; - protected function setUp() { - parent::setUp(); + public function addDBData() { + foreach ( [ 'P1', 'Q1', 'Q20', 'Q21', 'Q22' ] as $pageName ) { + if ( $pageName[0] === 'P' ) { + $entityType = 'property'; + $text = '{ "type": "property", "datatype": "string", "id": "P1" }'; + } else { + $entityType = 'item'; + $text = '{ "type": "item", "id": "Q1" }'; + } - foreach ( array( 'P1', 'Q1', 'Q20', 'Q21', 'Q22' ) as $pageName ) { - $this->insertPage( $pageName, '{ "type": "item", "id": "Q1" }' ); + $this->insertPage( $pageName, $text, $this->getEntityNamespace( $entityType ) ); } } @@ -50,13 +57,14 @@ $entityTitleLookup->expects( $this->exactly( $count ) ) ->method( 'getTitleForId' ) ->will( $this->returnCallback( function( EntityId $id ) { - return Title::newFromText( $id->getSerialization() ); + $namespace = $this->getEntityNamespace( $id->getEntityType() ); + return Title::makeTitle( $namespace, $id->getSerialization() ); } ) ); - $entityidParser = $this->getMockBuilder( EntityIdParser::class ) + $entityIdParser = $this->getMockBuilder( EntityIdParser::class ) ->disableOriginalConstructor() ->getMock(); - $entityidParser->expects( $this->any() ) + $entityIdParser->expects( $this->any() ) ->method( 'parse' ) ->will( $this->returnCallback( function( $id ) { return new ItemId( @@ -64,17 +72,7 @@ ); } ) ); - return new ReferencedEntitiesDataUpdater( $entityTitleLookup, $entityidParser ); - } - - /** - * @param StatementList $statements - * @param string $itemId - */ - private function addStatement( StatementList $statements, $itemId ) { - $statements->addNewStatement( - new PropertyValueSnak( 1, new EntityIdValue( new ItemId( $itemId ) ) ) - ); + return new ReferencedEntitiesDataUpdater( $entityTitleLookup, $entityIdParser ); } /** @@ -139,16 +137,16 @@ } public function entityIdProvider() { - $set1 = new StatementList(); - $this->addStatement( $set1, 'Q1' ); + $statementList1 = new StatementList(); + $this->addStatement( $statementList1, 'Q1' ); - $set2 = new StatementList(); - $this->addStatement( $set2, 'Q20' ); - $set2->addNewStatement( new PropertyValueSnak( + $statementList2 = new StatementList(); + $this->addStatement( $statementList2, 'Q20' ); + $statementList2->addNewStatement( new PropertyValueSnak( 1, UnboundedQuantityValue::newFromNumber( 1, self::UNIT_PREFIX . 'Q21' ) ) ); - $set2->addNewStatement( new PropertyValueSnak( + $statementList2->addNewStatement( new PropertyValueSnak( 1, QuantityValue::newFromNumber( 1, self::UNIT_PREFIX . 'Q22' ) ) ); @@ -156,34 +154,34 @@ $siteLinks = new SiteLinkList(); $siteLinks->addNewSiteLink( 'siteId', 'pageName', array( new ItemId( 'Q1' ) ) ); - return array( - array( new StatementList(), null, array( - ) ), - array( $set1, null, array( - 'P1', - 'Q1', - ) ), - array( new StatementList(), $siteLinks, array( - 'Q1', - ) ), - array( $set1, $siteLinks, array( - 'P1', - 'Q1', - ) ), - array( $set2, null, array( - 'P1', - 'Q20', - 'Q21', - 'Q22', - ) ), - array( $set2, $siteLinks, array( - 'P1', - 'Q20', - 'Q21', - 'Q22', - 'Q1', - ) ), + return [ + [ new StatementList(), null, [] ], + [ $statementList1, null, [ 'P1', 'Q1' ] ], + [ new StatementList(), $siteLinks, [ 'Q1' ] ], + [ $statementList1, $siteLinks, [ 'P1', 'Q1' ] ], + [ $statementList2, null, [ 'P1', 'Q20', 'Q21', 'Q22' ] ], + [ $statementList2, $siteLinks, [ 'P1', 'Q20', 'Q21', 'Q22', 'Q1' ] ] + ]; + } + + /** + * @param StatementList $statements + * @param string $itemId + */ + private function addStatement( StatementList $statements, $itemId ) { + $statements->addNewStatement( + new PropertyValueSnak( 1, new EntityIdValue( new ItemId( $itemId ) ) ) ); } + /** + * @param string $entityType + * @return int|null + */ + private function getEntityNamespace( $entityType ) { + $entityNamespaceLookup = WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup(); + + return $entityNamespaceLookup->getEntityNamespace( $entityType ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/343543 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id1e45c304469857c1b06aacd098c710b6bf32045 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits