diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index 3908e40e1..75a145589 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -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)) { diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index 4f236e020..a9d958069 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -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); diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index a2fa22024..6997c8b82 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -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'))); + } + } diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index c497a4a80..eb0215c18 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -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'); diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index c962bd725..7e9cae7ff 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -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 = 'cool image'; + $result = $this->CakeEmail->send(); + $this->assertContains($expected, $result['message']); + } + /** * testSendRenderPlugin method * diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index f45f19cdc..2eaab04f6 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -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 diff --git a/lib/Cake/Test/test_app/View/Emails/html/image.ctp b/lib/Cake/Test/test_app/View/Emails/html/image.ctp new file mode 100644 index 000000000..073d58ab6 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Emails/html/image.ctp @@ -0,0 +1,23 @@ +Html->image('image.gif', array( + 'alt' => 'cool image', + 'width' => 100, + 'height' => 100, + 'fullBase' => true, + )); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index d1b9d45b1..a0b4aef4e 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -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; } } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 984abf884..59ce0aca4 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -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 {