jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/346977 )
Change subject: Store entity ID in check result
......................................................................
Store entity ID in check result
The API will support checking for all violations of a given claim (by
claim ID), and it will return check results grouped by entity ID, so it
needs to know the entity ID of each check result. To avoid having to
parse the entity ID out of the claim ID twice, we store it in the check
result. This means that checkConstraint()’s third parameter, $entity, is
no longer optional, which in turn requires many small changes to the
tests, even though most of the tests don’t actually use the entity.
Change-Id: I06d1256dc9c09e390aaf1367d40b5b1890c2142f
---
M includes/ConstraintCheck/Checker/CommonsLinkChecker.php
M includes/ConstraintCheck/Checker/ConflictsWithChecker.php
M includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
M includes/ConstraintCheck/Checker/FormatChecker.php
M includes/ConstraintCheck/Checker/InverseChecker.php
M includes/ConstraintCheck/Checker/ItemChecker.php
M includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
M includes/ConstraintCheck/Checker/MultiValueChecker.php
M includes/ConstraintCheck/Checker/OneOfChecker.php
M includes/ConstraintCheck/Checker/QualifierChecker.php
M includes/ConstraintCheck/Checker/QualifiersChecker.php
M includes/ConstraintCheck/Checker/RangeChecker.php
M includes/ConstraintCheck/Checker/SingleValueChecker.php
M includes/ConstraintCheck/Checker/SymmetricChecker.php
M includes/ConstraintCheck/Checker/TargetRequiredClaimChecker.php
M includes/ConstraintCheck/Checker/TypeChecker.php
M includes/ConstraintCheck/Checker/UniqueValueChecker.php
M includes/ConstraintCheck/Checker/ValueTypeChecker.php
M includes/ConstraintCheck/ConstraintChecker.php
M includes/ConstraintCheck/DelegatingConstraintChecker.php
M includes/ConstraintCheck/Result/CheckResult.php
M tests/phpunit/Checker/CommonsLinkChecker/CommonsLinkCheckerTest.php
M tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
M tests/phpunit/Checker/ConnectionChecker/TargetRequiredClaimCheckerTest.php
M tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
M tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
M tests/phpunit/Checker/QualifierChecker/MandatoryQualifiersCheckerTest.php
M tests/phpunit/Checker/QualifierChecker/QualifierCheckerTest.php
M tests/phpunit/Checker/QualifierChecker/QualifiersCheckerTest.php
M tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
M tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
M tests/phpunit/Checker/ValueCountChecker/UniqueValueCheckerTest.php
M tests/phpunit/Fake/FakeChecker.php
M tests/phpunit/Fake/FakeCheckerTest.php
M tests/phpunit/Result/CheckResultTest.php
35 files changed, 261 insertions(+), 178 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, but someone else must approve
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/ConstraintCheck/Checker/CommonsLinkChecker.php
b/includes/ConstraintCheck/Checker/CommonsLinkChecker.php
index 3c2656d..1452e45 100644
--- a/includes/ConstraintCheck/Checker/CommonsLinkChecker.php
+++ b/includes/ConstraintCheck/Checker/CommonsLinkChecker.php
@@ -39,7 +39,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
$namespace = '';
@@ -60,7 +60,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -72,7 +72,7 @@
*/
if ( $dataValue->getType() !== 'string' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'string' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$commonsLink = $dataValue->getValue();
@@ -96,7 +96,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
/**
diff --git a/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
b/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
index ae5b337..d144d09 100644
--- a/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
+++ b/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
@@ -54,7 +54,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -64,7 +64,7 @@
*/
if ( !array_key_exists( 'property', $constraintParameters ) ) {
$message = wfMessage(
"wbqc-violation-message-parameter-needed" )->params(
$constraint->getConstraintTypeName(), 'property' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$parameters['property'] =
$this->constraintParameterParser->parseSingleParameter(
$constraintParameters['property'] );
@@ -95,7 +95,7 @@
}
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
index 54806d0..4a86ce3 100644
--- a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
+++ b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
@@ -47,7 +47,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
$property = false;
@@ -68,7 +68,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -91,7 +91,7 @@
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'quantity" or "time' )->escaped();
}
if ( isset( $message ) ) {
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$thisValue = $this->rangeCheckerHelper->getComparativeValue(
$dataValue );
@@ -108,7 +108,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-diff-within-range-property-needs value" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult(
$entity->getId(), $statement, $constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
if ( $mainSnak->getDataValue()->getType() ===
$dataValue->getType() && $mainSnak->getType() === 'value' ) {
@@ -129,13 +129,13 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(),
$statement, $constraint->getConstraintTypeQid(), $parameters, $status, $message
);
}
}
$message = wfMessage(
"wbqc-violation-message-diff-within-range-property-must-exist" )->escaped();
$status = CheckResult::STATUS_VIOLATION;
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/FormatChecker.php
b/includes/ConstraintCheck/Checker/FormatChecker.php
index cbe0cb0..867ed09 100644
--- a/includes/ConstraintCheck/Checker/FormatChecker.php
+++ b/includes/ConstraintCheck/Checker/FormatChecker.php
@@ -39,7 +39,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -48,7 +48,7 @@
$parameters['pattern'] =
$this->helper->parseSingleParameter( $pattern, true );
} else {
$message = wfMessage(
"wbqc-violation-message-parameter-needed" )->params(
$constraint->getConstraintTypeName(), 'pattern' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
if ( array_key_exists( 'constraint_status',
$constraintParameters ) ) {
@@ -63,7 +63,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -75,11 +75,11 @@
*/
if ( $dataValue->getType() !== 'string' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'string' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$message = wfMessage( 'wbqc-violation-message-security-reason'
)->params( $constraint->getConstraintTypeName(), 'string' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, CheckResult::STATUS_TODO,
$message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, CheckResult::STATUS_TODO,
$message );
}
}
diff --git a/includes/ConstraintCheck/Checker/InverseChecker.php
b/includes/ConstraintCheck/Checker/InverseChecker.php
index 99babb2..ba52d56 100644
--- a/includes/ConstraintCheck/Checker/InverseChecker.php
+++ b/includes/ConstraintCheck/Checker/InverseChecker.php
@@ -56,7 +56,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -76,7 +76,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -88,20 +88,20 @@
*/
if ( $dataValue->getType() !== 'wikibase-entityid' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'wikibase-entityid' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/** @var EntityIdValue $dataValue */
if ( !array_key_exists( 'property', $constraintParameters ) ) {
$message = wfMessage(
"wbqc-violation-message-property-needed" )->params(
$constraint->getConstraintTypeName(), 'property' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$property = $constraintParameters['property'];
$targetItem = $this->entityLookup->getEntity(
$dataValue->getEntityId() );
if ( $targetItem === null ) {
$message = wfMessage(
"wbqc-violation-message-target-entity-must-exist" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$targetItemStatementList = $targetItem->getStatements();
@@ -113,7 +113,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/ItemChecker.php
b/includes/ConstraintCheck/Checker/ItemChecker.php
index 105c506..2b5c0a3 100644
--- a/includes/ConstraintCheck/Checker/ItemChecker.php
+++ b/includes/ConstraintCheck/Checker/ItemChecker.php
@@ -54,7 +54,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -76,7 +76,7 @@
*/
if ( !$property ) {
$message = wfMessage(
"wbqc-violation-message-property-needed" )->params(
$constraint->getConstraintTypeName(), 'property' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/*
@@ -102,7 +102,7 @@
}
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
index 80958d4..8c8087c 100644
--- a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
+++ b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
@@ -39,7 +39,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -67,7 +67,7 @@
}
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/MultiValueChecker.php
b/includes/ConstraintCheck/Checker/MultiValueChecker.php
index 7682742..68c08ca 100644
--- a/includes/ConstraintCheck/Checker/MultiValueChecker.php
+++ b/includes/ConstraintCheck/Checker/MultiValueChecker.php
@@ -35,7 +35,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$propertyId = $statement->getPropertyId();
$parameters = array ();
@@ -50,7 +50,7 @@
$status = CheckResult::STATUS_COMPLIANCE;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/OneOfChecker.php
b/includes/ConstraintCheck/Checker/OneOfChecker.php
index fe735c2..03c025e 100644
--- a/includes/ConstraintCheck/Checker/OneOfChecker.php
+++ b/includes/ConstraintCheck/Checker/OneOfChecker.php
@@ -40,7 +40,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -62,7 +62,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement, 'One of',
$parameters, CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
'One of', $parameters, CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -74,13 +74,13 @@
*/
if ( $dataValue->getType() !== 'wikibase-entityid' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'wikibase-entityid' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/** @var EntityIdValue $dataValue */
if ( !$items ) {
$message = wfMessage(
"wbqc-violation-message-property-needed" )->params(
$constraint->getConstraintTypeName(), 'property' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
if ( in_array( $dataValue->getEntityId()->getSerialization(),
$items ) ) {
@@ -91,7 +91,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/QualifierChecker.php
b/includes/ConstraintCheck/Checker/QualifierChecker.php
index d033095..49c3aa3 100644
--- a/includes/ConstraintCheck/Checker/QualifierChecker.php
+++ b/includes/ConstraintCheck/Checker/QualifierChecker.php
@@ -39,9 +39,9 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$message = wfMessage( "wbqc-violation-message-qualifier"
)->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), array (), CheckResult::STATUS_VIOLATION,
$message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), array (), CheckResult::STATUS_VIOLATION,
$message );
}
}
diff --git a/includes/ConstraintCheck/Checker/QualifiersChecker.php
b/includes/ConstraintCheck/Checker/QualifiersChecker.php
index 8c467f9..cbd7d1a 100644
--- a/includes/ConstraintCheck/Checker/QualifiersChecker.php
+++ b/includes/ConstraintCheck/Checker/QualifiersChecker.php
@@ -41,7 +41,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -65,7 +65,7 @@
}
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/RangeChecker.php
b/includes/ConstraintCheck/Checker/RangeChecker.php
index 60c6f51..eea4d2c 100644
--- a/includes/ConstraintCheck/Checker/RangeChecker.php
+++ b/includes/ConstraintCheck/Checker/RangeChecker.php
@@ -47,7 +47,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -63,7 +63,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -95,7 +95,7 @@
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'quantity" or "time' )->escaped();
}
if ( isset( $message ) ) {
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$comparativeValue =
$this->rangeCheckerHelper->getComparativeValue( $dataValue );
@@ -108,7 +108,7 @@
$status = CheckResult::STATUS_COMPLIANCE;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/SingleValueChecker.php
b/includes/ConstraintCheck/Checker/SingleValueChecker.php
index 3265e7a..398df13 100644
--- a/includes/ConstraintCheck/Checker/SingleValueChecker.php
+++ b/includes/ConstraintCheck/Checker/SingleValueChecker.php
@@ -35,7 +35,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$propertyId = $statement->getPropertyId();
$parameters = array ();
@@ -50,7 +50,7 @@
$status = CheckResult::STATUS_COMPLIANCE;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/SymmetricChecker.php
b/includes/ConstraintCheck/Checker/SymmetricChecker.php
index 68d89c2..8b95d40 100644
--- a/includes/ConstraintCheck/Checker/SymmetricChecker.php
+++ b/includes/ConstraintCheck/Checker/SymmetricChecker.php
@@ -56,7 +56,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -73,7 +73,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -84,14 +84,14 @@
*/
if ( $dataValue->getType() !== 'wikibase-entityid' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName(), 'wikibase-entityid' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/** @var EntityIdValue $dataValue */
$targetItem = $this->entityLookup->getEntity(
$dataValue->getEntityId() );
if ( $targetItem === null ) {
$message = wfMessage(
"wbqc-violation-message-target-entity-must-exist" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$targetItemStatementList = $targetItem->getStatements();
@@ -103,7 +103,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/TargetRequiredClaimChecker.php
b/includes/ConstraintCheck/Checker/TargetRequiredClaimChecker.php
index 8999461..e722282 100644
--- a/includes/ConstraintCheck/Checker/TargetRequiredClaimChecker.php
+++ b/includes/ConstraintCheck/Checker/TargetRequiredClaimChecker.php
@@ -56,7 +56,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -84,7 +84,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeName() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -96,19 +96,19 @@
*/
if ( $dataValue->getType() !== 'wikibase-entityid' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeName(), 'wikibase-entityid' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/** @var EntityIdValue $dataValue */
if ( !$property ) {
$message = wfMessage(
"wbqc-violation-message-property-needed" )->params(
$constraint->getConstraintTypeName(), 'property' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$targetEntity = $this->entityLookup->getEntity(
$dataValue->getEntityId() );
if ( $targetEntity === null ) {
$message = wfMessage(
"wbqc-violation-message-target-entity-must-exist" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$targetEntityStatementList = $targetEntity->getStatements();
@@ -135,7 +135,7 @@
}
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/TypeChecker.php
b/includes/ConstraintCheck/Checker/TypeChecker.php
index 62fdf47..b11c4d5 100644
--- a/includes/ConstraintCheck/Checker/TypeChecker.php
+++ b/includes/ConstraintCheck/Checker/TypeChecker.php
@@ -57,7 +57,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -79,7 +79,7 @@
*/
if ( !$classes ) {
$message = wfMessage(
"wbqc-violation-message-parameter-needed" )->params(
$constraint->getConstraintTypeName(), 'class' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/*
@@ -92,7 +92,7 @@
$relationId = self::subclassId;
} else {
$message = wfMessage(
"wbqc-violation-message-type-relation-instance-or-subclass" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
if ( $this->typeCheckerHelper->hasClassInRelation(
$entity->getStatements(), $relationId, $classes ) ) {
@@ -103,7 +103,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/Checker/UniqueValueChecker.php
b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
index b6c46bc..082a82a 100644
--- a/includes/ConstraintCheck/Checker/UniqueValueChecker.php
+++ b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
@@ -36,11 +36,11 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
- $message = wfMessage(
"wbqc-violation-message-not-yet-implemented" )->params(
$constraint->getConstraintTypeName(), 'string' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, CheckResult::STATUS_TODO,
$message );
+ $message = wfMessage(
"wbqc-violation-message-not-yet-implemented" )->params(
$constraint->getConstraintTypeName() )->escaped();
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, CheckResult::STATUS_TODO,
$message );
}
}
diff --git a/includes/ConstraintCheck/Checker/ValueTypeChecker.php
b/includes/ConstraintCheck/Checker/ValueTypeChecker.php
index 7f66399..ee3ba0b 100644
--- a/includes/ConstraintCheck/Checker/ValueTypeChecker.php
+++ b/includes/ConstraintCheck/Checker/ValueTypeChecker.php
@@ -59,7 +59,7 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null ) {
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity ) {
$parameters = array ();
$constraintParameters = $constraint->getConstraintParameters();
@@ -87,7 +87,7 @@
*/
if ( !$mainSnak instanceof PropertyValueSnak ) {
$message = wfMessage(
"wbqc-violation-message-value-needed" )->params(
$constraint->getConstraintTypeQid() )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$dataValue = $mainSnak->getDataValue();
@@ -99,13 +99,13 @@
*/
if ( $dataValue->getType() !== 'wikibase-entityid' ) {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-type" )->params(
$constraint->getConstraintTypeQid(), 'wikibase-entityid' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/** @var EntityIdValue $dataValue */
if ( !$classes ) {
$message = wfMessage(
"wbqc-violation-message-parameter-needed" )->params(
$constraint->getConstraintTypeQid(), 'class' )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
/*
@@ -118,14 +118,14 @@
$relationId = self::subclassId;
} else {
$message = wfMessage(
"wbqc-violation-message-type-relation-instance-or-subclass" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$item = $this->entityLookup->getEntity(
$dataValue->getEntityId() );
if ( !( $item instanceof StatementListProvider ) ) {
$message = wfMessage(
"wbqc-violation-message-value-entity-must-exist" )->escaped();
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters,
CheckResult::STATUS_VIOLATION, $message );
}
$statements = $item->getStatements();
@@ -138,7 +138,7 @@
$status = CheckResult::STATUS_VIOLATION;
}
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), $parameters, $status, $message );
}
}
diff --git a/includes/ConstraintCheck/ConstraintChecker.php
b/includes/ConstraintCheck/ConstraintChecker.php
index a6638c0..59fd0dd 100644
--- a/includes/ConstraintCheck/ConstraintChecker.php
+++ b/includes/ConstraintCheck/ConstraintChecker.php
@@ -17,6 +17,6 @@
*
* @return CheckResult
*/
- public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity = null );
+ public function checkConstraint( Statement $statement, Constraint
$constraint, EntityDocument $entity );
}
diff --git a/includes/ConstraintCheck/DelegatingConstraintChecker.php
b/includes/ConstraintCheck/DelegatingConstraintChecker.php
index 20bdab1..0652262 100644
--- a/includes/ConstraintCheck/DelegatingConstraintChecker.php
+++ b/includes/ConstraintCheck/DelegatingConstraintChecker.php
@@ -117,7 +117,7 @@
$parameter = $constraint->getConstraintParameters();
if ( array_key_exists( 'known_exception', $parameter)
&& in_array( $entity->getId()->getSerialization(), explode( ',',
$parameter['known_exception'] ) ) ) {
$message = 'This entity is a known exception
for this constraint and has been marked as such.';
- $result[] = new CheckResult( $statement,
$constraint->getConstraintTypeQid(), array (), CheckResult::STATUS_EXCEPTION,
$message ); // todo: display parameters anyway
+ $result[] = new CheckResult( $entity->getId(),
$statement, $constraint->getConstraintTypeQid(), array (),
CheckResult::STATUS_EXCEPTION, $message ); // todo: display parameters anyway
continue;
}
@@ -149,7 +149,7 @@
return $result;
} else {
- return new CheckResult( $statement,
$constraint->getConstraintTypeQid() );
+ return new CheckResult( $entity->getId(), $statement,
$constraint->getConstraintTypeQid() );
}
}
diff --git a/includes/ConstraintCheck/Result/CheckResult.php
b/includes/ConstraintCheck/Result/CheckResult.php
index d5bdd8d..19618d1 100644
--- a/includes/ConstraintCheck/Result/CheckResult.php
+++ b/includes/ConstraintCheck/Result/CheckResult.php
@@ -5,6 +5,7 @@
use DataValues\DataValue;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\PropertyId;
use LogicException;
@@ -22,6 +23,11 @@
const STATUS_VIOLATION = 'violation';
const STATUS_EXCEPTION = 'exception';
const STATUS_TODO = 'todo';
+
+ /**
+ * @var EntityId
+ */
+ private $entityId;
/**
* @var Statement
@@ -50,13 +56,15 @@
private $message;
/**
+ * @param EntityId $entityId
* @param Statement $statement
* @param string $constraintName
* @param array $parameters (string => string[])
* @param string $status
* @param string $message (sanitized HTML)
*/
- public function __construct( Statement $statement, $constraintName,
$parameters = array (), $status = self::STATUS_TODO, $message = '' ) {
+ public function __construct( EntityId $entityId, Statement $statement,
$constraintName, $parameters = array (), $status = self::STATUS_TODO, $message
= '' ) {
+ $this->entityId = $entityId;
$this->statement = $statement;
$this->constraintName = $constraintName;
$this->parameters = $parameters;
@@ -65,6 +73,13 @@
}
/**
+ * @return EntityId
+ */
+ public function getEntityId() {
+ return $this->entityId;
+ }
+
+ /**
* @return Statement
*/
public function getStatement() {
diff --git
a/tests/phpunit/Checker/CommonsLinkChecker/CommonsLinkCheckerTest.php
b/tests/phpunit/Checker/CommonsLinkChecker/CommonsLinkCheckerTest.php
index 156d888..17f9694 100644
--- a/tests/phpunit/Checker/CommonsLinkChecker/CommonsLinkCheckerTest.php
+++ b/tests/phpunit/Checker/CommonsLinkChecker/CommonsLinkCheckerTest.php
@@ -7,6 +7,7 @@
use Wikibase\DataModel\Snak\PropertyValueSnak;
use DataValues\StringValue;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -75,7 +76,7 @@
public function testCommonsLinkConstraintValid() {
$value = new StringValue( 'test image.jpg' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value ) );
- $this->assertEquals( 'compliance',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should comply' );
+ $this->assertEquals( 'compliance',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should comply' );
}
public function testCommonsLinkConstraintInvalid() {
@@ -85,36 +86,36 @@
$statement1 = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value1 ) );
$statement2 = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value2 ) );
$statement3 = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value3 ) );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement1,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement2,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement3,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement1,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement2,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement3,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
}
public function testNotImplementedNamespaces() {
$value = new StringValue( 'test image.jpg' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value ) );
- $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array() ) )->getStatus(), 'check is not implemented'
);
- $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Gallery') ) )->getStatus(),
'check is not implemented' );
- $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Institution') )
)->getStatus(), 'check is not implemented' );
- $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Museum') ) )->getStatus(),
'check is not implemented' );
- $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Creator') ) )->getStatus(),
'check is not implemented' );
+ $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array() ), $this->getEntity() )->getStatus(), 'check
is not implemented' );
+ $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Gallery') ),
$this->getEntity() )->getStatus(), 'check is not implemented' );
+ $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Institution') ),
$this->getEntity() )->getStatus(), 'check is not implemented' );
+ $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Museum') ), $this->getEntity()
)->getStatus(), 'check is not implemented' );
+ $this->assertEquals( 'todo',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'Creator') ),
$this->getEntity() )->getStatus(), 'check is not implemented' );
}
public function testCommonsLinkConstraintNotExistent() {
$value = new StringValue( 'no image.jpg' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value ) );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
}
public function testCommonsLinkConstraintNoStringValue() {
$value = new EntityIdValue( new ItemId( 'Q1' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), $value ) );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
}
public function testCommonsLinkConstraintNoValueSnak() {
$statement = new Statement( new PropertyNoValueSnak( 1 ) );
- $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ) )->getStatus(),
'check should not comply' );
+ $this->assertEquals( 'violation',
$this->commonsLinkChecker->checkConstraint( $statement,
$this->getConstraintMock( array( 'namespace' => 'File' ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
}
/**
@@ -137,4 +138,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git a/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
b/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
index 693ac71..9acb836 100644
--- a/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
+++ b/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
@@ -8,6 +8,7 @@
use Wikibase\DataModel\Snak\PropertyValueSnak;
use DataValues\StringValue;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -49,18 +50,12 @@
*/
private $checker;
- /**
- * @var EntityDocument
- */
- private $entity;
-
protected function setUp() {
parent::setUp();
$this->lookup = new JsonFileEntityLookup( __DIR__ );
$this->helper = new ConstraintParameterParser();
$this->connectionCheckerHelper = new ConnectionCheckerHelper();
$this->checker = new SymmetricChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper );
- $this->entity = $this->lookup->getEntity( new ItemId( 'Q1' ) );
}
protected function tearDown() {
@@ -68,7 +63,6 @@
unset( $this->helper );
unset( $this->connectionCheckerHelper );
unset( $this->checker );
- unset( $this->entity );
parent::tearDown();
}
@@ -76,7 +70,7 @@
$value = new EntityIdValue( new ItemId( 'Q3' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->entity );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -84,7 +78,7 @@
$value = new EntityIdValue( new ItemId( 'Q2' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->entity );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -92,7 +86,7 @@
$value = new StringValue( 'Q3' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->entity );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -100,14 +94,14 @@
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->entity );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
public function testSymmetricConstraintNoValueSnak() {
$statement = new Statement( new PropertyNoValueSnak( 1 ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->entity );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock(), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -129,4 +123,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git
a/tests/phpunit/Checker/ConnectionChecker/TargetRequiredClaimCheckerTest.php
b/tests/phpunit/Checker/ConnectionChecker/TargetRequiredClaimCheckerTest.php
index b1468ca..816ec95 100644
--- a/tests/phpunit/Checker/ConnectionChecker/TargetRequiredClaimCheckerTest.php
+++ b/tests/phpunit/Checker/ConnectionChecker/TargetRequiredClaimCheckerTest.php
@@ -7,6 +7,7 @@
use Wikibase\DataModel\Snak\PropertyValueSnak;
use DataValues\StringValue;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -72,7 +73,7 @@
'property' => 'P2',
'item' => 'Q42'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -84,7 +85,7 @@
'property' => 'P2',
'item' => 'Q2'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -95,7 +96,7 @@
$constraintParameters = array(
'property' => 'P2'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -106,7 +107,7 @@
$constraintParameters = array(
'property' => 'P3'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -115,7 +116,7 @@
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
$constraintParameters = array();
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -126,7 +127,7 @@
$constraintParameters = array(
'property' => 'P2'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -137,7 +138,7 @@
$constraintParameters = array(
'property' => 'P2'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -147,7 +148,7 @@
$constraintParameters = array(
'property' => 'P2'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -171,4 +172,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
index f2601dc..12d64fd 100644
--- a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
+++ b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
@@ -7,6 +7,7 @@
use Wikibase\DataModel\Snak\PropertyValueSnak;
use DataValues\StringValue;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -73,16 +74,16 @@
$statement9 = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value9 ) );
$statement10 = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value10 ) );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
}
public function testFormatConstraintTaxonName() {
@@ -110,36 +111,36 @@
$statement9 = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value9 ) );
$statement10 = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value10 ) );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
}
public function testFormatConstraintEmptyPattern() {
$pattern = null;
$value = new StringValue( 'Populus × canescens' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value ) );
- $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'todo',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
}
public function testFormatConstraintNoStringValue() {
$pattern =
"(|somevalue|novalue|.*virus.*|.*viroid.*|.*phage.*|((×)?[A-Z]([a-z]+-)?[a-z]+((
[A-Z]?[a-z]+)|( ([a-z]+-)?([a-z]+-)?[a-z]+)|(
×([a-z]+-)?([a-z]+-)?([a-z]+-)?([a-z]+-)?[a-z]+)|( \([A-Z][a-z]+\) [a-z]+)|(
(‘|')[A-Z][a-z]+(('|’)s)?( de)?( [A-Z][a-z]+(-([A-Z])?[a-z]+)*)*('|’)*)|( ×|
Group| (sub)?sp\.| (con)?(sub)?(notho)?var\.| (sub)?ser\.| (sub)?sect\.|
subg\.| (sub)?f\.))*))";
$value = new EntityIdValue( new ItemId( 'Q1' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P345' ), $value ) );
- $this->assertEquals( 'violation',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
}
public function testFormatConstraintNoValueSnak() {
$pattern = ".";
$statement = new Statement( new PropertyNoValueSnak( 1 ) );
- $this->assertEquals( 'violation',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->formatChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'pattern' => $pattern ) ), $this->getEntity() )->getStatus(), 'check
should not comply' );
}
/**
@@ -162,4 +163,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git a/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
b/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
index e88f679..3df6413 100644
--- a/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
+++ b/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
@@ -7,6 +7,7 @@
use Wikibase\DataModel\Snak\PropertyValueSnak;
use DataValues\StringValue;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -56,34 +57,34 @@
$values = 'Q1,Q2,Q3';
- $this->assertEquals( 'compliance',
$this->oneOfChecker->checkConstraint( $statementIn, $this->getConstraintMock(
array( 'item' => $values ) ) )->getStatus(), 'check should comply' );
- $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statementNotIn,
$this->getConstraintMock( array( 'item' => $values ) ) )->getStatus(), 'check
should not comply' );
+ $this->assertEquals( 'compliance',
$this->oneOfChecker->checkConstraint( $statementIn, $this->getConstraintMock(
array( 'item' => $values ) ), $this->getEntity() )->getStatus(), 'check should
comply' );
+ $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statementNotIn,
$this->getConstraintMock( array( 'item' => $values ) ), $this->getEntity()
)->getStatus(), 'check should not comply' );
}
public function testOneOfConstraintWrongType() {
$value = new StringValue( 'Q1' );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P123' ), $value ) );
$values = 'Q1,Q2,Q3';
- $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ), $this->getEntity() )->getStatus(), 'check should
not comply' );
}
public function testOneOfConstraintEmptyArray() {
$value = new EntityIdValue( new ItemId( 'Q1' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P123' ), $value ) );
- $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array() ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array() ), $this->getEntity() )->getStatus(), 'check should not comply' );
}
public function testOneOfConstraintArrayWithSomevalue() {
$value = new EntityIdValue( new ItemId( 'Q1' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P123' ), $value ) );
$values = 'Q1,Q2,Q3,somevalue';
- $this->assertEquals( 'compliance',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ) )->getStatus(), 'check should comply' );
+ $this->assertEquals( 'compliance',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ), $this->getEntity() )->getStatus(), 'check should
comply' );
}
public function testOneOfConstraintNoValueSnak() {
$statement = new Statement( new PropertyNoValueSnak( 1 ) );
$values = 'Q1,Q2,Q3,somevalue';
- $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ) )->getStatus(), 'check should not comply' );
+ $this->assertEquals( 'violation',
$this->oneOfChecker->checkConstraint( $statement, $this->getConstraintMock(
array( 'item' => $values ) ), $this->getEntity() )->getStatus(), 'check should
not comply' );
}
/**
@@ -106,4 +107,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git
a/tests/phpunit/Checker/QualifierChecker/MandatoryQualifiersCheckerTest.php
b/tests/phpunit/Checker/QualifierChecker/MandatoryQualifiersCheckerTest.php
index 5f6a53f..4b0a84b 100644
--- a/tests/phpunit/Checker/QualifierChecker/MandatoryQualifiersCheckerTest.php
+++ b/tests/phpunit/Checker/QualifierChecker/MandatoryQualifiersCheckerTest.php
@@ -60,7 +60,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
$qualifierChecker = new MandatoryQualifiersChecker(
$this->helper );
- $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => 'P2' ) ) );
+ $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => 'P2' ) ), $entity );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -68,7 +68,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
$qualifierChecker = new MandatoryQualifiersChecker(
$this->helper );
- $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => 'P2,P3' ) ) );
+ $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => 'P2,P3' ) ), $entity );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
diff --git a/tests/phpunit/Checker/QualifierChecker/QualifierCheckerTest.php
b/tests/phpunit/Checker/QualifierChecker/QualifierCheckerTest.php
index e0959d8..b575d46 100644
--- a/tests/phpunit/Checker/QualifierChecker/QualifierCheckerTest.php
+++ b/tests/phpunit/Checker/QualifierChecker/QualifierCheckerTest.php
@@ -60,7 +60,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q1' ) );
$qualifierChecker = new QualifierChecker( $this->helper );
- $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array() ) );
+ $checkResult = $qualifierChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array() ),
$entity );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
diff --git a/tests/phpunit/Checker/QualifierChecker/QualifiersCheckerTest.php
b/tests/phpunit/Checker/QualifierChecker/QualifiersCheckerTest.php
index ba30bd7..38c89d7 100644
--- a/tests/phpunit/Checker/QualifierChecker/QualifiersCheckerTest.php
+++ b/tests/phpunit/Checker/QualifierChecker/QualifiersCheckerTest.php
@@ -67,7 +67,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q2' ) );
$qualifiersChecker = new QualifiersChecker( $this->helper );
- $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ) );
+ $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ), $entity );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -75,7 +75,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q3' ) );
$qualifiersChecker = new QualifiersChecker( $this->helper );
- $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ) );
+ $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ), $entity );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -83,7 +83,7 @@
/** @var Item $entity */
$entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
$qualifiersChecker = new QualifiersChecker( $this->helper );
- $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ) );
+ $checkResult = $qualifiersChecker->checkConstraint(
$this->getFirstStatement( $entity ), $this->getConstraintMock( array(
'property' => $this->qualifiersList ) ), $entity );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
diff --git a/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
b/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
index aa8bb84..2eebd07 100644
--- a/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
+++ b/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
@@ -9,6 +9,8 @@
use DataValues\QuantityValue;
use DataValues\StringValue;
use DataValues\TimeValue;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use WikibaseQuality\ConstraintReport\Constraint;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\RangeChecker;
@@ -72,7 +74,7 @@
'minimum_quantity' => 0,
'maximum_quantity' => 10
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -83,7 +85,7 @@
'minimum_quantity' => 100,
'maximum_quantity' => 1000
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -94,7 +96,7 @@
'minimum_quantity' => 0,
'maximum_quantity' => 1
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -106,7 +108,7 @@
'minimum_date' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -118,7 +120,7 @@
'minimum_date' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -130,7 +132,7 @@
'minimum_date' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -142,7 +144,7 @@
'minimum_quantity' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -154,7 +156,7 @@
'minimum_quantity' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -166,14 +168,14 @@
'minimum_date' => $min,
'maximum_date' => $max
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
public function testRangeConstraintNoValueSnak() {
$statement = new Statement( new PropertyNoValueSnak( 1 ) );
$constraintParameters = array();
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -197,4 +199,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
index 08fdc41..145fb7f 100644
--- a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
+++ b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
@@ -5,6 +5,7 @@
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
@@ -64,7 +65,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -74,7 +75,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -84,7 +85,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -95,7 +96,7 @@
'relation' => 'subclass',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -105,7 +106,7 @@
'relation' => 'subclass',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -115,7 +116,7 @@
'relation' => 'subclass',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
@@ -126,7 +127,7 @@
'relation' => 'instance',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -136,7 +137,7 @@
'relation' => 'instance',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -146,7 +147,7 @@
'relation' => 'instance',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -157,7 +158,7 @@
'relation' => 'subclass',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -167,7 +168,7 @@
'relation' => 'subclass',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -177,7 +178,7 @@
'relation' => 'subclass',
'class' => 'Q200,Q201'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -187,7 +188,7 @@
$constraintParameters = array(
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -196,7 +197,7 @@
$constraintParameters = array(
'relation' => 'instance'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -206,7 +207,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -216,7 +217,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -226,7 +227,7 @@
'relation' => 'instance',
'class' => 'Q100,Q101'
);
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertEquals( 'violation', $checkResult->getStatus(),
'check should not comply' );
}
@@ -250,4 +251,11 @@
return $mock;
}
+ /**
+ * @return EntityDocument
+ */
+ private function getEntity() {
+ return new Item( new ItemId( 'Q1' ) );
+ }
+
}
diff --git a/tests/phpunit/Checker/ValueCountChecker/UniqueValueCheckerTest.php
b/tests/phpunit/Checker/ValueCountChecker/UniqueValueCheckerTest.php
index c8e3527..6920e02 100644
--- a/tests/phpunit/Checker/ValueCountChecker/UniqueValueCheckerTest.php
+++ b/tests/phpunit/Checker/ValueCountChecker/UniqueValueCheckerTest.php
@@ -4,6 +4,7 @@
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Entity\EntityIdValue;
@@ -46,8 +47,10 @@
// todo: it is currently only testing that 'todo' comes back
public function testCheckUniqueValueConstraint() {
- $statement = new Statement( new PropertyValueSnak(
$this->uniquePropertyId, new EntityIdValue( new ItemId( 'Q404' ) ) ) );
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( array() ) );
+ $itemId = new ItemId( 'Q404' );
+ $entity = new Item( $itemId );
+ $statement = new Statement( new PropertyValueSnak(
$this->uniquePropertyId, new EntityIdValue( $itemId ) ) );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( array() ), $entity );
$this->assertEquals( 'todo', $checkResult->getStatus(), 'check
should point out that it should be implemented soon' );
}
diff --git a/tests/phpunit/Fake/FakeChecker.php
b/tests/phpunit/Fake/FakeChecker.php
index 9a9a797..4b4aee0 100644
--- a/tests/phpunit/Fake/FakeChecker.php
+++ b/tests/phpunit/Fake/FakeChecker.php
@@ -27,10 +27,10 @@
public function checkConstraint(
Statement $statement,
Constraint $constraint,
- EntityDocument $entity = null
+ EntityDocument $entity
) {
return new CheckResult(
- $statement, $constraint->getConstraintTypeQid(), [],
$this->status
+ $entity->getId(), $statement,
$constraint->getConstraintTypeQid(), [], $this->status
);
}
}
diff --git a/tests/phpunit/Fake/FakeCheckerTest.php
b/tests/phpunit/Fake/FakeCheckerTest.php
index 4dc8ed0..90e237e 100644
--- a/tests/phpunit/Fake/FakeCheckerTest.php
+++ b/tests/phpunit/Fake/FakeCheckerTest.php
@@ -2,6 +2,8 @@
namespace WikibaseQuality\ConstraintReport\Tests\Fake;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Statement\Statement;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -14,7 +16,8 @@
$statement = $this->dummy( Statement::class );
$result = $checker->checkConstraint(
$statement,
- $this->dummy( Constraint::class )
+ $this->dummy( Constraint::class ),
+ new Item( new ItemId( 'Q1' ) )
);
$this->assertSame( $statement, $result->getStatement() );
@@ -26,7 +29,8 @@
$constraintTypeId = 'constraint id';
$result = $checker->checkConstraint(
$this->dummy( Statement::class ),
- new Constraint( 'some guid', $this->dummy(
PropertyId::class ), $constraintTypeId, [] )
+ new Constraint( 'some guid', $this->dummy(
PropertyId::class ), $constraintTypeId, [] ),
+ new Item( new ItemId( 'Q1' ) )
);
$this->assertSame( $constraintTypeId,
$result->getConstraintName() );
@@ -38,7 +42,8 @@
$checker = new FakeChecker( $expectedStatus );
$result = $checker->checkConstraint(
$this->dummy( Statement::class ),
- $this->dummy( Constraint::class )
+ $this->dummy( Constraint::class ),
+ new Item( new ItemId( 'Q1' ) )
);
$this->assertSame( $expectedStatus, $result->getStatus() );
diff --git a/tests/phpunit/Result/CheckResultTest.php
b/tests/phpunit/Result/CheckResultTest.php
index 2cb2e54..2687806 100644
--- a/tests/phpunit/Result/CheckResultTest.php
+++ b/tests/phpunit/Result/CheckResultTest.php
@@ -7,6 +7,8 @@
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use DataValues\StringValue;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
@@ -19,6 +21,11 @@
* @license GNU GPL v2+
*/
class CheckResultTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var EntityId
+ */
+ private $entityId;
/**
* @var Statement
@@ -47,6 +54,7 @@
protected function setUp() {
parent::setUp();
+ $this->entityId = new ItemId( 'Q1' );
$this->statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1' ), new StringValue( 'Foo' ) ) );
$this->constraintName = 'Range';
$this->parameters = array ();
@@ -56,6 +64,7 @@
protected function tearDown() {
parent::tearDown();
+ unset( $this->entityId );
unset( $this->statement );
unset( $this->constraintName );
unset( $this->parameters );
@@ -64,7 +73,8 @@
}
public function testConstructAndGetters() {
- $checkResult = new CheckResult( $this->statement,
$this->constraintName, $this->parameters, $this->status, $this->message );
+ $checkResult = new CheckResult( $this->entityId,
$this->statement, $this->constraintName, $this->parameters, $this->status,
$this->message );
+ $this->assertEquals( $this->entityId,
$checkResult->getEntityId() );
$this->assertEquals( $this->statement,
$checkResult->getStatement() );
$this->assertEquals( $this->statement->getPropertyId(),
$checkResult->getPropertyId() );
$this->assertEquals(
$this->statement->getMainSnak()->getDataValue(), $checkResult->getDataValue() );
@@ -76,7 +86,7 @@
}
public function testWithWrongSnakType() {
- $checkResult = new CheckResult( new Statement( new
PropertyNoValueSnak( 1 ) ), $this->constraintName, $this->parameters,
$this->status, $this->message );
+ $checkResult = new CheckResult( $this->entityId, new Statement(
new PropertyNoValueSnak( 1 ) ), $this->constraintName, $this->parameters,
$this->status, $this->message );
$this->setExpectedException( LogicException::class );
$checkResult->getDataValue();
}
--
To view, visit https://gerrit.wikimedia.org/r/346977
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I06d1256dc9c09e390aaf1367d40b5b1890c2142f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits