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

Change subject: Use NewItem+NewStatement in DiffWithinRangeCheckerTest
......................................................................

Use NewItem+NewStatement in DiffWithinRangeCheckerTest

This makes the tests much more readable (the difference between the
tests is no longer hidden in the JSON files), and also lets us get rid
of the entity JSON files (it looks like some of them were already
unused). It is also easier to add tests of this kind in the future.

The values, statements and builders are static and shared between tests
as a slight optimization. (The builders are immutable, each modification
method creates a new clone.)

(Note that the new test code is not always exactly equivalent to the old
one – it often uses different values – but it still tests the same
thing. The exception is testDiffWithinRangeConstraintTooSmall, which, as
far as I can tell, actually used to test a too-big difference instead of
the intended too-small difference.)

Bug: T168240
Change-Id: I1c39e90d76a6d274d89e203888c07daea270f70c
---
M tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
D tests/phpunit/Checker/RangeChecker/Q1.json
D tests/phpunit/Checker/RangeChecker/Q2.json
D tests/phpunit/Checker/RangeChecker/Q3.json
D tests/phpunit/Checker/RangeChecker/Q4.json
D tests/phpunit/Checker/RangeChecker/Q5.json
D tests/phpunit/Checker/RangeChecker/Q6.json
D tests/phpunit/Checker/RangeChecker/Q7.json
M tests/phpunit/ConstraintParameters.php
9 files changed, 135 insertions(+), 436 deletions(-)


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

diff --git a/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php 
b/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
index a8178dd..c8aa6a0 100644
--- a/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
+++ b/tests/phpunit/Checker/RangeChecker/DiffWithinRangeCheckerTest.php
@@ -2,13 +2,9 @@
 
 namespace WikibaseQuality\ConstraintReport\Test\RangeChecker;
 
+use DataValues\TimeValue;
 use Wikibase\DataModel\Snak\PropertyNoValueSnak;
 use Wikibase\DataModel\Statement\Statement;
-use Wikibase\DataModel\Snak\PropertyValueSnak;
-use DataValues\TimeValue;
-use DataValues\UnboundedQuantityValue;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\Repo\Tests\NewItem;
 use Wikibase\Repo\Tests\NewStatement;
 use WikibaseQuality\ConstraintReport\Constraint;
@@ -16,7 +12,6 @@
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\RangeCheckerHelper;
 use WikibaseQuality\ConstraintReport\Tests\ConstraintParameters;
 use WikibaseQuality\ConstraintReport\Tests\ResultAssertions;
-use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
 
 /**
  * @covers 
\WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\DiffWithinRangeChecker
@@ -34,24 +29,83 @@
        use ConstraintParameters, ResultAssertions;
 
        /**
-        * @var JsonFileEntityLookup
-        */
-       private $lookup;
-
-       /**
+        * A TimeValue for the year 1.
+        *
         * @var TimeValue
         */
-       private $timeValue;
+       private static $t0001;
+
+       /**
+        * A TimeValue for the year 1800.
+        *
+        * @var TimeValue
+        */
+       private static $t1800;
+
+       /**
+        * A TimeValue for the year 1900.
+        *
+        * @var TimeValue
+        */
+       private static $t1900;
+
+       /**
+        * A TimeValue for the year 1970.
+        *
+        * @var TimeValue
+        */
+       private static $t1970;
+
+       /**
+        * A TimeValue for the year 2000.
+        *
+        * @var TimeValue
+        */
+       private static $t2000;
+
+       /**
+        * A Statement for a $t1970 date of death (P570).
+        *
+        * @var Statement
+        */
+       private static $s1970;
+
+       /**
+        * Builder for an item with date of death 1970 ($s1970).
+        *
+        * @var NewItem
+        */
+       private static $i1970;
+
+       /**
+        * Constraint parameters specifying a range of [0, 150] (years) for 
date of birth (P569).
+        *
+        * @var array
+        */
+       private $dob0to150Parameters;
 
        /**
         * @var DiffWithinRangeChecker
         */
        private $checker;
 
+       public static function setUpBeforeClass() {
+               parent::setUpBeforeClass();
+               self::$t0001 = new TimeValue( '+00000000001-01-01T00:00:00Z', 
0, 0, 0, 11, 'http://www.wikidata.org/entity/Q1985727' );
+               self::$t1800 = new TimeValue( '+00000001800-01-01T00:00:00Z', 
0, 0, 0, 11, 'http://www.wikidata.org/entity/Q1985727' );
+               self::$t1900 = new TimeValue( '+00000001900-01-01T00:00:00Z', 
0, 0, 0, 11, 'http://www.wikidata.org/entity/Q1985727' );
+               self::$t1970 = new TimeValue( '+00000001970-01-01T00:00:00Z', 
0, 0, 0, 11, 'http://www.wikidata.org/entity/Q1985727' );
+               self::$t2000 = new TimeValue( '+00000002000-01-01T00:00:00Z', 
0, 0, 0, 11, 'http://www.wikidata.org/entity/Q1985727' );
+               self::$s1970 = NewStatement::forProperty( 'P570' )->withValue( 
self::$t1970 )->build();
+               self::$i1970 = NewItem::withId( 'Q1' )->andStatement( 
self::$s1970 );
+       }
+
        protected function setUp() {
                parent::setUp();
-               $this->lookup = new JsonFileEntityLookup( __DIR__ );
-               $this->timeValue = new TimeValue( 
'+00000001970-01-01T00:00:00Z', 0, 0, 0, 11, 
'http://www.wikidata.org/entity/Q1985727' );
+               $this->dob0to150Parameters = array_merge(
+                       $this->propertyParameter( 'P569' ),
+                       $this->rangeParameter( 'quantity', 0, 150 )
+               );
                $this->checker = new DiffWithinRangeChecker(
                        $this->getConstraintParameterParser(),
                        new RangeCheckerHelper( $this->getDefaultConfig() ),
@@ -60,114 +114,116 @@
        }
 
        public function testDiffWithinRangeConstraintWithinRange() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
-               $constraintParameters = [
-                       'property' => 'P569',
-                       'minimum_quantity' => 0,
-                       'maximum_quantity' => 150
-               ];
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t1900 ) )
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertCompliance( $checkResult );
        }
 
        public function testDiffWithinRangeConstraintTooSmall() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
-               $constraintParameters = [
-                       'property' => 'P569',
-                       'minimum_quantity' => 50,
-                       'maximum_quantity' => 150
-               ];
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t2000 ) )
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range' );
        }
 
        public function testDiffWithinRangeConstraintTooBig() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q6' ) );
-               $constraintParameters = [
-                       'property' => 'P569',
-                       'minimum_quantity' => 0,
-                       'maximum_quantity' => 150
-               ];
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t1800 ) )
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range' );
        }
 
        public function testDiffWithinRangeConstraintWrongTypeOfProperty() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q7' ) );
-               $constraintParameters = [
-                       'property' => 'P569',
-                       'minimum_quantity' => 1,
-                       'maximum_quantity' => 100
-               ];
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( '1900' ) )
+                       ->build();
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range-must-have-equal-types' );
        }
 
        public function testDiffWithinRangeConstraintNoValueSnak() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
+               $entity = self::$i1970->build();
                $statement = new Statement( new PropertyNoValueSnak( 1 ) );
-               $constraintParameters = [
-                       'property' => 'P1000',
-                       'minimum_quantity' => 0,
-                       'maximum_quantity' => 150
-               ];
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $constraint = $this->getConstraintMock( 
$this->dob0to150Parameters );
+
+               $checkResult = $this->checker->checkConstraint( $statement, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-value-needed' );
        }
 
        public function testDiffWithinRangeConstraintLeftOpenWithinRange() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t1970 ) )
+                       ->build();
                $constraintParameters = array_merge(
                        $this->propertyParameter( 'P569' ),
-                       $this->rangeParameter( 'quantity', null, 
UnboundedQuantityValue::newFromNumber( 100 ) )
+                       $this->rangeParameter( 'quantity', null, 150 )
                );
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $constraint = $this->getConstraintMock( $constraintParameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertCompliance( $checkResult );
        }
 
        public function testDiffWithinRangeConstraintLeftOpenTooBig() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t0001 ) )
+                       ->build();
                $constraintParameters = array_merge(
                        $this->propertyParameter( 'P569' ),
-                       $this->rangeParameter( 'quantity', null, 
UnboundedQuantityValue::newFromNumber( 0 ) )
+                       $this->rangeParameter( 'quantity', null, 150 )
                );
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $constraint = $this->getConstraintMock( $constraintParameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range-leftopen' );
        }
 
        public function testDiffWithinRangeConstraintRightOpenWithinRange() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t0001 ) )
+                       ->build();
                $constraintParameters = array_merge(
                        $this->propertyParameter( 'P569' ),
-                       $this->rangeParameter( 'quantity', 
UnboundedQuantityValue::newFromNumber( 0 ), null )
+                       $this->rangeParameter( 'quantity', 0, null )
                );
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $constraint = $this->getConstraintMock( $constraintParameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertCompliance( $checkResult );
        }
 
        public function testDiffWithinRangeConstraintRightOpenTooSmall() {
-               $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
+               $entity = self::$i1970
+                       ->andStatement( NewStatement::forProperty( 'P569' 
)->withValue( self::$t2000 ) )
+                       ->build();
                $constraintParameters = array_merge(
                        $this->propertyParameter( 'P569' ),
-                       $this->rangeParameter( 'quantity', 
UnboundedQuantityValue::newFromNumber( 100 ), null )
+                       $this->rangeParameter( 'quantity', 0, null )
                );
-               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P570' ), $this->timeValue ) );
+               $constraint = $this->getConstraintMock( $constraintParameters );
 
-               $checkResult = $this->checker->checkConstraint( $statement, 
$this->getConstraintMock( $constraintParameters ), $entity );
+               $checkResult = $this->checker->checkConstraint( self::$s1970, 
$constraint, $entity );
+
                $this->assertViolation( $checkResult, 
'wbqc-violation-message-diff-within-range-rightopen' );
        }
 
diff --git a/tests/phpunit/Checker/RangeChecker/Q1.json 
b/tests/phpunit/Checker/RangeChecker/Q1.json
deleted file mode 100644
index 54902bc..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q1.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
-  "pageid": 2693,
-  "ns": 120,
-  "title": "Item:Q1",
-  "lastrevid": 2705,
-  "modified": "2015-03-05T10:58:31Z",
-  "id": "Q1",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemRange"
-    }
-  },
-  "claims": {
-    "P1457": [
-      {
-        "id": "Q1001$a7bd1dae-43f7-dfe2-b3ce-fed6aaba6036",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P1457",
-          "datatype": "quantity",
-          "datavalue": {
-            "value": {
-              "amount": "+31415926536",
-              "unit": "1",
-              "upperBound": "+31415926537",
-              "lowerBound": "+31415926535"
-            },
-            "type": "quantity"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q2.json 
b/tests/phpunit/Checker/RangeChecker/Q2.json
deleted file mode 100644
index 4b3d307..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q2.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
-  "pageid": 2694,
-  "ns": 120,
-  "title": "Item:Q2",
-  "lastrevid": 2707,
-  "modified": "2015-03-05T11:00:55Z",
-  "id": "Q2",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemRange"
-    }
-  },
-  "claims": {
-    "P1457": [
-      {
-        "id": "Q1002$077bb557-4fb0-8703-e13f-72543ff6fbdf",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P1457",
-          "datatype": "quantity",
-          "datavalue": {
-            "value": {
-              "amount": "+42",
-              "unit": "1",
-              "upperBound": "+43",
-              "lowerBound": "+41"
-            },
-            "type": "quantity"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q3.json 
b/tests/phpunit/Checker/RangeChecker/Q3.json
deleted file mode 100644
index cea51a3..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q3.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
-  "pageid": 2695,
-  "ns": 120,
-  "title": "Item:Q3",
-  "lastrevid": 2709,
-  "modified": "2015-03-05T11:02:07Z",
-  "id": "Q3",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemRange"
-    }
-  },
-  "claims": {
-    "P1457": [
-      {
-        "id": "Q1003$7d1f2c41-4975-57f1-0abf-aba740eaf8cb",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P1457",
-          "datatype": "quantity",
-          "datavalue": {
-            "value": {
-              "amount": "+3.141592",
-              "unit": "1",
-              "upperBound": "+3.141593",
-              "lowerBound": "+3.141591"
-            },
-            "type": "quantity"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q4.json 
b/tests/phpunit/Checker/RangeChecker/Q4.json
deleted file mode 100644
index 38c4e1b..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q4.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
-  "pageid": 2696,
-  "ns": 120,
-  "title": "Item:Q4",
-  "lastrevid": 2713,
-  "modified": "2015-03-05T11:11:06Z",
-  "id": "Q4",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemDiffWithinRange"
-    }
-  },
-  "claims": {
-    "P570": [
-      {
-        "id": "Q1004$99f3a85d-4dad-09de-6e50-d67a520906c2",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P570",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001970-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ],
-    "P569": [
-      {
-        "id": "Q1004$e13a936e-4441-ae27-2359-03411523ea66",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P569",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001900-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q5.json 
b/tests/phpunit/Checker/RangeChecker/Q5.json
deleted file mode 100644
index 60fce4b..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q5.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
-  "pageid": 2697,
-  "ns": 120,
-  "title": "Item:Q5",
-  "lastrevid": 2720,
-  "modified": "2015-03-05T11:34:33Z",
-  "id": "Q5",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemDiffWithinRange"
-    }
-  },
-  "claims": {
-    "P570": [
-      {
-        "id": "Q1005$a67f349c-4d73-154e-2783-b150944000c6",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P570",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001970-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ],
-    "P569": [
-      {
-        "id": "Q1005$3d57a0d3-4f91-85cf-1958-b6fc8ce822bf",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P569",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000000001-01-00T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 10,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q6.json 
b/tests/phpunit/Checker/RangeChecker/Q6.json
deleted file mode 100644
index 1c90dea..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q6.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
-  "pageid": 2699,
-  "ns": 120,
-  "title": "Item:Q6",
-  "lastrevid": 2719,
-  "modified": "2015-03-05T11:33:21Z",
-  "id": "Q6",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemDiffWithinRange"
-    }
-  },
-  "claims": {
-    "P570": [
-      {
-        "id": "Q1007$07e366b9-485d-c662-9bd1-00557cccb839",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P570",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001970-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ],
-    "P569": [
-      {
-        "id": "Q1007$877edbc0-46ab-95b0-f17b-9c0265b5faa3",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P569",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001800-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Checker/RangeChecker/Q7.json 
b/tests/phpunit/Checker/RangeChecker/Q7.json
deleted file mode 100644
index 4b28d13..0000000
--- a/tests/phpunit/Checker/RangeChecker/Q7.json
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-  "pageid": 2699,
-  "ns": 120,
-  "title": "Item:Q6",
-  "lastrevid": 2719,
-  "modified": "2015-03-05T11:33:21Z",
-  "id": "Q6",
-  "type": "item",
-  "labels": {
-    "en": {
-      "language": "en",
-      "value": "TestItemDiffWithinRange"
-    }
-  },
-  "claims": {
-    "P570": [
-      {
-        "id": "Q1007$07e366b9-485d-c662-9bd1-00557cccb839",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P570",
-          "datatype": "time",
-          "datavalue": {
-            "value": {
-              "time": "+00000001970-01-01T00:00:00Z",
-              "timezone": 0,
-              "before": 0,
-              "after": 0,
-              "precision": 11,
-              "calendarmodel": "http://www.wikidata.org/entity/Q1985727";
-            },
-            "type": "time"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ],
-    "P569": [
-      {
-        "id": "Q1007$877edbc0-46ab-95b0-f17b-9c0265b5faa3",
-        "mainsnak": {
-          "snaktype": "value",
-          "property": "P569",
-          "datatype": "quantity",
-          "datavalue": {
-            "value": {
-              "amount": "+31415926536",
-              "unit": "1",
-              "upperBound": "+31415926537",
-              "lowerBound": "+31415926535"
-            },
-            "type": "quantity"
-          }
-        },
-        "type": "statement",
-        "rank": "normal"
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/tests/phpunit/ConstraintParameters.php 
b/tests/phpunit/ConstraintParameters.php
index 72ccff0..c527d10 100644
--- a/tests/phpunit/ConstraintParameters.php
+++ b/tests/phpunit/ConstraintParameters.php
@@ -4,6 +4,7 @@
 
 use DataValues\DataValue;
 use DataValues\StringValue;
+use DataValues\UnboundedQuantityValue;
 use Serializers\Serializer;
 use ValueFormatters\ValueFormatter;
 use Wikibase\DataModel\Entity\EntityIdValue;
@@ -114,11 +115,11 @@
 
        /**
         * @param string $type 'quantity' or 'time'
-        * @param DataValue|null $min lower boundary, or null to signify no 
lower boundary
-        * @param DataValue|null $max upper boundary, or null to signfiy no 
upper boundary
+        * @param DataValue|int|float|null $min lower boundary, or null to 
signify no lower boundary
+        * @param DataValue|int|float|null $max upper boundary, or null to 
signfiy no upper boundary
         * @return array
         */
-       public function rangeParameter( $type, DataValue $min = null, DataValue 
$max = null ) {
+       public function rangeParameter( $type, $min, $max ) {
                $configKey = $type === 'quantity' ? 'Quantity' : 'Date';
                $config = $this->getDefaultConfig();
                $minimumId = $config->get( 'WBQualityConstraintsMinimum' . 
$configKey . 'Id' );
@@ -126,11 +127,17 @@
                if ( $min === null ) {
                        $minimumSnak = new PropertyNoValueSnak( new PropertyId( 
$minimumId ) );
                } else {
+                       if ( is_numeric( $min ) ) {
+                               $min = UnboundedQuantityValue::newFromNumber( 
$min );
+                       }
                        $minimumSnak = new PropertyValueSnak( new PropertyId( 
$minimumId ), $min );
                }
                if ( $max === null ) {
                        $maximumSnak = new PropertyNoValueSnak( new PropertyId( 
$maximumId ) );
                } else {
+                       if ( is_numeric( $max ) ) {
+                               $max = UnboundedQuantityValue::newFromNumber( 
$max );
+                       }
                        $maximumSnak = new PropertyValueSnak( new PropertyId( 
$maximumId ), $max );
                }
                $snakSerializer = $this->getSnakSerializer();

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

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