Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312214

Change subject: Cleanup DateTimeValueCleanerTest
......................................................................

Cleanup DateTimeValueCleanerTest

In this patch I'm not touching any of the test cases. This is pure
refactoring to make the code easier to read and easier to work on in
future patches.

Bug: T146356
Change-Id: Ibee47dd1c9b1eaf2a4eaa94225d0acfa2476cc60
---
M repo/tests/phpunit/includes/Rdf/DateTimeValueCleanerTest.php
1 file changed, 66 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/14/312214/1

diff --git a/repo/tests/phpunit/includes/Rdf/DateTimeValueCleanerTest.php 
b/repo/tests/phpunit/includes/Rdf/DateTimeValueCleanerTest.php
index 6baa999..ec56642 100644
--- a/repo/tests/phpunit/includes/Rdf/DateTimeValueCleanerTest.php
+++ b/repo/tests/phpunit/includes/Rdf/DateTimeValueCleanerTest.php
@@ -20,91 +20,106 @@
 class DateTimeValueCleanerTest extends \PHPUnit_Framework_TestCase {
 
        public function getDates() {
-               return array(
+               $greg = TimeValue::CALENDAR_GREGORIAN;
+               $jul = TimeValue::CALENDAR_JULIAN;
+               $year1m = TimeValue::PRECISION_YEAR1M;
+               $year = TimeValue::PRECISION_YEAR;
+               $month = TimeValue::PRECISION_MONTH;
+
+               return [
                        // Gregorian
-                       array( "+00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985727";, "2014-01-05T12:34:56Z" ),
-                       array( "+00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985727";, "2014-01-01T12:34:56Z",
-                                       TimeValue::PRECISION_YEAR ),
-                       array( "-00000000200-00-00T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "-0200-01-01T00:00:00Z" ),
-                       array( "+00000000200-00-00T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "0200-01-01T00:00:00Z" ),
-                       array( "+00000000200-00-00T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "0200-01-01T00:00:00Z",
-                                       TimeValue::PRECISION_YEAR ),
-                       array( "+02000000200-00-00T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "2000000200-01-01T00:00:00Z" ),
-                       array( "+92000000200-05-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "92000000200-01-01T00:00:00Z",
-                                       TimeValue::PRECISION_Ma ),
-                       array( "+92000000200-05-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "92000000200-05-31T00:00:00Z" ),
-                       array( "-02000000200-05-22T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "-2000000200-05-22T00:00:00Z" ),
-                       array( "-02000000200-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "-2000000200-02-29T00:00:00Z" ),
-                       array( "+00000000200-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "0200-02-28T00:00:00Z" ),
-                       array( "+00000000204-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "0204-02-29T00:00:00Z" ),
-                       array( "+00000002204-04-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "2204-04-30T00:00:00Z" ),
-                       array( "+00000002204-04-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, "2204-04-01T00:00:00Z",
-                                       TimeValue::PRECISION_MONTH ),
-                       array( "+00000000000-04-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, null ),
-                       array( "-00000000000-04-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";, null ),
+                       [ '+00000002014-01-05T12:34:56Z', $greg, 
'2014-01-05T12:34:56Z' ],
+                       [ '+00000002014-01-05T12:34:56Z', $greg, 
'2014-01-01T12:34:56Z', $year ],
+                       [ '-00000000200-00-00T00:00:00Z', $greg, 
'-0200-01-01T00:00:00Z' ],
+                       [ '+00000000200-00-00T00:00:00Z', $greg, 
'0200-01-01T00:00:00Z' ],
+                       [ '+00000000200-00-00T00:00:00Z', $greg, 
'0200-01-01T00:00:00Z', $year ],
+                       [ '+02000000200-00-00T00:00:00Z', $greg, 
'2000000200-01-01T00:00:00Z' ],
+                       [ '+92000000200-05-31T00:00:00Z', $greg, 
'92000000200-01-01T00:00:00Z', $year1m ],
+                       [ '+92000000200-05-31T00:00:00Z', $greg, 
'92000000200-05-31T00:00:00Z' ],
+                       [ '-02000000200-05-22T00:00:00Z', $greg, 
'-2000000200-05-22T00:00:00Z' ],
+                       [ '-02000000200-02-31T00:00:00Z', $greg, 
'-2000000200-02-29T00:00:00Z' ],
+                       [ '+00000000200-02-31T00:00:00Z', $greg, 
'0200-02-28T00:00:00Z' ],
+                       [ '+00000000204-02-31T00:00:00Z', $greg, 
'0204-02-29T00:00:00Z' ],
+                       [ '+00000002204-04-31T00:00:00Z', $greg, 
'2204-04-30T00:00:00Z' ],
+                       [ '+00000002204-04-31T00:00:00Z', $greg, 
'2204-04-01T00:00:00Z', $month ],
+                       [ '+00000000000-04-31T00:00:00Z', $greg, null ],
+                       [ '-00000000000-04-31T00:00:00Z', $greg, null ],
+
                        // Julian
-                       array( "+00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985786";, "2014-01-18T12:34:56Z" ),
-                       array( "-00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985786";, "-2015-12-19T12:34:56Z" ),
-                       array( "+00000000200-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985786";, "0200-03-02T00:00:00Z" ),
-                       array( "+00000000204-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985786";, "0204-03-02T00:00:00Z" ),
-                       array( "-02000000204-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985786";, null ),
+                       [ '+00000002014-01-05T12:34:56Z', $jul, 
'2014-01-18T12:34:56Z' ],
+                       [ '-00000002014-01-05T12:34:56Z', $jul, 
'-2015-12-19T12:34:56Z' ],
+                       [ '+00000000200-02-31T00:00:00Z', $jul, 
'0200-03-02T00:00:00Z' ],
+                       [ '+00000000204-02-31T00:00:00Z', $jul, 
'0204-03-02T00:00:00Z' ],
+                       [ '-02000000204-02-31T00:00:00Z', $jul, null ],
+
                        // Neither
-                       array( "+00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q42";, null ),
-               );
+                       [ '+00000002014-01-05T12:34:56Z', 
'http://www.wikidata.org/entity/Q42', null ],
+               ];
        }
 
        public function getDatesXSD11() {
-               return array(
+               $greg = TimeValue::CALENDAR_GREGORIAN;
+               $jul = TimeValue::CALENDAR_JULIAN;
+               $year10 = TimeValue::PRECISION_YEAR10;
+               $year = TimeValue::PRECISION_YEAR;
+               $day = TimeValue::PRECISION_DAY;
+
+               return [
                        // Gregorian
-                       array( "-00000000200-00-00T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";,
-                               "-0199-01-01T00:00:00Z" ),
-                       array( "-02000000200-05-22T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";,
-                               "-2000000200-01-01T00:00:00Z", 
TimeValue::PRECISION_10a ),
-                       array( "-02000000200-02-31T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985727";,
-                               "-2000000200-01-01T00:00:00Z", 
TimeValue::PRECISION_10a ),
+                       [ '-00000000200-00-00T00:00:00Z', $greg, 
'-0199-01-01T00:00:00Z' ],
+                       [ '-02000000200-05-22T00:00:00Z', $greg, 
'-2000000200-01-01T00:00:00Z', $year10 ],
+                       [ '-02000000200-02-31T00:00:00Z', $greg, 
'-2000000200-01-01T00:00:00Z', $year10 ],
+
                        // Julian
-                       array( "-00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985786";,
-                               "-2014-12-19T12:34:56Z" ),
-                       array( "-00000002014-01-05T12:34:56Z", 
"http://www.wikidata.org/entity/Q1985786";,
-                               "-2013-01-01T12:34:56Z", 
TimeValue::PRECISION_YEAR ),
-                       array( "-0100-07-12T00:00:00Z", 
"http://www.wikidata.org/entity/Q1985786";,
-                               "-0099-07-10T00:00:00Z", 
TimeValue::PRECISION_DAY )
-               );
+                       [ '-00000002014-01-05T12:34:56Z', $jul, 
'-2014-12-19T12:34:56Z' ],
+                       [ '-00000002014-01-05T12:34:56Z', $jul, 
'-2013-01-01T12:34:56Z', $year ],
+                       [ '-0100-07-12T00:00:00Z', $jul, 
'-0099-07-10T00:00:00Z', $day ],
+               ];
        }
 
        /**
         * @dataProvider getDates
         */
-       public function testCleanDate( $date, $calendar, $expected, $precision 
= TimeValue::PRECISION_SECOND ) {
+       public function testCleanDate(
+               $date,
+               $calendar,
+               $expected,
+               $precision = TimeValue::PRECISION_SECOND
+       ) {
                $julianCleaner = new JulianDateTimeValueCleaner( false );
                $gregorianCleaner = new DateTimeValueCleaner( false );
 
                $value = new TimeValue( $date, 0, 0, 0, $precision, $calendar );
 
                $result = $julianCleaner->getStandardValue( $value );
-               $this->assertEquals( $expected, $result );
+               $this->assertSame( $expected, $result );
 
-               if ( $calendar == TimeValue::CALENDAR_GREGORIAN ) {
+               if ( $calendar === TimeValue::CALENDAR_GREGORIAN ) {
                        $result = $gregorianCleaner->getStandardValue( $value );
-                       $this->assertEquals( $expected, $result );
+                       $this->assertSame( $expected, $result );
                }
        }
 
        /**
         * @dataProvider getDatesXSD11
         */
-       public function testCleanDateXSD11( $date, $calendar, $expected, 
$precision = TimeValue::PRECISION_SECOND ) {
+       public function testCleanDateXSD11(
+               $date,
+               $calendar,
+               $expected,
+               $precision = TimeValue::PRECISION_SECOND
+       ) {
                $julianCleaner = new JulianDateTimeValueCleaner();
-               $gregorianCleaner = new DateTimeValueCleaner( true );
+               $gregorianCleaner = new DateTimeValueCleaner();
 
                $value = new TimeValue( $date, 0, 0, 0, $precision, $calendar );
 
                $result = $julianCleaner->getStandardValue( $value );
-               $this->assertEquals( $expected, $result );
+               $this->assertSame( $expected, $result );
 
-               if ( $calendar == TimeValue::CALENDAR_GREGORIAN ) {
+               if ( $calendar === TimeValue::CALENDAR_GREGORIAN ) {
                        $result = $gregorianCleaner->getStandardValue( $value );
-                       $this->assertEquals( $expected, $result );
+                       $this->assertSame( $expected, $result );
                }
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibee47dd1c9b1eaf2a4eaa94225d0acfa2476cc60
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to