2013-12-16 04:20:34 +01:00
|
|
|
<?php
|
2015-08-30 07:02:55 +02:00
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\FieldType\DBYear;
|
|
|
|
|
2015-08-30 07:02:55 +02:00
|
|
|
|
2013-12-16 04:20:34 +01:00
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2015-08-30 07:02:55 +02:00
|
|
|
class DBYearTest extends SapphireTest {
|
2013-12-16 04:20:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the scaffolding form field works
|
|
|
|
*/
|
|
|
|
public function testScaffoldFormFieldFirst() {
|
2015-08-30 07:02:55 +02:00
|
|
|
$year = new DBYear();
|
2013-12-16 04:20:34 +01:00
|
|
|
$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() {
|
2015-08-30 07:02:55 +02:00
|
|
|
$year = new DBYear();
|
2013-12-16 04:20:34 +01:00
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|