From c551faad4685b46057e6cfa7e762ca1013dd96b7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 1 Apr 2016 23:08:31 -0400 Subject: [PATCH] Add tests for changes in #8387 Add tests covering the new behavior. --- .../Test/Case/View/Helper/FormHelperTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 79fd6118d..d9213b3e7 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -8073,6 +8073,34 @@ class FormHelperTest extends CakeTestCase { )); } +/** + * Test that postLink doesn't modify the fields in the containing form. + * + * postLink() calls inside open forms should not modify the field list + * for the form. + * + * @return void + */ + public function testPostLinkSecurityHashInline() { + $hash = Security::hash( + '/posts/delete/1' . + serialize(array()) . + '' . + Configure::read('Security.salt') + ); + $hash .= '%3A'; + $this->Form->request->params['_Token']['key'] = 'test'; + + $this->Form->create('Post', ['url' => ['action' => 'add']]); + $this->Form->input('title'); + $this->Form->postLink('Delete', '/posts/delete/1', ['inline' => false]); + $result = $this->View->fetch('postLink'); + + $this->assertEquals(array('Post.title'), $this->Form->fields); + $this->assertContains($hash, $result, 'Should contain the correct hash.'); + $this->assertAttributeEquals('/posts/add', '_lastAction', $this->Form, 'lastAction was should be restored.'); + } + /** * Test using postLink with N dimensional data. *