Lucas Werkmeister (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384502 )
Change subject: Add tests for T178160 ...................................................................... Add tests for T178160 This adds tests for the new Context functionality introduced in I60ad838dda (copied from the existing tests, except with null $results). The API part is not tested yet because the API tests still use the old result format, where it’s impossible to reproduce the bug. Bug: T178160 Change-Id: I851fe71705a60730c5270f3ab38e54a037a2688b --- M tests/phpunit/Context/MainSnakContextTest.php M tests/phpunit/Context/QualifierContextTest.php M tests/phpunit/Context/ReferenceContextTest.php M tests/phpunit/Context/StatementContextTest.php 4 files changed, 294 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints refs/changes/02/384502/1 diff --git a/tests/phpunit/Context/MainSnakContextTest.php b/tests/phpunit/Context/MainSnakContextTest.php index d039adb..c0b6bb9 100644 --- a/tests/phpunit/Context/MainSnakContextTest.php +++ b/tests/phpunit/Context/MainSnakContextTest.php @@ -132,4 +132,58 @@ $this->assertSame( $expected, $actual ); } + public function testStoreCheckResultInArray_NullResult() { + $entity = NewItem::withId( 'Q1' )->build(); + $statement1 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$13ea0742-0190-4d88-b7b0-baee67573818' ) + ->build(); + $statement2 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d' ) + ->build(); + $statement3 = NewStatement::noValueFor( 'P2' ) + ->withGuid( 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9' ) + ->build(); + $context1 = new MainSnakContext( $entity, $statement1 ); + $context2 = new MainSnakContext( $entity, $statement2 ); + $context3 = new MainSnakContext( $entity, $statement3 ); + + $actual = []; + $context1->storeCheckResultInArray( null, $actual ); + $context2->storeCheckResultInArray( null, $actual ); + $context3->storeCheckResultInArray( null, $actual ); + + $expected = [ + 'Q1' => [ + 'claims' => [ + 'P1' => [ + [ + 'id' => 'P1$13ea0742-0190-4d88-b7b0-baee67573818', + 'mainsnak' => [ + 'hash' => $statement1->getMainSnak()->getHash(), + 'results' => [], + ], + ], + [ + 'id' => 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d', + 'mainsnak' => [ + 'hash' => $statement2->getMainSnak()->getHash(), + 'results' => [], + ], + ], + ], + 'P2' => [ + [ + 'id' => 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9', + 'mainsnak' => [ + 'hash' => $statement3->getMainSnak()->getHash(), + 'results' => [], + ], + ], + ], + ], + ], + ]; + $this->assertSame( $expected, $actual ); + } + } diff --git a/tests/phpunit/Context/QualifierContextTest.php b/tests/phpunit/Context/QualifierContextTest.php index 0b49baa..cc5f0f7 100644 --- a/tests/phpunit/Context/QualifierContextTest.php +++ b/tests/phpunit/Context/QualifierContextTest.php @@ -171,4 +171,87 @@ $this->assertSame( $expected, $actual ); } + public function testStoreCheckResultInArray_NullResult() { + $entity = NewItem::withId( 'Q1' )->build(); + $statement1 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$13ea0742-0190-4d88-b7b0-baee67573818' ) + ->build(); + $statement2 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d' ) + ->build(); + $statement3 = NewStatement::noValueFor( 'P2' ) + ->withGuid( 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9' ) + ->build(); + $snak1 = NewStatement::noValueFor( 'P11' )->build()->getMainSnak(); + $snak2 = NewStatement::someValueFor( 'P11' )->build()->getMainSnak(); + $snak3 = NewStatement::noValueFor( 'P12' )->build()->getMainSnak(); + $context1 = new QualifierContext( $entity, $statement1, $snak1 ); + $context2 = new QualifierContext( $entity, $statement1, $snak2 ); + $context3 = new QualifierContext( $entity, $statement1, $snak3 ); + $context4 = new QualifierContext( $entity, $statement2, $snak3 ); + $context5 = new QualifierContext( $entity, $statement3, $snak3 ); + + $actual = []; + $context1->storeCheckResultInArray( null, $actual ); + $context2->storeCheckResultInArray( null, $actual ); + $context3->storeCheckResultInArray( null, $actual ); + $context4->storeCheckResultInArray( null, $actual ); + $context5->storeCheckResultInArray( null, $actual ); + + $expected = [ + 'Q1' => [ + 'claims' => [ + 'P1' => [ + [ + 'id' => 'P1$13ea0742-0190-4d88-b7b0-baee67573818', + 'qualifiers' => [ + 'P11' => [ + [ + 'hash' => $snak1->getHash(), + 'results' => [] + ], + [ + 'hash' => $snak2->getHash(), + 'results' => [] + ] + ], + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ] + ] + ], + ], + [ + 'id' => 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d', + 'qualifiers' => [ + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ] + ] + ], + ], + ], + 'P2' => [ + [ + 'id' => 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9', + 'qualifiers' => [ + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ] + ] + ], + ], + ], + ], + ], + ]; + $this->assertSame( $expected, $actual ); + } + } diff --git a/tests/phpunit/Context/ReferenceContextTest.php b/tests/phpunit/Context/ReferenceContextTest.php index 1ba883c..22bbdf9 100644 --- a/tests/phpunit/Context/ReferenceContextTest.php +++ b/tests/phpunit/Context/ReferenceContextTest.php @@ -227,4 +227,127 @@ $this->assertSame( $expected, $actual['Q1']['claims'] ); } + public function testStoreCheckResultInArray_NullResult() { + $entity = NewItem::withId( 'Q1' )->build(); + $statement1 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$13ea0742-0190-4d88-b7b0-baee67573818' ) + ->build(); + $statement2 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d' ) + ->build(); + $statement3 = NewStatement::noValueFor( 'P2' ) + ->withGuid( 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9' ) + ->build(); + $snak1 = NewStatement::noValueFor( 'P11' )->build()->getMainSnak(); + $snak2 = NewStatement::someValueFor( 'P11' )->build()->getMainSnak(); + $snak3 = NewStatement::noValueFor( 'P12' )->build()->getMainSnak(); + $reference1 = new Reference( [ $snak1, $snak2, $snak3 ] ); + $statement1->getReferences()->addReference( $reference1 ); + $reference2 = new Reference( [ $snak2, $snak3 ] ); + $statement1->getReferences()->addReference( $reference2 ); + $statement2->getReferences()->addReference( $reference1 ); + $statement3->getReferences()->addReference( $reference2 ); + $context1 = new ReferenceContext( $entity, $statement1, $reference1, $snak1 ); + $context2 = new ReferenceContext( $entity, $statement1, $reference1, $snak2 ); + $context3 = new ReferenceContext( $entity, $statement1, $reference1, $snak3 ); + $context4 = new ReferenceContext( $entity, $statement1, $reference2, $snak2 ); + $context5 = new ReferenceContext( $entity, $statement1, $reference2, $snak3 ); + $context6 = new ReferenceContext( $entity, $statement2, $reference1, $snak1 ); + $context7 = new ReferenceContext( $entity, $statement3, $reference2, $snak3 ); + + $actual = []; + $context1->storeCheckResultInArray( null, $actual ); + $context2->storeCheckResultInArray( null, $actual ); + $context3->storeCheckResultInArray( null, $actual ); + $context4->storeCheckResultInArray( null, $actual ); + $context5->storeCheckResultInArray( null, $actual ); + $context6->storeCheckResultInArray( null, $actual ); + $context7->storeCheckResultInArray( null, $actual ); + + $expected = [ + 'P1' => [ + [ + 'id' => 'P1$13ea0742-0190-4d88-b7b0-baee67573818', + 'references' => [ + [ + 'hash' => $reference1->getHash(), + 'snaks' => [ + 'P11' => [ + [ + 'hash' => $snak1->getHash(), + 'results' => [] + ], + [ + 'hash' => $snak2->getHash(), + 'results' => [] + ] + ], + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ] + ] + ] + ], + [ + 'hash' => $reference2->getHash(), + 'snaks' => [ + 'P11' => [ + [ + 'hash' => $snak2->getHash(), + 'results' => [] + ] + ], + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ] + ] + ] + ], + ], + ], + [ + 'id' => 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d', + 'references' => [ + [ + 'hash' => $reference1->getHash(), + 'snaks' => [ + 'P11' => [ + [ + 'hash' => $snak1->getHash(), + 'results' => [] + ], + ], + ] + ], + ], + ], + ], + 'P2' => [ + [ + 'id' => 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9', + 'references' => [ + [ + 'hash' => $reference2->getHash(), + 'snaks' => [ + 'P12' => [ + [ + 'hash' => $snak3->getHash(), + 'results' => [] + ], + ], + ] + ], + ], + ], + ], + ]; + $this->assertSame( [ 'Q1' ], array_keys( $actual ) ); + $this->assertSame( [ 'claims' ], array_keys( $actual['Q1'] ) ); + $this->assertSame( $expected, $actual['Q1']['claims'] ); + } + } diff --git a/tests/phpunit/Context/StatementContextTest.php b/tests/phpunit/Context/StatementContextTest.php index a55eb1d..0eb6097 100644 --- a/tests/phpunit/Context/StatementContextTest.php +++ b/tests/phpunit/Context/StatementContextTest.php @@ -111,4 +111,38 @@ $this->assertSame( $expected, $actual ); } + public function testStoreCheckResultInArray_NullResult() { + $entity = NewItem::withId( 'Q1' )->build(); + $statement1 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$13ea0742-0190-4d88-b7b0-baee67573818' ) + ->build(); + $statement2 = NewStatement::noValueFor( 'P1' ) + ->withGuid( 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d' ) + ->build(); + $statement3 = NewStatement::noValueFor( 'P2' ) + ->withGuid( 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9' ) + ->build(); + $context1 = new StatementContext( $entity, $statement1 ); + $context2 = new StatementContext( $entity, $statement2 ); + $context3 = new StatementContext( $entity, $statement3 ); + + $actual = []; + $context1->storeCheckResultInArray( null, $actual ); + $context2->storeCheckResultInArray( null, $actual ); + $context3->storeCheckResultInArray( null, $actual ); + + $expected = [ + 'Q1' => [ + 'P1' => [ + 'P1$13ea0742-0190-4d88-b7b0-baee67573818' => [], + 'P1$9fbfae7f-6f21-4967-8e2c-ec04ca16873d' => [], + ], + 'P2' => [ + 'P2$4638ca58-5128-4a1f-88a9-b379fe9f8ad9' => [], + ], + ], + ]; + $this->assertSame( $expected, $actual ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/384502 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I851fe71705a60730c5270f3ab38e54a037a2688b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits