Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402883 )

Change subject: Add scope helpers to test traits
......................................................................

Add scope helpers to test traits

ConstraintParameters gains a method to turn Context::TYPE_* constants
into constraint parameters, and ResultAssertions gains an assertion that
a result is not in scope.

Bug: T183542
Change-Id: I668908f61a52c9d39ea27f590a1d72cfb541ec75
---
M tests/phpunit/ConstraintParameters.php
M tests/phpunit/ResultAssertions.php
2 files changed, 51 insertions(+), 0 deletions(-)


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

diff --git a/tests/phpunit/ConstraintParameters.php 
b/tests/phpunit/ConstraintParameters.php
index 7c16529..3c0b424 100644
--- a/tests/phpunit/ConstraintParameters.php
+++ b/tests/phpunit/ConstraintParameters.php
@@ -17,6 +17,7 @@
 use Wikibase\DataModel\Snak\PropertySomeValueSnak;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
 use Wikibase\DataModel\Snak\Snak;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
 use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
 use Wikibase\Repo\Parsers\TimeParserFactory;
@@ -313,4 +314,40 @@
                ];
        }
 
+       /**
+        * @param string[] $scopes Context::TYPE_* constants
+        * @return array
+        */
+       public function scopeParameter( array $scopes ) {
+               $config = $this->getDefaultConfig();
+               $constraintScopeParameterId = $config->get( 
'WBQualityConstraintsConstraintScopeId' );
+               $itemIds = [];
+               foreach ( $scopes as $scope ) {
+                       switch ( $scope ) {
+                               case Context::TYPE_STATEMENT:
+                                       $itemIds[] = $config->get( 
'WBQualityConstraintsConstraintCheckedOnMainValueId' );
+                                       break;
+                               case Context::TYPE_QUALIFIER:
+                                       $itemIds[] = $config->get( 
'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
+                                       break;
+                               case Context::TYPE_REFERENCE:
+                                       $itemIds[] = $config->get( 
'WBQualityConstraintsConstraintCheckedOnReferencesId' );
+                                       break;
+                               default:
+                                       $this->assertTrue( false, 'unknown 
context type ' . $scope );
+                       }
+               }
+               return [ $constraintScopeParameterId => array_map(
+                       function ( $itemId ) use ( $constraintScopeParameterId 
) {
+                               return $this->getSnakSerializer()->serialize(
+                                       new PropertyValueSnak(
+                                               new PropertyId( 
$constraintScopeParameterId ),
+                                               new EntityIdValue( new ItemId( 
$itemId ) )
+                                       )
+                               );
+                       },
+                       $itemIds
+               ) ];
+       }
+
 }
diff --git a/tests/phpunit/ResultAssertions.php 
b/tests/phpunit/ResultAssertions.php
index 3a41f11..df64307 100644
--- a/tests/phpunit/ResultAssertions.php
+++ b/tests/phpunit/ResultAssertions.php
@@ -122,4 +122,18 @@
                );
        }
 
+       /**
+        * Assert that $result indicates a skipped constraint check
+        * due to the snak not being within the scope of the constraint.
+        *
+        * @param CheckResult $result
+        */
+       public function assertNotInScope( CheckResult $result ) {
+               $this->assertSame(
+                       CheckResult::STATUS_NOT_IN_SCOPE,
+                       $result->getStatus(),
+                       'Check should indicate that snak is out of scope of 
constraint; message: ' . $result->getMessage()
+               );
+       }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I668908f61a52c9d39ea27f590a1d72cfb541ec75
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

Reply via email to