Permalink
Browse files

Allow names option to overwrite options for month picker.

This is a feature FormHelper currently offers, maintain it in the new
implementation.
  • Loading branch information...
1 parent a15e091 commit 6987857625049a931c3d0797efe38d20435c53b5 @markstory markstory committed Feb 23, 2014
Showing with 30 additions and 0 deletions.
  1. +2 −0 src/View/Widget/DateTime.php
  2. +28 −0 tests/TestCase/View/Widget/DateTimeTest.php
@@ -302,6 +302,8 @@ protected function _monthSelect($options = []) {
if (empty($options['options'])) {
if ($options['names'] === true) {
$options['options'] = $this->_getMonthNames($options['leadingZeroKey']);
+ } elseif (is_array($options['names'])) {
+ $options['options'] = $options['names'];
} else {
$options['options'] = $this->_generateNumbers(1, 12, $options);
}
@@ -394,6 +394,34 @@ public function testRenderMonthWidgetWithNames() {
}
/**
+ * Test rendering month widget with custom names.
+ *
+ * @return void
+ */
+ public function testRenderMonthWidgetWithCustomNames() {
+ $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' => [
+ 'names' => ['01' => 'Jan', '02' => 'Feb']
+ ],
+ 'val' => $now,
+ ]);
+ $expected = [
+ 'select' => ['name' => 'date[month]'],
+ ['option' => ['value' => '01']], 'Jan', '/option',
+ ['option' => ['value' => '02']], 'Feb', '/option',
+ '/select',
+ ];
+ $this->assertTags($result, $expected);
+ }
+
+/**
* Test rendering the day widget.
*
* @return void

0 comments on commit 6987857

Please sign in to comment.