jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/356557 )
Change subject: Add test for extracting constraint parameters
......................................................................
Add test for extracting constraint parameters
This is a test for functionality introduced in commit 0c03ee2a24 (change
I6e5428187f), but it uses configuration variables added only in commit
8e9438ea7c (change Id47731c99b), so it is added in a separate commit.
testImportConstraintsForProperty and testRun / P2.json are not updated
because the added benefit seems small compared to the large amount of
extra code that would be needed.
Also fixes some confusing comments in other tests.
Change-Id: I88f03425a3bb9d6dd1900b73579faf36b94fdfeb
---
M tests/phpunit/Job/UpdateConstraintsTableJobTest.php
1 file changed, 57 insertions(+), 5 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
index 4d0bf8b..9fb5385 100644
--- a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
+++ b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
@@ -133,7 +133,59 @@
// TODO is there a good way to assert that this function did
not touch the database?
}
- // TODO add test for extractConstraintFromStatement with parameters
once that’s implemented
+ public function testExtractConstraintFromStatement_Parameters() {
+ $job = UpdateConstraintsTableJob::newFromGlobalState(
Title::newFromText( 'constraintsTableUpdate' ), [ 'propertyId' => 'P2' ] );
+
+ $config = $this->getDefaultConfig();
+ $propertyConstraintId = $config->get(
'WBQualityConstraintsPropertyConstraintId' );
+ $typeId = $config->get( 'WBQualityConstraintsTypeConstraintId'
);
+ $classId = $config->get( 'WBQualityConstraintsClassId' );
+ $relationId = $config->get( 'WBQualityConstraintsRelationId' );
+ $instanceOfRelationId = $config->get(
'WBQualityConstraintsInstanceOfRelationId' );
+
+ $classHumanSnak = new PropertyValueSnak(
+ new PropertyId( $classId ),
+ new EntityIdValue( new ItemId( 'Q5' ) )
+ );
+ $classFictionalHumanSnak = new PropertyValueSnak(
+ new PropertyId( $classId ),
+ new EntityIdValue( new ItemId( 'Q15632617' ) )
+ );
+ $relationInstanceOfSnak = new PropertyValueSnak(
+ new PropertyId( $relationId ),
+ new EntityIdValue( new ItemId( $instanceOfRelationId ) )
+ );
+
+ $statementGuid = 'P2$e95e1eb9-eaa5-48d1-a3d6-0b34fc5d3cd0';
+ $statement = new Statement(
+ new PropertyValueSnak(
+ new PropertyId( $propertyConstraintId ),
+ new EntityIdValue( new ItemId( $typeId ) )
+ ),
+ new SnakList( [ $classHumanSnak,
$classFictionalHumanSnak, $relationInstanceOfSnak ] ),
+ null,
+ $statementGuid
+ );
+
+ $constraint = $job->extractConstraintFromStatement( new
PropertyId( 'P2' ), $statement );
+
+ $snakSerializer =
WikibaseRepo::getDefaultInstance()->getSerializerFactory()->newSnakSerializer();
+ $this->assertEquals( $typeId,
$constraint->getConstraintTypeQid() );
+ $this->assertEquals( new PropertyId( 'P2' ),
$constraint->getPropertyId() );
+ $this->assertEquals( $statementGuid,
$constraint->getConstraintId() );
+ $this->assertEquals(
+ [
+ $classId => [
+ $snakSerializer->serialize(
$classHumanSnak ),
+ $snakSerializer->serialize(
$classFictionalHumanSnak )
+ ],
+ $relationId => [
+ $snakSerializer->serialize(
$relationInstanceOfSnak )
+ ]
+ ],
+ $constraint->getConstraintParameters()
+ );
+ }
public function testImportConstraintsForProperty() {
$job = UpdateConstraintsTableJob::newFromGlobalState(
Title::newFromText( 'constraintsTableUpdate' ), [ 'propertyId' => 'P2' ] );
@@ -169,7 +221,7 @@
],
[],
[
- // constraint previously imported from the
statement under test is still there
+ // constraint previously imported from the
property under test is still there
[
'P2$2892c48c-53e5-40ef-94a2-274ebf35075c',
'2',
@@ -183,7 +235,7 @@
$singleValueId->getSerialization(),
'{}'
],
- // constraint imported from a different
statement is still there
+ // constraint imported from a different
property is still there
[
'P3$1926459f-a4d6-42f5-a46e-e1866a2499ed',
'3',
@@ -224,7 +276,7 @@
],
[],
[
- // constraint previously imported from the
statement under test was removed
+ // constraint previously imported from the
property under test was removed
// new constraint imported from the statement
under test is there
[
'P2$484b7eaf-e86c-4f25-91dc-7ae19f8be8de',
@@ -232,7 +284,7 @@
'Q19474404',
'{}'
],
- // constraint imported from a different
statement is still there
+ // constraint imported from a different
property is still there
[
'P3$1926459f-a4d6-42f5-a46e-e1866a2499ed',
'3',
--
To view, visit https://gerrit.wikimedia.org/r/356557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I88f03425a3bb9d6dd1900b73579faf36b94fdfeb
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits