Merge branch 'master' into 2.3

Conflicts:
	lib/Cake/View/View.php
This commit is contained in:
mark_story 2012-10-01 21:20:25 -04:00
commit a3ae58da09
7 changed files with 81 additions and 7 deletions

View file

@ -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';

View file

@ -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';

View file

@ -2247,6 +2247,43 @@ class FormHelperTest extends CakeTestCase {
$this->assertRegExp('#<option value="pm"[^>]*>pm</option>#', $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('<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
*

View file

@ -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');
@ -1421,6 +1422,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 = <<<TEXT
Parent View.
this is the test elementThe view
TEXT;
$this->assertEquals($expected, $result);
}
/**
* Test that setting arbitrary properties still works.
*
@ -1485,4 +1502,4 @@ TEXT;
$result = $this->View->fetch('title', $default);
$this->assertEquals($expected, $result);
}
}
}

View file

@ -0,0 +1,3 @@
<?php echo $this->element('test_element'); ?>
<?php $this->extend('parent_view'); ?>
The view

View file

@ -2261,6 +2261,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
@ -2322,9 +2336,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':

View file

@ -891,7 +891,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
*/
@ -1156,9 +1156,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 (isset($options['callbacks'])) {
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
}