jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/382713 )

Change subject: Add UsedForValuesOnly to DelegatingConstraintCheckerTest
......................................................................


Add UsedForValuesOnly to DelegatingConstraintCheckerTest

DelegatingConstraintCheckerTest should contain at least one constraint
of every constraint type, to make sure that ConstraintReportFactory
isn’t missing any checkers when initializing the checker map.

The test is also refactored to remove the magic number of constraints
for P1 from three places where it was previously hard-coded, so that in
the future adding just an array entry is enough to add another
constraint type.

Change-Id: I7977221f86833147466da554fe930536567c02e6
---
M tests/phpunit/DelegatingConstraintCheckerTest.php
1 file changed, 215 insertions(+), 203 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/DelegatingConstraintCheckerTest.php 
b/tests/phpunit/DelegatingConstraintCheckerTest.php
index 12d3fb6..b518e5c 100644
--- a/tests/phpunit/DelegatingConstraintCheckerTest.php
+++ b/tests/phpunit/DelegatingConstraintCheckerTest.php
@@ -64,6 +64,12 @@
         */
        private $lookup;
 
+       /**
+        * Number of constraints for P1.
+        * @var int
+        */
+       private $constraintCount;
+
        protected function setUp() {
                parent::setUp();
                $this->lookup = new InMemoryEntityLookup();
@@ -112,207 +118,213 @@
         */
        public function addDBData() {
                $config = $this->getDefaultConfig();
-
-               $this->db->delete(
-                       CONSTRAINT_TABLE,
-                       '*'
-               );
-
-               $this->db->insert(
-                       CONSTRAINT_TABLE,
+               $constraints = [
                        [
-                               [
-                                       'constraint_guid' => 
'P1$ecb8f617-90f1-4ef3-afab-f4bf3881ec28',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'CommonsLink' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->namespaceParameter( 
'File' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P10$0bdbe1cb-8afb-4d16-9fd0-c1d0a5b717ce',
-                                       'pid' => 10,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'CommonsLink' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->namespaceParameter( 
'File' ),
-                                               $this->exceptionsParameter( [ 
'Q5' ] )
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P11$01c56d1f-b3ce-4a1a-bef7-8c652f395eb2',
-                                       'pid' => 11,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => json_encode( 
[
-                                               $this->getDefaultConfig()->get( 
'WBQualityConstraintsExceptionToConstraintId' ) => [
-                                                       [ 'snaktype' => 
'novalue', 'property' => 'P2316' ]
-                                               ]
-                                       ] )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$6ad9eb64-13fd-43a1-afc8-84857108bd59',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'MandatoryQualifier' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->propertyParameter( 'P2' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$cfff6d73-320c-43c5-8582-e9cbb98e2ca2',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ConflictsWith' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->propertyParameter( 'P2' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$c81a981e-4eab-44c9-8aa2-62c63072902e',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Inverse' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->propertyParameter( 'P2' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$2040dee1-8c9d-45b7-ac01-2ce8046f578b',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'AllowedQualifiers' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->propertiesParameter( [ 
'P2', 'P3' ] )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$09a20b38-fe36-444b-b9ed-22eb46c3ea73',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'DifferenceWithinRange' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->propertyParameter( 'P2' 
),
-                                               $this->rangeParameter( 
'quantity', 0, 150 )
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$3dac547d-3faf-4198-9b9c-0ba1eae32752',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Format' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->formatParameter( '[0-9]' 
)
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$cc5708c8-3ec8-4bf3-8931-409530e4d634',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'MultiValue' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$021b2558-8e7c-4c2c-ba14-4596dc11536e',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'DistinctValues' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$3ddc8c54-c056-425c-8745-d257004d585f',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'SingleValue' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$dc4464ed-42a5-47f6-b725-04b1d9d1dfc6',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Symmetric' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$713ec92d-cd08-413d-b4dc-8e6eeb8c7861',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$a083d339-7bd6-4737-a987-b55ae8a1a5f3',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'OneOf' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->itemsParameter( [ 'Q2', 
'Q3' ] )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$b8587fb1-7315-46ba-9d04-07f0e9af857d',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Range' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->rangeParameter( 'time', 
'0', '2015' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$83ee554c-41fd-4bfa-ae9b-960d0eee2fa4',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ValueRequiresClaim' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->propertyParameter( 'P2' 
),
-                                               $this->itemsParameter( [ 'Q2' ] 
)
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$370a45b5-b007-455d-b5fa-03b90c629fe5',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ItemRequiresClaim' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->propertyParameter( 'P2' 
),
-                                               $this->itemsParameter( [ 'Q2', 
'Q3' ] )
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$831d9d5d-ed77-48f2-8433-fb80a9ef3aad',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Type' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->relationParameter( 
'instance' ),
-                                               $this->classParameter( [ 'Q2', 
'Q3' ] )
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P1$fe667c64-be46-4521-a54d-8a895b6005b0',
-                                       'pid' => 1,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ValueType' ),
-                                       'constraint_parameters' => json_encode( 
array_merge(
-                                               $this->relationParameter( 
'instance' ),
-                                               $this->classParameter( [ 'Q2', 
'Q3' ] )
-                                       ) )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P3$0a011ed8-1e2b-470c-a306-fb8ea6953779',
-                                       'pid' => 3,
-                                       'constraint_type_qid' => 'Is not 
inside',
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P6$ad792000-6a12-413d-9fe5-11d2467b7a92',
-                                       'pid' => 6,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => json_encode(
-                                               $this->statusParameter( 
'mandatory' )
-                                       )
-                               ],
-                               [
-                                       'constraint_guid' => 
'P7$a3f746e7-66a0-46fd-96ab-6ff6638332a4',
-                                       'pid' => 7,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => '{}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P8$34c8af8e-bb50-4458-994b-f355ff899fff',
-                                       'pid' => 8,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => 
'{"@error":{"toolong":true}}'
-                               ],
-                               [
-                                       'constraint_guid' => 
'P9$43053ee8-79da-4326-a2ac-f85098291db3',
-                                       'pid' => 9,
-                                       'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
-                                       'constraint_parameters' => 
'{"P2316":[{"snaktype":"novalue","property":"P2316"}],"P2303":[{"snaktype":"novalue","property":"P2316"}]}'
-                               ],
-                       ]
-               );
+                               'constraint_guid' => 
'P1$ecb8f617-90f1-4ef3-afab-f4bf3881ec28',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'CommonsLink' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->namespaceParameter( 'File' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P10$0bdbe1cb-8afb-4d16-9fd0-c1d0a5b717ce',
+                               'pid' => 10,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'CommonsLink' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->namespaceParameter( 'File' ),
+                                       $this->exceptionsParameter( [ 'Q5' ] )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P11$01c56d1f-b3ce-4a1a-bef7-8c652f395eb2',
+                               'pid' => 11,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => json_encode( [
+                                       $this->getDefaultConfig()->get( 
'WBQualityConstraintsExceptionToConstraintId' ) => [
+                                               [ 'snaktype' => 'novalue', 
'property' => 'P2316' ]
+                                       ]
+                               ] )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$6ad9eb64-13fd-43a1-afc8-84857108bd59',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'MandatoryQualifier' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->propertyParameter( 'P2' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$cfff6d73-320c-43c5-8582-e9cbb98e2ca2',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ConflictsWith' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->propertyParameter( 'P2' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$c81a981e-4eab-44c9-8aa2-62c63072902e',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Inverse' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->propertyParameter( 'P2' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$2040dee1-8c9d-45b7-ac01-2ce8046f578b',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'AllowedQualifiers' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->propertiesParameter( [ 'P2', 
'P3' ] )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$09a20b38-fe36-444b-b9ed-22eb46c3ea73',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'DifferenceWithinRange' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->propertyParameter( 'P2' ),
+                                       $this->rangeParameter( 'quantity', 0, 
150 )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$3dac547d-3faf-4198-9b9c-0ba1eae32752',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Format' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->formatParameter( '[0-9]' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$cc5708c8-3ec8-4bf3-8931-409530e4d634',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'MultiValue' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$021b2558-8e7c-4c2c-ba14-4596dc11536e',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'DistinctValues' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$3ddc8c54-c056-425c-8745-d257004d585f',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'SingleValue' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$dc4464ed-42a5-47f6-b725-04b1d9d1dfc6',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Symmetric' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$713ec92d-cd08-413d-b4dc-8e6eeb8c7861',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$a083d339-7bd6-4737-a987-b55ae8a1a5f3',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'OneOf' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->itemsParameter( [ 'Q2', 'Q3' ] )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$b8587fb1-7315-46ba-9d04-07f0e9af857d',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Range' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->rangeParameter( 'time', '0', 
'2015' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$83ee554c-41fd-4bfa-ae9b-960d0eee2fa4',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ValueRequiresClaim' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->propertyParameter( 'P2' ),
+                                       $this->itemsParameter( [ 'Q2' ] )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$370a45b5-b007-455d-b5fa-03b90c629fe5',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ItemRequiresClaim' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->propertyParameter( 'P2' ),
+                                       $this->itemsParameter( [ 'Q2', 'Q3' ] )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$831d9d5d-ed77-48f2-8433-fb80a9ef3aad',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'Type' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->relationParameter( 'instance' ),
+                                       $this->classParameter( [ 'Q2', 'Q3' ] )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$fe667c64-be46-4521-a54d-8a895b6005b0',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'ValueType' ),
+                               'constraint_parameters' => json_encode( 
array_merge(
+                                       $this->relationParameter( 'instance' ),
+                                       $this->classParameter( [ 'Q2', 'Q3' ] )
+                               ) )
+                       ],
+                       [
+                               'constraint_guid' => 
'P3$0a011ed8-1e2b-470c-a306-fb8ea6953779',
+                               'pid' => 3,
+                               'constraint_type_qid' => 'Is not inside',
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P6$ad792000-6a12-413d-9fe5-11d2467b7a92',
+                               'pid' => 6,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => json_encode(
+                                       $this->statusParameter( 'mandatory' )
+                               )
+                       ],
+                       [
+                               'constraint_guid' => 
'P7$a3f746e7-66a0-46fd-96ab-6ff6638332a4',
+                               'pid' => 7,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => '{}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P8$34c8af8e-bb50-4458-994b-f355ff899fff',
+                               'pid' => 8,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => 
'{"@error":{"toolong":true}}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P9$43053ee8-79da-4326-a2ac-f85098291db3',
+                               'pid' => 9,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedAsQualifier' ),
+                               'constraint_parameters' => 
'{"P2316":[{"snaktype":"novalue","property":"P2316"}],"P2303":[{"snaktype":"novalue","property":"P2316"}]}'
+                       ],
+                       [
+                               'constraint_guid' => 
'P1$a1b1f3d8-6215-4cb6-9edd-3af126ae134f',
+                               'pid' => 1,
+                               'constraint_type_qid' => 
$this->getConstraintTypeItemId( 'UsedForValuesOnly' ),
+                               'constraint_parameters' => '{}'
+                       ],
+               ];
+               $this->constraintCount = count( array_filter(
+                       $constraints,
+                       function ( $constraint ) {
+                               return $constraint['pid'] === 1;
+                       }
+               ) );
+
+               $this->db->delete( CONSTRAINT_TABLE, '*' );
+               $this->db->insert( CONSTRAINT_TABLE, $constraints );
        }
 
        public function testCheckOnEntityId() {
@@ -326,7 +338,7 @@
 
                $result = 
$this->constraintChecker->checkAgainstConstraintsOnEntityId( $entity->getId() );
 
-               $this->assertCount( 18, $result, 'Every constraint should be 
represented by one result' );
+               $this->assertCount( $this->constraintCount, $result, 'Every 
constraint should be represented by one result' );
                foreach ( $result as $checkResult ) {
                        $this->assertNotSame( 'todo', 
$checkResult->getStatus(), 'Constraints should not be unimplemented' );
                }
@@ -463,7 +475,7 @@
                        $statement->getGuid()
                );
 
-               $this->assertCount( 18, $result, 'Every constraint should be 
represented by one result' );
+               $this->assertCount( $this->constraintCount, $result, 'Every 
constraint should be represented by one result' );
        }
 
        public function testCheckOnClaimIdEmptyResult() {
@@ -498,7 +510,7 @@
                        $entity->getId()
                );
 
-               $this->assertCount( 18, $result, 'Every constraint should be 
represented by one result' );
+               $this->assertCount( $this->constraintCount, $result, 'Every 
constraint should be represented by one result' );
                foreach ( $result as $constraintGuid => $constraintResult ) {
                        $this->assertSame( [], $constraintResult, 'Constraint 
should have no bad parameters' );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/382713
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7977221f86833147466da554fe930536567c02e6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to