Merge branch '2.1' into 2.2

This commit is contained in:
mark_story 2012-04-17 21:47:24 -04:00
commit 21ba5bf04a
30 changed files with 420 additions and 172 deletions

View file

@ -11,4 +11,4 @@ echo $this->Rss->document(
array(), $channel, $content_for_layout
)
);
?>
?>

View file

@ -86,10 +86,6 @@
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
}
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();

View file

@ -1,6 +1,4 @@
<?php
echo $rss->header();
if (!isset($channel)) {
$channel = array();
}
@ -8,10 +6,9 @@ if (!isset($channel['title'])) {
$channel['title'] = $title_for_layout;
}
echo $rss->document(
$rss->channel(
echo $this->Rss->document(
$this->Rss->channel(
array(), $channel, $content_for_layout
)
);
?>

View file

@ -88,10 +88,6 @@ if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
}
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();

View file

@ -54,7 +54,7 @@ class CakeErrorController extends AppController {
$this->components[] = 'RequestHandler';
}
$this->constructClasses();
$this->Components->trigger('initialize', array(&$this));
$this->startupProcess();
$this->_set(array('cacheAction' => false, 'viewPath' => 'Errors'));
if (isset($this->RequestHandler)) {

View file

@ -471,17 +471,7 @@ class TranslateBehavior extends ModelBehavior {
);
}
if (array_key_exists($field, $this->settings[$model->alias])) {
unset($this->settings[$model->alias][$field]);
} elseif (in_array($field, $this->settings[$model->alias])) {
$this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field)));
}
if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) {
unset($this->runtime[$model->alias]['fields'][$field]);
} elseif (in_array($field, $this->runtime[$model->alias]['fields'])) {
$this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field)));
}
$this->_updateSettings($model, $field);
if (is_null($association)) {
if ($reset) {
@ -518,6 +508,25 @@ class TranslateBehavior extends ModelBehavior {
return true;
}
/**
* Update runtime setting for a given field.
*
* @param string $field The field to update.
*/
protected function _updateSettings(Model $model, $field) {
if (array_key_exists($field, $this->settings[$model->alias])) {
unset($this->settings[$model->alias][$field]);
} elseif (in_array($field, $this->settings[$model->alias])) {
$this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field)));
}
if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) {
unset($this->runtime[$model->alias]['fields'][$field]);
} elseif (in_array($field, $this->runtime[$model->alias]['fields'])) {
$this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field)));
}
}
/**
* Unbind translation for fields, optionally unbinds hasMany association for
* fake field
@ -550,17 +559,7 @@ class TranslateBehavior extends ModelBehavior {
$association = $value;
}
if (array_key_exists($field, $this->settings[$model->alias])) {
unset($this->settings[$model->alias][$field]);
} elseif (in_array($field, $this->settings[$model->alias])) {
$this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field)));
}
if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) {
unset($this->runtime[$model->alias]['fields'][$field]);
} elseif (in_array($field, $this->runtime[$model->alias]['fields'])) {
$this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field)));
}
$this->_updateSettings($model, $field);
if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {
$associations[] = $association;

View file

@ -602,6 +602,8 @@ class CakeSession {
$_SESSION = array();
}
} else {
// For IE<=8
session_cache_limiter("must-revalidate");
session_start();
}
return true;

View file

@ -1319,7 +1319,9 @@ class Model extends Object implements CakeEventListener {
$cols = $this->schema();
$model = null;
$column = str_replace(array($db->startQuote, $db->endQuote), '', $column);
$startQuote = isset($db->startQuote) ? $db->startQuote : null;
$endQuote = isset($db->endQuote) ? $db->endQuote : null;
$column = str_replace(array($startQuote, $endQuote), '', $column);
if (strpos($column, '.')) {
list($model, $column) = explode('.', $column);
@ -2034,6 +2036,9 @@ class Model extends Object implements CakeEventListener {
if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}
@ -2042,7 +2047,7 @@ class Model extends Object implements CakeEventListener {
if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) {
return $validates;
}
$options['validate'] = true;
$options['validate'] = false;
}
if ($options['atomic']) {
@ -2165,6 +2170,9 @@ class Model extends Object implements CakeEventListener {
if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}
@ -2173,7 +2181,7 @@ class Model extends Object implements CakeEventListener {
if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) {
return $validates;
}
$options['validate'] = true;
$options['validate'] = false;
}
if ($options['atomic']) {
$db = $this->getDataSource();
@ -2183,7 +2191,8 @@ class Model extends Object implements CakeEventListener {
$return = array();
$validates = true;
foreach ($data as $association => $values) {
if (isset($associations[$association]) && $associations[$association] === 'belongsTo') {
$notEmpty = !empty($values[$association]) || (!isset($values[$association]) && !empty($values));
if (isset($associations[$association]) && $associations[$association] === 'belongsTo' && $notEmpty) {
$validates = $this->{$association}->create(null) !== null;
$saved = false;
if ($validates) {
@ -2217,7 +2226,8 @@ class Model extends Object implements CakeEventListener {
if (!$validates) {
break;
}
if (isset($associations[$association])) {
$notEmpty = !empty($values[$association]) || (!isset($values[$association]) && !empty($values));
if (isset($associations[$association]) && $notEmpty) {
$type = $associations[$association];
$key = $this->{$type}[$association]['foreignKey'];
switch ($type) {
@ -3369,7 +3379,7 @@ class Model extends Object implements CakeEventListener {
* Sets the DataSource to which this model is bound.
*
* @param string $dataSource The name of the DataSource, as defined in app/Config/database.php
* @return boolean True on success
* @return void
* @throws MissingConnectionException
*/
public function setDataSource($dataSource = null) {

View file

@ -39,6 +39,8 @@ class CakeRequest implements ArrayAccess {
'plugin' => null,
'controller' => null,
'action' => null,
'named' => array(),
'pass' => array(),
);
/**

View file

@ -114,7 +114,7 @@ class SchemaShellTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -49,7 +49,7 @@ class DbConfigTaskTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -239,7 +239,7 @@ class TestTaskTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -525,7 +525,7 @@ class ShellTest extends CakeTestCase {
* @return void
*/
public function testCreateFileNonInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Not supported on Windows.');
$eol = PHP_EOL;
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
@ -534,7 +534,7 @@ class ShellTest extends CakeTestCase {
$this->Shell->interactive = false;
$contents = "<?php\necho 'test';\n\$te = 'st';\n";
$contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
@ -553,7 +553,7 @@ class ShellTest extends CakeTestCase {
* @return void
*/
public function testCreateFileInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Not supported on Windows.');
$eol = PHP_EOL;
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
@ -569,7 +569,7 @@ class ShellTest extends CakeTestCase {
->method('read')
->will($this->returnValue('y'));
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n";
$contents = "<?php{$eol}echo 'yet another test';{$eol}\$te = 'st';{$eol}";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
@ -609,81 +609,6 @@ class ShellTest extends CakeTestCase {
rmdir($path);
}
/**
* testCreateFileWindows method
*
* @return void
*/
public function testCreateFileWindowsNonInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsNonInteractive supported on Windows only.');
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
$Folder = new Folder($path, true);
$this->Shell->interactive = false;
$contents = "<?php\r\necho 'test';\r\n\$te = 'st';\r\n";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);
$contents = "<?php\r\necho 'another test';\r\n\$te = 'st';\r\n";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);
$Folder = new Folder($path);
$Folder->delete();
}
/**
* test createFile on windows with interactive on.
*
* @return void
*/
public function testCreateFileWindowsInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only.');
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
$Folder = new Folder($path, true);
$this->Shell->interactive = true;
$this->Shell->stdin->expects($this->at(0))
->method('read')
->will($this->returnValue('n'));
$this->Shell->stdin->expects($this->at(1))
->method('read')
->will($this->returnValue('y'));
$contents = "<?php\r\necho 'yet another test';\r\n\$te = 'st';\r\n";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);
// no overwrite
$contents = 'new contents';
$result = $this->Shell->createFile($file, $contents);
$this->assertFalse($result);
$this->assertTrue(file_exists($file));
$this->assertNotEquals($contents, file_get_contents($file));
// overwrite
$contents = 'more new contents';
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals($contents, file_get_contents($file));
$Folder->delete();
}
/**
* test hasTask method
*

View file

@ -117,7 +117,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -706,21 +706,21 @@ class CakeSessionTest extends CakeTestCase {
TestCakeSession::destroy();
TestCakeSession::write('Test', 'some value');
$this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime);
$this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1);
$this->assertEquals(10, $_SESSION['Config']['countdown']);
$this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']);
$this->assertEquals(time(), CakeSession::$time);
$this->assertEquals(time() + $timeoutSeconds, $_SESSION['Config']['time']);
$this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), CakeSession::$time, 1);
$this->assertWithinMargin(time() + $timeoutSeconds, $_SESSION['Config']['time'], 1);
Configure::write('Session.harden', true);
TestCakeSession::destroy();
TestCakeSession::write('Test', 'some value');
$this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime);
$this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1);
$this->assertEquals(10, $_SESSION['Config']['countdown']);
$this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']);
$this->assertEquals(time(), CakeSession::$time);
$this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']);
$this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1);
$this->assertWithinMargin(time(), CakeSession::$time, 1);
$this->assertWithinMargin(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time'], 1);
}
/**

View file

@ -0,0 +1,250 @@
<?php
/**
* DataSourceTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Datasource
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Model', 'Model');
App::uses('DataSource', 'Model/Datasource');
/**
* TestSource
*
* @package Cake.Test.Case.Model.Datasource
*/
class TestSource extends DataSource {
/**
* _schema
* @var type
*/
protected $_schema = array(
'id' => array(
'type' => 'integer',
'null' => false,
'key' => 'primary',
'length' => 11,
),
'text' => array(
'type' => 'string',
'null' => true,
'length' => 140,
),
'status' => array(
'type' => 'string',
'null' => true,
'length' => 140,
),
'customField' => array(
'type' => 'string',
'null' => true,
'length' => 255,
),
);
/**
* listSources
*
* @return boolean
*/
public function listSources() {
return null;
}
/**
* Returns the schema for the datasource to enable create/update
*
* @param object $Model
* @return array
*/
public function describe(Model $Model) {
return $this->_schema;
}
/**
* Just return $func to pass to read() to figure out the COUNT
* Required for delete/update to work
*
* @param Model $Model
* @param type $func
* @param type $params
* @return array
*/
public function calculate(Model $Model, $func, $params = array()) {
return $func;
}
}
/**
* DataSourceTest class
*
* @package Cake.Test.Case.Model.Datasource
*/
class DataSourceTest extends CakeTestCase {
/**
* Name of test source
*
* @var string
*/
public $sourceName = 'myapitest';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Source = $this->getMock(
'TestSource',
array('create', 'read', 'update', 'delete')
);
ConnectionManager::create($this->sourceName, array(
'datasource' => get_class($this->Source),
'apiKey' => '1234abcd',
));
$this->Model = $this->getMock(
'Model',
array('getDataSource'),
array(array('ds' => $this->sourceName))
);
$this->Model->expects($this->any())
->method('getDataSource')
->will($this->returnValue($this->Source));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Model, $this->Source);
ConnectionManager::drop($this->sourceName);
}
/**
* testCreate
*
* @return void
*/
public function testCreate() {
$data = array(
$this->Model->alias => array(
'text' => 'This is a test',
'status' => 'Test status',
'customField' => array(
'array', 'field', 'type',
'for', 'custom', 'datasources',
),
),
);
$this->Source->expects($this->once())
->method('create')
->with(
$this->equalTo($this->Model),
$this->equalTo(array_keys($data[$this->Model->alias])),
$this->equalTo(array_values($data[$this->Model->alias]))
);
$this->Model->save($data);
}
/**
* testRead
*
* @return void
*/
public function testRead() {
$expected = array(
'conditions' => array('status' => 'test'),
'fields' => null,
'joins' => array(),
'limit' => 10,
'offset' => null,
'order' => array(array('status')),
'page' => 1,
'group' => null,
'callbacks' => true,
);
$this->Source->expects($this->once())
->method('read')
->with(
$this->anything(),
$this->equalTo($expected)
);
$this->Model->find('all', array(
'conditions' => array('status' => 'test'),
'limit' => 10,
'order' => array('status'),
));
}
/**
* testUpdate
*
* @return void
*/
public function testUpdate() {
$data = array(
$this->Model->alias => array(
'id' => 1,
'text' => 'This is a test',
'status' => 'Test status',
'customField' => array(
'array', 'field', 'type',
'for', 'custom', 'datasources',
),
),
);
$this->Source->expects($this->any())
->method('read')
->will($this->returnValue(array(
array($this->Model->alias => array('count' => 1))
)));
$this->Source->expects($this->once())
->method('update')
->with(
$this->equalTo($this->Model),
$this->equalTo(array_keys($data[$this->Model->alias])),
$this->equalTo(array_values($data[$this->Model->alias]))
);
$this->Model->save($data);
}
/**
* testDelete
*
* @return void
*/
public function testDelete() {
$this->Source->expects($this->any())
->method('read')
->will($this->returnValue(array(
array($this->Model->alias => array('count' => 1))
)));
$this->Source->expects($this->once())
->method('delete')
->with(
$this->equalTo($this->Model),
$this->equalTo(array($this->Model->alias . '.id' => 1))
);
$this->Model->delete(1);
}
}

View file

@ -60,13 +60,6 @@ class DboTestSource extends DboSource {
*/
class DboSourceTest extends CakeTestCase {
/**
* debug property
*
* @var mixed null
*/
public $debug = null;
/**
* autoFixtures property
*
@ -102,7 +95,7 @@ class DboSourceTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -5228,6 +5228,39 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment'));
}
/**
* testSaveAssociatedHasManyEmpty method
*
* @return void
*/
public function testSaveAssociatedHasManyEmpty() {
$this->loadFixtures('Article', 'Comment');
$TestModel = new Article();
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
$TestModel->validate = $TestModel->Comment->validate = array('user_id' => array('notEmpty' => array('rule' => 'notEmpty', 'required' => true)));
//empty hasMany data is ignored in save
$result = $TestModel->saveAssociated(array(
'Article' => array('title' => 'title', 'user_id' => 1),
'Comment' => array()
), array('validate' => true));
$this->assertTrue($result);
$result = $TestModel->saveAssociated(array(
'Article' => array('title' => 'title', 'user_id' => 1),
'Comment' => array()
), array('validate' => true, 'atomic' => false));
$this->assertEquals(array('Article' => true), $result);
//empty primary data is not ignored
$result = $TestModel->saveAssociated(array('Article' => array()), array('validate' => true));
$this->assertFalse($result);
$result = $TestModel->saveAssociated(array('Article' => array()), array('validate' => true, 'atomic' => false));
$this->assertEquals(array('Article' => false), $result);
}
/**
* testSaveAssociatedHasManyValidation method
*

View file

@ -972,12 +972,21 @@ class HttpSocketTest extends CakeTestCase {
->method('request')
->with(array('method' => 'GET', 'uri' => 'https://secure.example.com/test.php?one=two'));
$this->RequestSocket->expects($this->at(6))
->method('request')
->with(array('method' => 'GET', 'uri' => 'https://example.com/oauth/access?clientid=123&redirect_uri=http%3A%2F%2Fexample.com&code=456'));
$this->RequestSocket->get('http://www.google.com/');
$this->RequestSocket->get('http://www.google.com/', array('foo' => 'bar'));
$this->RequestSocket->get('http://www.google.com/', 'foo=bar');
$this->RequestSocket->get('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23'));
$this->RequestSocket->get('http://www.google.com/', null, array('version' => '1.0'));
$this->RequestSocket->get('https://secure.example.com/test.php', array('one' => 'two'));
$this->RequestSocket->get('https://example.com/oauth/access', array(
'clientid' => '123',
'redirect_uri' => 'http://example.com',
'code' => 456
));
}
/**

View file

@ -2157,7 +2157,8 @@ class RouterTest extends CakeTestCase {
$expected = array(
'plugin' => null, 'controller' => false, 'action' => false,
'param1' => '1', 'param2' => '2'
'named' => array(), 'pass' => array(),
'param1' => '1', 'param2' => '2',
);
$this->assertEquals(Router::getParams(), $expected);
$this->assertEquals(Router::getParam('controller'), false);
@ -2168,7 +2169,10 @@ class RouterTest extends CakeTestCase {
$params = array('controller' => 'pages', 'action' => 'display');
Router::setRequestInfo(array($params, $paths));
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
$expected = array(
'plugin' => null, 'controller' => 'pages', 'action' => 'display',
'named' => array(), 'pass' => array(),
);
$this->assertEquals(Router::getParams(), $expected);
$this->assertEquals(Router::getParams(true), $expected);
}

View file

@ -103,6 +103,8 @@ class ValidationTest extends CakeTestCase {
public function setUp() {
parent::setUp();
$this->_appEncoding = Configure::read('App.encoding');
$this->_appLocale = setlocale(LC_ALL, "0");
setlocale(LC_ALL, 'en_US');
}
/**
@ -113,6 +115,7 @@ class ValidationTest extends CakeTestCase {
public function tearDown() {
parent::tearDown();
Configure::write('App.encoding', $this->_appEncoding);
setlocale(LC_ALL, $this->_appLocale);
}
/**
@ -1490,10 +1493,16 @@ class ValidationTest extends CakeTestCase {
$this->assertTrue(Validation::decimal('+0123.45e6'));
$this->assertTrue(Validation::decimal('-0123.45e6'));
$this->assertTrue(Validation::decimal('0123.45e6'));
$this->assertTrue(Validation::decimal('1234'));
$this->assertTrue(Validation::decimal('-1234'));
$this->assertTrue(Validation::decimal('+1234'));
$this->assertTrue(Validation::decimal(1234.56));
$this->assertTrue(Validation::decimal(1234.00));
$this->assertTrue(Validation::decimal(.0));
$this->assertTrue(Validation::decimal(.00));
$this->assertTrue(Validation::decimal(.01));
$this->assertFalse(Validation::decimal('string'));
$this->assertFalse(Validation::decimal('1234'));
$this->assertFalse(Validation::decimal('-1234'));
$this->assertFalse(Validation::decimal('+1234'));
}
/**

View file

@ -6047,7 +6047,7 @@ class FormHelperTest extends CakeTestCase {
public function testPostButton() {
$result = $this->Form->postButton('Hi', '/controller/action');
$this->assertTags($result, array(
'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8', 'style' => 'display:none;'),
'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div',
@ -6073,7 +6073,6 @@ class FormHelperTest extends CakeTestCase {
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
'style' => 'display:none;'
),
array('div' => array('style' => 'display:none;')),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),

View file

@ -40,7 +40,7 @@ class MediaViewTest extends CakeTestCase {
}
/**
* endTest method
* tearDown method
*
* @return void
*/

View file

@ -994,6 +994,23 @@ class ViewTest extends CakeTestCase {
$this->assertRegExp('/Add User/', $result);
}
/**
* Test render()ing a file in a subdir from a custom viewPath
* in a plugin.
*
* @return void
*/
public function testGetViewFileNameSubdirWithPluginAndViewPath() {
$this->PostsController->plugin = 'TestPlugin';
$this->PostsController->viewPath = 'Elements';
$this->PostsController->name = 'Posts';
$View = new TestView($this->PostsController);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' .
DS . 'View' . DS . 'Elements' . DS . 'sub_dir' . DS . 'sub_element.ctp';
$this->assertEquals($expected, $View->getViewFileName('sub_dir/sub_element'));
}
/**
* test that view vars can replace the local helper variables
* and not overwrite the $this->Helper references

View file

@ -0,0 +1 @@
Content from TestPlugin.Elements/sub_dir/sub_element

View file

@ -382,9 +382,9 @@ class Validation {
public static function decimal($check, $places = null, $regex = null) {
if (is_null($regex)) {
if (is_null($places)) {
$regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
$regex = '/^[-+]?[0-9]*(\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?)?$/';
} else {
$regex = '/^[-+]?[0-9]*\\.{1}[0-9]{' . $places . '}$/';
$regex = '/^[-+]?[0-9]*(\\.{1}[0-9]{' . $places . '})?$/';
}
}
return self::_check($check, $regex);

View file

@ -140,6 +140,20 @@ class Helper extends Object {
'autoplay', 'controls', 'loop', 'muted'
);
/**
* Format to attribute
*
* @var string
*/
protected $_attributeFormat = '%s="%s"';
/**
* Format to attribute
*
* @var string
*/
protected $_minimizedAttributeFormat = '%s="%s"';
/**
* Default Constructor
*

View file

@ -144,6 +144,11 @@ class FormHelper extends AppHelper {
'class' => $plugin . $this->request->params['models'][$model]['className'],
'alias' => $model
));
} elseif (ClassRegistry::isKeySet($this->defaultModel)) {
$defaultObject = ClassRegistry::getObject($this->defaultModel);
if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
$object = $defaultObject->{$model};
}
} else {
$object = ClassRegistry::init($model, true);
}
@ -349,12 +354,13 @@ class FormHelper extends AppHelper {
$options = $model;
$model = null;
}
if (empty($model) && $model !== false && !empty($this->request->params['models'])) {
$model = key($this->request->params['models']);
$this->defaultModel = $model;
} elseif (empty($model) && empty($this->request->params['models'])) {
$model = false;
}
$this->defaultModel = $model;
$key = null;
if ($model !== false) {
@ -396,7 +402,7 @@ class FormHelper extends AppHelper {
$options['action'] = $this->request->here(false);
} elseif (empty($options['url']) || is_array($options['url'])) {
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $this->defaultModel) {
if (!empty($model)) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
} elseif (!empty($this->request->params['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->request->params['controller']);
@ -1584,7 +1590,7 @@ class FormHelper extends AppHelper {
/**
* Create a `<button>` tag with a surrounding `<form>` that submits via POST.
*
* This method creates a `<form>` element. So do not use this method in some opened form.
* This method creates a `<form>` element. So do not use this method in an already opened form.
* Instead use FormHelper::submit() or FormHelper::button() to create buttons inside opened forms.
*
* ### Options:
@ -1599,7 +1605,7 @@ class FormHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::postButton
*/
public function postButton($title, $url, $options = array()) {
$out = $this->create(false, array('id' => false, 'url' => $url, 'style' => 'display:none;'));
$out = $this->create(false, array('id' => false, 'url' => $url));
if (isset($options['data']) && is_array($options['data'])) {
foreach ($options['data'] as $key => $value) {
$out .= $this->hidden($key, array('value' => $value, 'id' => false));

View file

@ -102,20 +102,6 @@ class HtmlHelper extends AppHelper {
'javascriptend' => '</script>'
);
/**
* Format to attribute
*
* @var string
*/
protected $_attributeFormat = '%s="%s"';
/**
* Format to attribute
*
* @var string
*/
protected $_minimizedAttributeFormat = '%s="%s"';
/**
* Breadcrumbs.
*

View file

@ -648,7 +648,7 @@ class View extends Object {
/**
* Fetch the content for a block. If a block is
* empty or undefined '' will be returnned.
* empty or undefined '' will be returned.
*
* @param string $name Name of the block
* @return The block content or '' if the block does not exist.
@ -954,7 +954,7 @@ class View extends Object {
$name = trim($name, DS);
} elseif ($name[0] === '.') {
$name = substr($name, 3);
} elseif (!$plugin) {
} elseif (!$plugin || $this->viewPath !== $this->name) {
$name = $this->viewPath . DS . $subDir . $name;
}
}