Skip to content
Permalink
Browse files

reset value Sources via end(), split up tests, extend tests for filte…

…ring of invalid sources and form end() resetting
  • Loading branch information...
Jonas Hartmann
Jonas Hartmann committed Aug 21, 2016
1 parent 375a4e4 commit 39d53a9d56a869da84f7f666057786b0a36b24f1
Showing with 64 additions and 3 deletions.
  1. +3 −0 src/View/Helper/FormHelper.php
  2. +61 −3 tests/TestCase/View/Helper/FormHelperTest.php
@@ -534,6 +534,8 @@ protected function _csrfField()
* Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
* input fields where appropriate.
*
* Resets some parts of the stated shared among multiple FormHelper::create() calls to defaults.
*
* @param array $secureAttributes Secure attributes which will be passed as HTML attributes
* into the hidden input elements generated for the Security Component.
* @return string A closing FORM tag.
@@ -555,6 +557,7 @@ public function end(array $secureAttributes = [])
$this->templater()->pop();
$this->requestType = null;
$this->_context = null;
$this->_valuesSources = ['context'];
$this->_idPrefix = $this->config('idPrefix');
return $out;
@@ -8098,10 +8098,16 @@ public function testFormValuesSourcesSettersGetters()
$result = $this->Form->getSourceValue('id');
$this->assertEquals($expected, $result);
$expected = ['query', 'data', 'context'];
$this->Form->setValuesSources(['query', 'data', 'invalid', 'context', 'foo']);
$result = $this->Form->getValuesSources();
$this->assertEquals($expected, $result);
$this->Form->request->data['id'] = '1';
$this->Form->request->query['id'] = '2';
$this->Form->setValuesSources(['context']);
$expected = '1';
$result = $this->Form->getSourceValue('id');
$this->assertEquals($expected, $result);
@@ -8131,7 +8137,7 @@ public function testFormValuesSourcesSettersGetters()
*
* @return void
*/
public function testFormValuesSourcesSwitchInputs()
public function testFormValuesSourcesSingleSwitchRendering()
{
$this->loadFixtures('Articles');
$articles = TableRegistry::get('Articles');
@@ -8204,9 +8210,21 @@ public function testFormValuesSourcesSwitchInputs()
['input' => ['type' => 'hidden', 'name' => 'id', 'id' => 'id', 'value' => '9']],
];
$this->assertHtml($expected, $result);
}
/**
* Tests the different input rendering values based on sources values switching while supplying
* an entity (base context) and multiple sources (durch as data, query)
*
* @return void
*/
public function testFormValuesSourcesListSwitchRendering()
{
$this->loadFixtures('Articles');
$articles = TableRegistry::get('Articles');
$article = new Article();
$articles->patchEntity($article, ['id' => '3']);
unset($this->Form->request->data['id']);
$this->Form->request->query['id'] = '9';
$this->Form->create($article);
@@ -8261,7 +8279,7 @@ public function testFormValuesSourcesSwitchInputs()
*
* @return void
*/
public function testFormValuesSourcesSwitchViaOptions()
public function testFormValuesSourcesSwitchViaOptionsRendering()
{
$this->loadFixtures('Articles');
$articles = TableRegistry::get('Articles');
@@ -8318,6 +8336,19 @@ public function testFormValuesSourcesSwitchViaOptions()
$this->assertHtml($expected, $result);
$result = $this->Form->getSourceValue('id');
$this->assertEquals('8', $result);
}
/**
* Test the different form input renderings based on values sources switchings through form options
*
* @return void
*/
public function testFormValuesSourcesSwitchViaOptionsAndSetterRendering()
{
$this->loadFixtures('Articles');
$articles = TableRegistry::get('Articles');
$article = new Article();
$articles->patchEntity($article, ['id' => '3']);
$this->Form->request->data['id'] = '10';
@@ -8342,4 +8373,31 @@ public function testFormValuesSourcesSwitchViaOptions()
$result = $this->Form->getSourceValue('id');
$this->assertEquals('10', $result);
}
/**
* Test the different form input renderings based on values sources switchings through form options
*
* @return void
*/
public function testFormValuesSourcesResetViaEnd()
{
$expected = ['context'];
$result = $this->Form->getValuesSources();
$this->assertEquals($expected, $result);
$expected = ['query', 'context', 'data'];
$this->Form->setValuesSources(['query', 'context', 'data']);
$result = $this->Form->getValuesSources();
$this->assertEquals($expected, $result);
$this->Form->create();
$result = $this->Form->getValuesSources();
$this->assertEquals($expected, $result);
$this->Form->end();
$expected = ['context'];
$result = $this->Form->getValuesSources();
$this->assertEquals($expected, $result);
}
}

0 comments on commit 39d53a9

Please sign in to comment.
You can’t perform that action at this time.