Skip to content
Permalink
Browse files

Add tests for generating month selects.

  • Loading branch information...
markstory committed Jan 22, 2014
1 parent c8782a2 commit ed75f986b72fe371c33ed28d654842842582d050
Showing with 80 additions and 15 deletions.
  1. +14 −12 src/View/Input/DateTime.php
  2. +66 −3 tests/TestCase/View/Input/DateTimeTest.php
@@ -103,20 +103,22 @@ public function render(array $data) {
$templateOptions = [];
foreach ($this->_selects as $select) {
if ($data[$select] !== false) {
$method = $select . 'Select';
$data[$select]['name'] = $data['name'] . "[" . $select . "]";
$data[$select]['val'] = $selected[$select];
if (!isset($data[$select]['empty'])) {
$data[$select]['empty'] = $data['empty'];
}
if (!isset($data[$select]['disabled'])) {
$data[$select]['disabled'] = $data['disabled'];
}
if ($data[$select] === false || $data[$select] === null) {
$templateOptions[$select] = '';
unset($data[$select]);
continue;
}
$method = $select . 'Select';
$data[$select]['name'] = $data['name'] . "[" . $select . "]";
$data[$select]['val'] = $selected[$select];
$templateOptions[$select] = $this->{$method}($data[$select]);
if (!isset($data[$select]['empty'])) {
$data[$select]['empty'] = $data['empty'];
}
if (!isset($data[$select]['disabled'])) {
$data[$select]['disabled'] = $data['disabled'];
}
$templateOptions[$select] = $this->{$method}($data[$select]);
unset($data[$select]);
}
unset($data['name'], $data['empty'], $data['disabled'], $data['val']);
@@ -43,7 +43,7 @@ public function setUp() {
'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>',
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
'dateWidget' => '{{year}}-{{month}}-{{day}} {{hour}}:{{minute}}:{{second}}'
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}'
];
$this->templates = new StringTemplate($templates);
$this->selectBox = new SelectBox($this->templates);
@@ -251,12 +251,75 @@ public function testRenderYearWidgetValueOutOfBounds() {
$this->assertTags($result, $expected);
}
/**
* Test rendering the month widget
*
* @return void
*/
public function testRenderMonthWidget() {
$this->markTestIncomplete();
$now = new \DateTime('2010-09-01 12:00:00');
$result = $this->DateTime->render([
'name' => 'date',
'year' => false,
'day' => false,
'hour' => false,
'minute' => false,
'second' => false,
'val' => $now,
]);
$expected = [
'select' => ['name' => 'date[month]'],
['option' => ['value' => '01']], '01', '/option',
['option' => ['value' => '02']], '02', '/option',
['option' => ['value' => '03']], '03', '/option',
['option' => ['value' => '04']], '04', '/option',
['option' => ['value' => '05']], '05', '/option',
['option' => ['value' => '06']], '06', '/option',
['option' => ['value' => '07']], '07', '/option',
['option' => ['value' => '08']], '08', '/option',
['option' => ['value' => '09', 'selected' => 'selected']], '09', '/option',
['option' => ['value' => '10']], '10', '/option',
['option' => ['value' => '11']], '11', '/option',
['option' => ['value' => '12']], '12', '/option',
'/select',
];
$this->assertTags($result, $expected);
}
/**
* Test rendering month widget with names.
*
* @return void
*/
public function testRenderMonthWidgetWithNames() {
$this->markTestIncomplete();
$now = new \DateTime('2010-09-01 12:00:00');
$result = $this->DateTime->render([
'name' => 'date',
'year' => false,
'day' => false,
'hour' => false,
'minute' => false,
'second' => false,
'month' => ['data-foo' => 'test', 'names' => true],
'val' => $now,
]);
$expected = [
'select' => ['name' => 'date[month]', 'data-foo' => 'test'],
['option' => ['value' => '01']], 'January', '/option',
['option' => ['value' => '02']], 'February', '/option',
['option' => ['value' => '03']], 'March', '/option',
['option' => ['value' => '04']], 'April', '/option',
['option' => ['value' => '05']], 'May', '/option',
['option' => ['value' => '06']], 'June', '/option',
['option' => ['value' => '07']], 'July', '/option',
['option' => ['value' => '08']], 'August', '/option',
['option' => ['value' => '09', 'selected' => 'selected']], 'September', '/option',
['option' => ['value' => '10']], 'October', '/option',
['option' => ['value' => '11']], 'November', '/option',
['option' => ['value' => '12']], 'December', '/option',
'/select',
];
$this->assertTags($result, $expected);
}
public function testRenderDayWidget() {

0 comments on commit ed75f98

Please sign in to comment.
You can’t perform that action at this time.