silverstripe-framework/tests/model/DBYearTest.php
Sam Minnee aeccb8b8e0 API: Move DBField subclasses into SilverStripe\Model\FieldType namespace
API: Deprecate SS_Datetime.

The DBField subclasses are have all been renamed to start with “DB” and
be in the SilverStripe\Model\FieldType namespace. To keep DataObject
definitions concise, the original short variations of their names are
preserved as service definitions. Most of the field generation code
doesn’t need to change, but where field classes are referenced directly,
changes will be needed.

SS_Datetime, which is commonly referenced outside the model system
itself, has been preserved as a subclass of DBDatetime. This has been
marked as deprecated and can be removed in SilverStripe 5.

A few places that referred to $db and $casting values weren’t using
the Injector to instantiate the relevant classes. This meant that the
remapping we have created as part of moving classes into a namespace
didn’t work.
2016-03-22 18:09:30 +13:00

45 lines
1.1 KiB
PHP
Executable File

<?php
use SilverStripe\Model\FieldType\DBYear;
/**
* @package framework
* @subpackage tests
*/
class DBYearTest extends SapphireTest {
/**
* Test that the scaffolding form field works
*/
public function testScaffoldFormFieldFirst() {
$year = new DBYear();
$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 DBYear();
$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);
}
}