Skip to content

Commit

Permalink
Re-enable the day() tests for refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 25, 2014
1 parent 7a9c9e3 commit bead8ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
22 changes: 14 additions & 8 deletions src/View/Helper/FormHelper.php
Expand Up @@ -62,6 +62,13 @@ class FormHelper extends Helper {
'month' => array(), 'year' => array(), 'meridian' => array()
);

/**
* The various pickers that make up a datetime picker.
*
* @var array
*/
protected $_datetimeParts = ['year', 'month', 'day', 'hour', 'minute', 'second', 'meridian'];

/**
* Settings for the helper.
*
Expand Down Expand Up @@ -1839,20 +1846,20 @@ public function multiCheckbox($fieldName, $options, $attributes = []) {
/**
* Returns a SELECT element for days.
*
* ### Attributes:
* ### Options:
*
* - `empty` - If true, the empty select option is shown. If a string,
* that string is displayed as the empty element.
* - `value` The selected value of the input.
*
* @param string $fieldName Prefix name for the SELECT element
* @param array $attributes HTML attributes for the select element
* @param array $option Options & HTML attributes for the select element
* @return string A generated day select box.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::day
*/
public function day($fieldName = null, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);
public function day($fieldName = null, $options = []) {
$options += array('empty' => true, 'value' => null);
$options = $this->_dateTimeSelected('day', $fieldName, $options);

if (strlen($attributes['value']) > 2) {
$date = date_create($attributes['value']);
Expand All @@ -1863,7 +1870,7 @@ public function day($fieldName = null, $attributes = array()) {
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
}
return $this->select($fieldName . ".day", $this->_generateOptions('day'), $attributes);
return $this->select($fieldName . ".day", $this->_generateOptions('day'), $options);
}

/**
Expand Down Expand Up @@ -2177,8 +2184,7 @@ public function dateTime($fieldName, $options = array()) {
* @return array Converted options.
*/
protected function _datetimeOptions($options) {
$types = ['year', 'month', 'day', 'hour', 'minute', 'second', 'meridian'];
foreach ($types as $type) {
foreach ($this->_datetimeParts as $type) {
if (!isset($options[$type])) {
$options[$type] = [];
}
Expand Down
11 changes: 5 additions & 6 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -5511,12 +5511,11 @@ public function testMonth() {
* @return void
*/
public function testDay() {
$this->markTestIncomplete('Need to revisit once models work again.');
extract($this->dateRegex);

$result = $this->Form->day('Model.field', array('value' => false));
$expected = array(
array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
array('select' => array('name' => 'Model[field][day]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
Expand All @@ -5533,7 +5532,7 @@ public function testDay() {
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
$result = $this->Form->day('Model.field');
$expected = array(
array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
array('select' => array('name' => 'Model[field][day]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
Expand All @@ -5554,7 +5553,7 @@ public function testDay() {
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->day('Model.field', array('value' => '10'));
$expected = array(
array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
array('select' => array('name' => 'Model[field][day]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
Expand All @@ -5575,7 +5574,7 @@ public function testDay() {
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
$result = $this->Form->day('Model.field', array('value' => true));
$expected = array(
array('select' => array('name' => 'Model[field][day]', 'id' => 'ModelFieldDay')),
array('select' => array('name' => 'Model[field][day]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
Expand All @@ -5597,7 +5596,7 @@ public function testDay() {
$result = $this->Form->day('Project.release');

$expected = array(
array('select' => array('name' => 'Project[release][day]', 'id' => 'ProjectReleaseDay')),
array('select' => array('name' => 'Project[release][day]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
Expand Down

0 comments on commit bead8ab

Please sign in to comment.