From 80c355baa5c0ceb93bbd879b345ad49c3bca8ab6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 28 Sep 2012 22:01:53 -0400 Subject: [PATCH 1/5] Make minutes/hours wrap around correctly. Also account for times around midnight that roll over days/months/years. Fixes #3242 --- .../Test/Case/View/Helper/FormHelperTest.php | 37 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 17 +++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 5e822c7a0..9da345458 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2229,6 +2229,43 @@ class FormHelperTest extends CakeTestCase { $this->assertRegExp('##', $result); } +/** + * Test interval + selected near the hour roll over. + * + * @return void + */ + public function testTimeSelectedWithInterval() { + $result = $this->Form->input('Model.start_time', array( + 'timeFormat' => 24, + 'type' => 'time', + 'interval' => 15, + 'selected' => '15:57' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + + $result = $this->Form->input('Model.start_time', array( + 'timeFormat' => 24, + 'type' => 'time', + 'interval' => 15, + 'selected' => '23:57' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + + $result = $this->Form->input('Model.created', array( + 'timeFormat' => 24, + 'type' => 'datetime', + 'interval' => 15, + 'selected' => '2012-09-30 23:56' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + } + /** * test form->input() with datetime, date and time types * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index ad6bf80a0..9ffab2c1a 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2244,6 +2244,20 @@ class FormHelper extends AppHelper { $monthNames = $attributes['monthNames']; $attributes = array_diff_key($attributes, $defaults); + if (!empty($interval) && $interval > 1 && !empty($min)) { + $current = new DateTime(); + if ($year !== null) { + $current->setDate($year, $month, $day); + } + if ($hour !== null) { + $current->setTime($hour, $min); + } + $change = (round($min * (1 / $interval)) * $interval) - $min; + $current->modify($change > 0 ? "+$change minutes" : "$change minutes"); + $newTime = explode(' ', $current->format('Y m d H i a')); + list($year, $month, $day, $hour, $min, $meridian) = $newTime; + } + if (isset($attributes['id'])) { if (is_string($attributes['id'])) { // build out an array version @@ -2305,9 +2319,6 @@ class FormHelper extends AppHelper { } $opt = implode($separator, $selects); - if (!empty($interval) && $interval > 1 && !empty($min)) { - $min = round($min * (1 / $interval)) * $interval; - } $selectMinuteAttr['interval'] = $interval; switch ($timeFormat) { case '24': From 89ab0a2d066af668d8cbde870373537cb47a1fb9 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 30 Sep 2012 23:44:32 +0530 Subject: [PATCH 2/5] Fix docblock --- lib/Cake/View/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 9fa93d01c..c492aa4b8 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -903,7 +903,7 @@ class View extends Object { * Sandbox method to evaluate a template / view script in. * * @param string $viewFn Filename of the view - * @param array $___dataForView Data to include in rendered view. + * @param array $dataForView Data to include in rendered view. * If empty the current View::$viewVars will be used. * @return string Rendered output */ From 739b3b70f77eeede56b5cae86e1bbf0543ba61c6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 Sep 2012 20:17:50 -0400 Subject: [PATCH 3/5] Update text in routes.php to clarify when to remove core routes. --- app/Config/routes.php | 2 +- lib/Cake/Console/Templates/skel/Config/routes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Config/routes.php b/app/Config/routes.php index b3823779e..32151d27c 100644 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -38,7 +38,7 @@ CakePlugin::routes(); /** - * Load the CakePHP default routes. Remove this if you do not want to use + * Load the CakePHP default routes. Only remove this if you do not want to use * the built-in default routes. */ require CAKE . 'Config' . DS . 'routes.php'; diff --git a/lib/Cake/Console/Templates/skel/Config/routes.php b/lib/Cake/Console/Templates/skel/Config/routes.php index 82cd2dbe9..c68cc3e4a 100644 --- a/lib/Cake/Console/Templates/skel/Config/routes.php +++ b/lib/Cake/Console/Templates/skel/Config/routes.php @@ -38,7 +38,7 @@ CakePlugin::routes(); /** - * Load the CakePHP default routes. Remove this if you do not want to use + * Load the CakePHP default routes. Only remove this if you do not want to use * the built-in default routes. */ require CAKE . 'Config' . DS . 'routes.php'; From affb3192adb0084b55265f2a6758050ce9a300fd Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 Sep 2012 22:44:27 -0400 Subject: [PATCH 4/5] Fix issue where including elements + extending views fails. If you include an element before calling extend(), the parent view will be assumed to be an element instead of a view/layout. Fixes #3248 --- lib/Cake/Test/Case/View/ViewTest.php | 16 ++++++++++++++++ .../test_app/View/Posts/extend_with_element.ctp | 3 +++ lib/Cake/View/View.php | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 lib/Cake/Test/test_app/View/Posts/extend_with_element.ctp diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 33c0ceb90..2c4411df4 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1397,6 +1397,22 @@ TEXT; $this->View->render('extend_missing_element'); } +/** + * Test extend() preceeded by an element() + * + * @return void + */ + public function testExtendWithElementBeforeExtend() { + $this->View->layout = false; + $result = $this->View->render('extend_with_element'); + $expected = <<assertEquals($expected, $result); + } + /** * Test that setting arbitrary properties still works. * diff --git a/lib/Cake/Test/test_app/View/Posts/extend_with_element.ctp b/lib/Cake/Test/test_app/View/Posts/extend_with_element.ctp new file mode 100644 index 000000000..eda18b709 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Posts/extend_with_element.ctp @@ -0,0 +1,3 @@ +element('test_element'); ?> +extend('parent_view'); ?> +The view diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index c492aa4b8..aedddd90f 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -415,9 +415,15 @@ class View extends Object { $this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file))); } + $current = $this->_current; + $restore = $this->_currentType; + $this->_currentType = self::TYPE_ELEMENT; $element = $this->_render($file, array_merge($this->viewVars, $data)); + $this->_currentType = $restore; + $this->_current = $current; + if ($callbacks) { $this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element))); } From c94886a9882e69629a07ba892f0d32891005f3f9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 Sep 2012 22:51:19 -0400 Subject: [PATCH 5/5] Add missing import that causes tests to fail in isolation. --- lib/Cake/Test/Case/View/ViewTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 2c4411df4..75875349d 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -21,6 +21,7 @@ App::uses('View', 'View'); App::uses('Helper', 'View'); App::uses('Controller', 'Controller'); App::uses('CacheHelper', 'View/Helper'); +App::uses('HtmlHelper', 'View/Helper'); App::uses('ErrorHandler', 'Error');