From 94c19e349a5b73c8321f0d7d0372fc8218d14fa5 Mon Sep 17 00:00:00 2001 From: Daniel Pickering Date: Mon, 16 Dec 2013 03:20:34 +0000 Subject: [PATCH] FIX: Year.php getDefaultOptions now fixed, sets key as year. Also added YearTest unit test. --- model/fieldtypes/Year.php | 2 +- tests/model/YearTest.php | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) mode change 100644 => 100755 model/fieldtypes/Year.php create mode 100755 tests/model/YearTest.php 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); + + } +}