[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Don't create property in item namespace in ReferencedEntitie...
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(
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Don't create property in item namespace in ReferencedEntitie...
Aude has uploaded a new change for review. ( 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, 46 insertions(+), 48 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/43/343543/1 diff --git a/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php b/repo/tests/phpunit/includes/ParserOutput/ReferencedEntitiesDataUpdaterTest.php index e6220c7..e3f9a39 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() { + $itemNamespace = $this->getEntityNamespace( 'item' ); - foreach ( array( 'P1', 'Q1', 'Q20', 'Q21', 'Q22' ) as $pageName ) { - $this->insertPage( $pageName, '{ "type": "item", "id": "Q1" }' ); + foreach ( [ 'P1', 'Q1', 'Q20', 'Q21', 'Q22' ] as $pageName ) { + if ( $pageName === 'P1' ) { + $content = '{ "type": "property", "datatype": "string", "id": "P1" }'; + $this->insertPage( $pageName, $content, $this->getEntityNamespace( 'property' ) ); + } else { + $content = '{ "type": "item", "id": "Q1" }'; + $this->insertPage( $pageName, $content, $itemNamespace ); + } } } @@ -50,7 +57,8 @@ $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 ) @@ -65,16 +73,6 @@ } ) ); 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 ) ) ) - ); } /** @@ -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' ) ) ); -