Merge remote-tracking branch 'origin/2.1' into 2.2

Conflicts:
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Model/ModelValidationTest.php
This commit is contained in:
Jose Lorenzo Rodriguez 2012-06-06 11:06:06 -04:30
commit 51635c2ca6
9 changed files with 87 additions and 15 deletions

View file

@ -137,7 +137,9 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
if ($options['deep']) {
$validates = $model->{$association}->validateAssociated($values, $options);
} else {
$validates = $model->{$association}->create($values) !== null && $model->{$association}->validates($options);
$model->{$association}->create(null);
$validates = $model->{$association}->set($values) && $model->{$association}->validates($options);
$data[$association] = $model->{$association}->data[$model->{$association}->alias];
}
if (is_array($validates)) {
if (in_array(false, $validates, true)) {

View file

@ -296,21 +296,8 @@ class ExceptionRendererTest extends CakeTestCase {
$testApp . 'Error' . DS
),
), App::RESET);
Configure::write('Error', array(
'handler' => 'TestAppsErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
Configure::write('Exception', array(
'handler' => 'TestAppsErrorHandler::handleException',
'renderer' => 'TestAppsExceptionRenderer',
'log' => true
));
App::uses('TestAppsErrorController', 'Controller');
App::uses('TestAppsExceptionRenderer', 'Error');
$exception = new SocketException('socket exception');
$renderer = new TestAppsExceptionRenderer($exception);

View file

@ -2057,4 +2057,34 @@ class ModelValidationTest extends BaseModelTest {
$this->assertSame($set, $Validator->getField('other'));
}
/**
* Tests that altering data in a beforeValidate callback will lead to saving those
* values in database, this time with belongsTo associations
*
* @return void
*/
public function testValidateFirstAssociatedWithBeforeValidate2() {
$this->loadFixtures('Article', 'User');
$model = new CustomArticle();
$model->validate = array(
'title' => array(
'notempty' => array(
'rule' => 'notEmpty',
'required' => true
)
)
);
$data = array(
'User' => array('user' => 'foo', 'password' => 'bar'),
'CustomArticle' => array(
'body' => 'a test'
)
);
$result = $model->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result);
$this->assertEquals('foo', $model->field('title', array('body' => 'a test')));
}
}

View file

@ -5939,6 +5939,7 @@ class ModelWriteTest extends BaseModelTest {
* @return void
*/
public function testValidateAssociated() {
$this->loadFixtures('Attachment', 'Article', 'Comment');
$TestModel = new Comment();
$TestModel->Attachment->validate = array('attachment' => 'notEmpty');

View file

@ -1099,6 +1099,27 @@ class CakeEmailTest extends CakeTestCase {
$this->assertEquals(array('Time'), $result);
}
/**
* testSendRenderWithImage method
*
* @return void
*/
public function testSendRenderWithImage() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('image');
$this->CakeEmail->emailFormat('html');
$expected = '<img src="http://localhost/img/image.gif" alt="cool image" width="100" height="100" />';
$result = $this->CakeEmail->send();
$this->assertContains($expected, $result['message']);
}
/**
* testSendRenderPlugin method
*

View file

@ -324,7 +324,7 @@ object(View) {
validationErrors => array()
hasRendered => false
uuids => array()
request => null
request => object(CakeRequest) {}
response => object(CakeResponse) {}
elementCache => 'default'
int => (int) 2

View file

@ -0,0 +1,23 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @since CakePHP(tm) v 2.1
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
echo $this->Html->image('image.gif', array(
'alt' => 'cool image',
'width' => 100,
'height' => 100,
'fullBase' => true,
));

View file

@ -313,6 +313,9 @@ class Helper extends Object {
$path = h($this->assetTimestamp($this->webroot($path)));
if (!empty($options['fullBase'])) {
if ($path[0] == '/') {
$path = substr($path, 1);
}
$path = $this->url('/', true) . $path;
}
}

View file

@ -319,6 +319,11 @@ class View extends Object {
}
$this->_eventManager = $controller->getEventManager();
}
if (empty($this->request) && !($this->request = Router::getRequest(true))) {
$this->request = new CakeRequest(null, false);
$this->request->base = '';
$this->request->here = $this->request->webroot = '/';
}
if (is_object($controller) && isset($controller->response)) {
$this->response = $controller->response;
} else {