'',
'option' => '',
'optgroup' => '',
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}'
];
$this->templates = new StringTemplate($templates);
$this->context = $this->getMockBuilder('Cake\View\Form\ContextInterface')->getMock();
$this->selectBox = new SelectBoxWidget($this->templates);
$this->DateTime = new DateTimeWidget($this->templates, $this->selectBox);
}
/**
* Data provider for testing various types of invalid selected values.
*
* @return array
*/
public static function invalidSelectedValuesProvider()
{
return [
'false' => [false],
'true' => [true],
'string' => ['Bag of poop'],
'array' => [[
'derp' => 'hurt'
]]
];
}
/**
* test rendering selected values.
*
* @dataProvider invalidSelectedValuesProvider
* @return void
*/
public function testRenderSelectedInvalid($selected)
{
$result = $this->DateTime->render(['val' => $selected], $this->context);
$now = new \DateTime();
$format = '';
$this->assertContains(
sprintf($format, $now->format('Y'), $now->format('Y')),
$result
);
}
/**
* test rendering empty selected.
*
* @return void
*/
public function testRenderSelectedEmpty()
{
$result = $this->DateTime->render([
'val' => '',
'year' => ['empty' => true],
'month' => ['empty' => true],
'day' => ['empty' => true],
'hour' => ['empty' => true],
'minute' => ['empty' => true],
], $this->context);
$this->assertContains('', $result);
$this->assertNotRegExp('/value="\d+" selected="selected"/', $result);
$result = $this->DateTime->render([
'val' => ['year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''],
'year' => ['empty' => true],
'month' => ['empty' => true],
'day' => ['empty' => true],
'hour' => ['empty' => true],
'minute' => ['empty' => true],
], $this->context);
$this->assertContains('', $result);
$this->assertNotRegExp('/value="\d+" selected="selected"/', $result);
}
/**
* Test empty with custom values.
*
* @return void
*/
public function testRenderEmptyCustom()
{
$result = $this->DateTime->render([
'val' => '',
'year' => [
'empty' => ['nope' => '(choose one)'],
]
], $this->context);
$this->assertContains('', $result);
$this->assertNotContains('