Permalink
Browse files

Merge branch 'master' into 2.3

Conflicts:
	lib/Cake/View/View.php
  • Loading branch information...
2 parents 47708c5 + c94886a commit a3ae58da09fa85f15bb0fd9e3b14f745a2ae6e96 @markstory markstory committed Oct 2, 2012
@@ -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';
@@ -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';
@@ -2248,6 +2248,43 @@ public function testInputTime() {
}
/**
+ * 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('<option value="16" selected="selected">16</option>', $result);
+ $this->assertContains('<option value="00" selected="selected">00</option>', $result);
+
+ $result = $this->Form->input('Model.start_time', array(
+ 'timeFormat' => 24,
+ 'type' => 'time',
+ 'interval' => 15,
+ 'selected' => '23:57'
+ ));
+ $this->assertContains('<option value="00" selected="selected">0</option>', $result);
+ $this->assertContains('<option value="00" selected="selected">00</option>', $result);
+
+ $result = $this->Form->input('Model.created', array(
+ 'timeFormat' => 24,
+ 'type' => 'datetime',
+ 'interval' => 15,
+ 'selected' => '2012-09-30 23:56'
+ ));
+ $this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
+ $this->assertContains('<option value="10" selected="selected">October</option>', $result);
+ $this->assertContains('<option value="01" selected="selected">1</option>', $result);
+ $this->assertContains('<option value="00" selected="selected">0</option>', $result);
+ $this->assertContains('<option value="00" selected="selected">00</option>', $result);
+ }
+
+/**
* test form->input() with datetime, date and time types
*
* @return void
@@ -21,6 +21,7 @@
App::uses('Helper', 'View');
App::uses('Controller', 'Controller');
App::uses('CacheHelper', 'View/Helper');
+App::uses('HtmlHelper', 'View/Helper');
App::uses('ErrorHandler', 'Error');
@@ -1422,6 +1423,22 @@ public function testExtendMissingElement() {
}
/**
+ * Test extend() preceeded by an element()
+ *
+ * @return void
+ */
+ public function testExtendWithElementBeforeExtend() {
+ $this->View->layout = false;
+ $result = $this->View->render('extend_with_element');
+ $expected = <<<TEXT
+Parent View.
+this is the test elementThe view
+
+TEXT;
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* Test that setting arbitrary properties still works.
*
* @return void
@@ -1485,4 +1502,4 @@ public function testBlockDefaultValue() {
$result = $this->View->fetch('title', $default);
$this->assertEquals($expected, $result);
}
-}
+}
@@ -0,0 +1,3 @@
+<?php echo $this->element('test_element'); ?>
+<?php $this->extend('parent_view'); ?>
+The view
@@ -2261,6 +2261,20 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
$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
@@ -2322,9 +2336,6 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
}
$opt = implode($separator, $selects);
- if (!empty($interval) && $interval > 1 && !empty($min)) {
- $min = round($min * (1 / $interval)) * $interval;
- }
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) {
case '24':
@@ -891,7 +891,7 @@ protected function _render($viewFile, $data = array()) {
* 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
*/
@@ -1156,9 +1156,15 @@ protected function _renderElement($file, $data, $options) {
$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 (isset($options['callbacks'])) {
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
}

0 comments on commit a3ae58d

Please sign in to comment.