jenkins-bot has submitted this change and it was merged. (
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(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
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: merged
Gerrit-Change-Id: I668908f61a52c9d39ea27f590a1d72cfb541ec75
Gerrit-PatchSet: 6
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