Skip to content

Commit 8bbe2ad

Browse files
committed
Added test for month widget with no leadingZeroKey
Added a test case for rendering the month widget without leading zeros in the option value.
1 parent fa24100 commit 8bbe2ad

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/TestCase/View/Widget/DateTimeWidgetTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,49 @@ public function testRenderMonthWidget()
414414
$this->assertHtml($expected, $result);
415415
}
416416

417+
/**
418+
* Test rendering month widget with names and values without leading zeros.
419+
*
420+
* @return void
421+
*/
422+
public function testRenderMonthWidgetWithNamesNoLeadingZeros()
423+
{
424+
$now = new \DateTime('2010-12-01 12:00:00');
425+
$result = $this->DateTime->render([
426+
'name' => 'date',
427+
'year' => false,
428+
'day' => false,
429+
'hour' => false,
430+
'minute' => false,
431+
'second' => false,
432+
'month' => ['data-foo' => 'test', 'names' => true, 'leadingZeroKey' => false],
433+
'val' => $now,
434+
], $this->context);
435+
$expected = [
436+
'select' => ['name' => 'date[month]', 'data-foo' => 'test'],
437+
['option' => ['value' => '1']], 'January', '/option',
438+
['option' => ['value' => '2']], 'February', '/option',
439+
['option' => ['value' => '3']], 'March', '/option',
440+
['option' => ['value' => '4']], 'April', '/option',
441+
['option' => ['value' => '5']], 'May', '/option',
442+
['option' => ['value' => '6']], 'June', '/option',
443+
['option' => ['value' => '7']], 'July', '/option',
444+
['option' => ['value' => '8']], 'August', '/option',
445+
['option' => ['value' => '9']], 'September', '/option',
446+
['option' => ['value' => '10']], 'October', '/option',
447+
['option' => ['value' => '11']], 'November', '/option',
448+
['option' => ['value' => '12', 'selected' => 'selected']], 'December', '/option',
449+
'/select',
450+
];
451+
$this->assertHtml($expected, $result);
452+
$this->assertNotContains(
453+
'<option value="01">January</option>',
454+
$result,
455+
'no 01 in value'
456+
);
457+
458+
}
459+
417460
/**
418461
* Test rendering month widget with names.
419462
*

0 commit comments

Comments
 (0)