Complete coverage of Xml::DateMenu()
authorAntoine Musso <hashar@users.mediawiki.org>
Sun, 6 Feb 2011 22:10:48 +0000 (22:10 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sun, 6 Feb 2011 22:10:48 +0000 (22:10 +0000)
r81605 was not hitting all possible conditional tests. Verified with:

php phpunit.php --configuration suite.xml \
  --coverage-html /tmp/datecover \
   --filter DateMenu

Tests:
PHPUnit 3.5.10 by Sebastian Bergmann.
.
Time: 3 seconds, Memory: 27.50Mb
OK (1 test, 5 assertions)

tests/phpunit/includes/XmlTest.php

index 080d887..4086ce6 100644 (file)
@@ -74,6 +74,16 @@ class XmlTest extends MediaWikiTestCase {
        }
 
        public function testDateMenu( ) {
+               $curYear   = intval(gmdate('Y'));
+               $prevYear  = $curYear - 1;
+
+               $curMonth  = intval(gmdate('n'));
+               $prevMonth = $curMonth - 1;
+               if( $prevMonth == 0 ) { $prevMonth = 12; }
+               $nextMonth = $curMonth + 1;
+               if( $nextMonth == 13 ) { $nextMonth = 1; }
+
+
                $this->assertEquals(
                        '<label for="year">From year (and earlier):</label> <input name="year" size="4" value="2011" id="year" maxlength="4" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>
 <option value="1">January</option>
@@ -108,6 +118,35 @@ class XmlTest extends MediaWikiTestCase {
                        Xml::dateMenu( 2011, -1),
                        "Date menu with negative month for 'All'"
                );
+               $this->assertEquals(
+                       Xml::dateMenu( $curYear, $curMonth ),
+                       Xml::dateMenu( ''      , $curMonth ),
+                       "Date menu year is the current one when not specified"
+               );
+               $this->assertEquals(
+                       Xml::dateMenu( $prevYear, $nextMonth ),
+                       Xml::dateMenu( '', $nextMonth ),
+                       "Date menu next month is 11 months ago"
+               );
+
+               # FIXME: please note there is no year there!
+               $this->assertEquals(
+                       '<label for="year">From year (and earlier):</label> <input name="year" size="4" value="" id="year" maxlength="4" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>
+<option value="1">January</option>
+<option value="2">February</option>
+<option value="3">March</option>
+<option value="4">April</option>
+<option value="5">May</option>
+<option value="6">June</option>
+<option value="7">July</option>
+<option value="8">August</option>
+<option value="9">September</option>
+<option value="10">October</option>
+<option value="11">November</option>
+<option value="12">December</option></select>',
+                       Xml::dateMenu( '', ''),
+                       "Date menu with neither year or month"
+               );
        }
 
        #