From 5cf2ce723c751036b586708ffd6973d0083c7deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Fri, 25 Apr 2014 21:58:17 +0100 Subject: [PATCH 1/4] fixed FormHelper to allow create() on Mock Models without errors --- .../Test/Case/View/Helper/FormHelperTest.php | 20 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index f548663cd..411db6fe8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -8358,6 +8358,26 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test that create() works without raising errors with a Mock Model + * + * @return void + */ + public function testCreateNoErrorsWithMockModel() { + $encoding = strtolower(Configure::read('App.encoding')); + $ContactMock = $this->getMockBuilder('Contact') + ->disableOriginalConstructor() + ->getMock(); + ClassRegistry::removeObject('Contact'); + ClassRegistry::addObject('Contact', $ContactMock); + $result = $this->Form->create('Contact', array('type' => 'GET')); + $expected = array('form' => array( + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add', + 'accept-charset' => $encoding + )); + $this->assertTags($result, $expected); + } + /** * test creating a get form, and get form inputs. * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 4a532003b..85683a1d0 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -226,7 +226,7 @@ class FormHelper extends AppHelper { if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) { $validates = array(); - foreach ($object->validator() as $validateField => $validateProperties) { + foreach (iterator_to_array($object->validator(), true) as $validateField => $validateProperties) { if ($this->_isRequiredField($validateProperties)) { $validates[$validateField] = true; } From 68572d8046ff3f1ef4d1937a5c155b3f53c6b76c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 26 Apr 2014 17:29:09 +0530 Subject: [PATCH 2/4] Cannot use php 5.4+ array syntax for 2.x. --- .../Test/Case/Controller/Component/SecurityComponentTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php index 0243fa90b..055a8bc8e 100644 --- a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php @@ -142,7 +142,7 @@ class SecurityComponentTest extends CakeTestCase { public function setUp() { parent::setUp(); - $request = $this->getMock('CakeRequest', ['here'], ['posts/index', false]); + $request = $this->getMock('CakeRequest', array('here'), array('posts/index', false)); $request->addParams(array('controller' => 'posts', 'action' => 'index')); $request->expects($this->any()) ->method('here') @@ -794,7 +794,7 @@ class SecurityComponentTest extends CakeTestCase { $unlocked = 'Model.username'; $fields = array('Model.hidden', 'Model.password'); $fields = urlencode(Security::hash( - '/posts/index' . + '/posts/index' . serialize($fields) . $unlocked . Configure::read('Security.salt')) From a28158d614cb469dac41e03c9f95bffd0b60cdbc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 26 Apr 2014 10:22:14 -0400 Subject: [PATCH 3/4] Add additional test for f23d811ff59c50ef278e98bb75f4ec1e7e54a5b3 I neglected to put a negative test to ensure validatePost fails when the URL differs. --- .../Component/SecurityComponentTest.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php index 055a8bc8e..b470fba63 100644 --- a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php @@ -1067,7 +1067,7 @@ class SecurityComponentTest extends CakeTestCase { * * @return void */ - public function testRadio() { + public function testValidatePostRadio() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; $fields = '3be63770e7953c6d2119f5377a9303372040f66f%3An%3A0%3A%7B%7D'; @@ -1101,6 +1101,38 @@ class SecurityComponentTest extends CakeTestCase { $this->assertTrue($result); } +/** + * test validatePost uses here() as a hash input. + * + * @return void + */ + public function testValidatePostUrlAsHashInput() { + $this->Controller->Security->startup($this->Controller); + + $key = $this->Controller->request->params['_Token']['key']; + $fields = '5415d31b4483c1e09ddb58d2a91ba9650b12aa83%3A'; + $unlocked = ''; + + $this->Controller->request->data = array( + 'Model' => array('username' => '', 'password' => ''), + '_Token' => compact('key', 'fields', 'unlocked') + ); + $this->assertTrue($this->Controller->Security->validatePost($this->Controller)); + + $request = $this->getMock('CakeRequest', array('here'), array('articles/edit/1', false)); + $request->expects($this->at(0)) + ->method('here') + ->will($this->returnValue('/posts/index?page=1')); + $request->expects($this->at(1)) + ->method('here') + ->will($this->returnValue('/posts/edit/1')); + + $this->Controller->Security->request = $request; + $this->assertFalse($this->Controller->Security->validatePost($this->Controller)); + $this->assertFalse($this->Controller->Security->validatePost($this->Controller)); + } + + /** * test that a requestAction's controller will have the _Token appended to * the params. From 99a7ddf195f82254feffbd6766c03ae71e382082 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 26 Apr 2014 22:04:40 -0400 Subject: [PATCH 4/4] Update version number to 2.5.0-RC2 --- lib/Cake/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/VERSION.txt b/lib/Cake/VERSION.txt index d93087dc5..7eafc9e1e 100644 --- a/lib/Cake/VERSION.txt +++ b/lib/Cake/VERSION.txt @@ -17,4 +17,4 @@ // @license http://www.opensource.org/licenses/mit-license.php MIT License // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -2.5.0-RC1 +2.5.0-RC2