Merge pull request #2721 from froog/year_fix

FIX: Year.php getDefaultOptions now fixed, sets key as year. Also added YearTest unit test.
This commit is contained in:
Sean Harvey 2013-12-18 21:55:48 -08:00
commit 8ea8789ba7
2 changed files with 42 additions and 1 deletions

2
model/fieldtypes/Year.php Normal file → Executable file
View File

@ -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;
}

41
tests/model/YearTest.php Executable file
View File

@ -0,0 +1,41 @@
<?php
/**
* @package framework
* @subpackage tests
*/
class YearTest extends SapphireTest {
/**
* Test that the scaffolding form field works
*/
public function testScaffoldFormFieldFirst() {
$year = new Year();
$field = $year->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);
}
}