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

Change subject: Ignore deprecated statements in DiffWithinRangeChecker
......................................................................

Ignore deprecated statements in DiffWithinRangeChecker

When looking for the referenced statement of the constraint (e. g. the
“date of birth” statement for a constraint on “date of death”), skip
deprecated statements.

Two tests for the new behavior are added, along with a test for the
behavior when no referenced statement can be found, which was previously
untested (and should be identical to the behavior when only a deprecated
statement is present).

Bug: T170395
Change-Id: I614e32fc6200c45a4086777eab965f85045b1c57
---
M includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
M tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
2 files changed, 43 insertions(+), 0 deletions(-)


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

diff --git a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php 
b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
index 3caa51a..be5dd45 100644
--- a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
+++ b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php
@@ -106,6 +106,11 @@
                /** @var Statement $otherStatement */
                foreach ( $entity->getStatements() as $otherStatement ) {
                        if ( $property->equals( 
$otherStatement->getPropertyId() ) ) {
+                               // ignore deprecated statements of the 
referenced property
+                               if ( $otherStatement->getRank() === 
Statement::RANK_DEPRECATED ) {
+                                       continue;
+                               }
+
                                $otherMainSnak = $otherStatement->getMainSnak();
 
                                /*
diff --git a/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php 
b/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
index 67d078f..a83ad12 100644
--- a/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
+++ b/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
@@ -146,6 +146,44 @@
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range' );
        }
 
+       public function 
testDiffWithinRangeConstraintWithinRangeWithDeprecatedStatement() {
+               $deprecatedStatement = NewStatement::forProperty( 'P569' )
+                       ->withValue( self::$t1800 )
+                       ->withRank( Statement::RANK_DEPRECATED );
+               $entity = self::$i1970
+                       ->andStatement( $deprecatedStatement ) // should be 
ignored
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t1900 ) )
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
+
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
+               $this->assertCompliance( $checkResult );
+       }
+
+       public function testDiffWithinRangeConstraintWithoutStatement() {
+               $entity = self::$i1970->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
+
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
+               $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range-property-must-exist' );
+       }
+
+       public function 
testDiffWithinRangeConstraintWithOnlyDeprecatedStatement() {
+               $deprecatedStatement = NewStatement::forProperty( 'P569' )
+                       ->withValue( self::$t1900 )
+                       ->withRank( Statement::RANK_DEPRECATED );
+               $entity = self::$i1970
+                       ->andStatement( $deprecatedStatement ) // should be 
ignored
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
+
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
+               $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range-property-must-exist' );
+       }
+
        public function testDiffWithinRangeConstraintWrongTypeOfProperty() {
                $entity = self::$i1970
                        ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( '1900' ) )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I614e32fc6200c45a4086777eab965f85045b1c57
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

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

Reply via email to