jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/351612 )
Change subject: Replace "now" with current time before comparing
......................................................................
Replace "now" with current time before comparing
The special string "now" corresponds to the current time, so we turn it
into the current time formatted like a TimeValue.
(Note that due to T164279, the string will not be compared correctly –
this will be fixed in a separate change.)
Also adds a test, but due to the bug mentioned above, the min date for
the test has to be formatted differently so that the string comparison
works – a later change should clean that up.
Bug: T90107
Change-Id: I3fb31596c9c7a7447caa6bbfdb911b553da35daa
---
M includes/ConstraintCheck/Checker/RangeChecker.php
M tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
2 files changed, 21 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Thiemo Mättig (WMDE): Looks good to me, approved
diff --git a/includes/ConstraintCheck/Checker/RangeChecker.php
b/includes/ConstraintCheck/Checker/RangeChecker.php
index 3c8a255..8bdcda3 100644
--- a/includes/ConstraintCheck/Checker/RangeChecker.php
+++ b/includes/ConstraintCheck/Checker/RangeChecker.php
@@ -91,6 +91,15 @@
} else {
$message = wfMessage(
"wbqc-violation-message-range-parameters-needed" )->params( 'time',
'minimum_date', 'maximum_date' )->escaped();
}
+ if ( isset( $min ) && isset( $max ) ) {
+ $now = gmdate( '+Y-m-d\TH:i:s\Z' );
+ if ( $min === 'now' ) {
+ $min = $now;
+ }
+ if ( $max === 'now' ) {
+ $max = $now;
+ }
+ }
} else {
$message = wfMessage(
"wbqc-violation-message-value-needed-of-types-2" )->params(
$constraint->getConstraintTypeName(), 'quantity', 'time' )->escaped();
}
diff --git a/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
b/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
index aee6272..72aff88 100644
--- a/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
+++ b/tests/phpunit/Checker/RangeChecker/RangeCheckerTest.php
@@ -114,6 +114,18 @@
$this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
}
+ public function testRangeConstraintTimeWithinRangeToNow() {
+ $min = '+1960-01-01T00:00:00Z'; // TODO add leading zeroes as
in testRangeConstraintTimeWithinRange
+ $max = 'now';
+ $statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P1457' ), $this->timeValue ) );
+ $constraintParameters = array(
+ 'minimum_date' => $min,
+ 'maximum_date' => $max
+ );
+ $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
+ $this->assertEquals( 'compliance', $checkResult->getStatus(),
'check should comply' );
+ }
+
public function testRangeConstraintTimeTooSmall() {
$min = '+00000001975-01-01T00:00:00Z';
$max = '+00000001980-01-01T00:00:00Z';
--
To view, visit https://gerrit.wikimedia.org/r/351612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3fb31596c9c7a7447caa6bbfdb911b553da35daa
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: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits