Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
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
2d45db65c3 (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, 52 insertions(+), 5 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/57/356557/1

diff --git a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php 
b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
index 4d0bf8b..87a1fe3 100644
--- a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
+++ b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
@@ -133,7 +133,54 @@
                // 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' ] );
+               $typeId = $this->getDefaultConfig()->get( 
'WBQualityConstraintsTypeConstraintId' );
+               $classId = $this->getDefaultConfig()->get( 
'WBQualityConstraintsClassId' );
+               $relationId = $this->getDefaultConfig()->get( 
'WBQualityConstraintsRelationId' );
+               $instanceOfRelationId = $this->getDefaultConfig()->get( 
'WBQualityConstraintsInstanceOfRelationId' );
+               $statementGuid = 'P2$e95e1eb9-eaa5-48d1-a3d6-0b34fc5d3cd0';
+               $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 ) )
+               );
+               $statement = new Statement(
+                       new PropertyValueSnak(
+                               new PropertyId( $this->getDefaultConfig()->get( 
'WBQualityConstraintsPropertyConstraintId' ) ),
+                               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 +216,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 +230,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 +271,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 +279,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: newchange
Gerrit-Change-Id: I88f03425a3bb9d6dd1900b73579faf36b94fdfeb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

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

Reply via email to