diff --git a/model/fieldtypes/Year.php b/model/fieldtypes/Year.php old mode 100644 new mode 100755 index 1b98bc72f..5d31b5235 --- a/model/fieldtypes/Year.php +++ b/model/fieldtypes/Year.php @@ -39,7 +39,7 @@ class Year extends DBField { if (!$end) $end = 1900; $years = array(); for($i=$start;$i>=$end;$i--) { - $years[] = $i; + $years[$i] = $i; } return $years; } diff --git a/tests/model/YearTest.php b/tests/model/YearTest.php new file mode 100755 index 000000000..c659b7284 --- /dev/null +++ b/tests/model/YearTest.php @@ -0,0 +1,41 @@ +scaffoldFormField("YearTest"); + $this->assertEquals("DropdownField", get_class($field)); + + //This should be a list of years from the current one, counting down to 1900 + $source = $field->getSource(); + + $lastValue = end($source); + $lastKey = key($source); + + //Keys and values should be the same - and the last one should be 1900 + $this->assertEquals(1900, $lastValue); + $this->assertEquals(1900, $lastKey); + } + + public function testScaffoldFormFieldLast() { + $year = new Year(); + $field = $year->scaffoldFormField("YearTest"); + $source = $field->getSource(); + + //The first one should be the current year + $currentYear = (int)date('Y'); + $firstValue = reset($source); + $firstKey = key($source); + + $this->assertEquals($currentYear, $firstValue); + $this->assertEquals($currentYear, $firstKey); + + } +}