Skip to content

Commit

Permalink
Fix some of formhelper's tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 9, 2017
1 parent dbff1b7 commit cedd563
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -7244,14 +7244,14 @@ public function testFileUploadField()
$result = $this->Form->file('Model.upload');
$this->assertHtml($expected, $result);

$this->Form->request->data['Model']['upload'] = [
$this->Form->request = $this->Form->request->withData('Model.upload', [
'name' => '', 'type' => '', 'tmp_name' => '',
'error' => 4, 'size' => 0
];
]);
$result = $this->Form->file('Model.upload');
$this->assertHtml($expected, $result);

$this->Form->request->data['Model']['upload'] = 'no data should be set in value';
$this->Form->request = $this->Form->request->withData('Model.upload', 'no data should be set in value');
$result = $this->Form->file('Model.upload');
$this->assertHtml($expected, $result);
}
Expand Down Expand Up @@ -7318,7 +7318,7 @@ public function testButton()
*/
public function testButtonUnlockedByDefault()
{
$this->Form->request->params['_csrfToken'] = 'secured';
$this->Form->request = $this->Form->request->withParam('_csrfToken', 'secured');
$this->Form->button('Save', ['name' => 'save']);
$this->Form->button('Clear');

Expand Down Expand Up @@ -7435,8 +7435,9 @@ public function testPostButtonNestedData()
*/
public function testSecurePostButton()
{
$this->Form->request->params['_csrfToken'] = 'testkey';
$this->Form->request->params['_Token'] = ['unlockedFields' => []];
$this->Form->request = $this->Form->request
->withParam('_csrfToken', 'testkey')
->withParam('_Token.unlockedFields', []);

$result = $this->Form->postButton('Delete', '/posts/delete/1');
$tokenDebug = urlencode(json_encode([
Expand Down Expand Up @@ -7628,7 +7629,7 @@ public function testPostLinkSecurityHash()
{
$hash = hash_hmac('sha1', '/posts/delete/1' . serialize(['id' => '1']) . session_id(), Security::getSalt());
$hash .= '%3Aid';
$this->Form->request->params['_Token']['key'] = 'test';
$this->Form->request = $this->Form->request->withParam('_Token.key', 'test');

$result = $this->Form->postLink(
'Delete',
Expand Down Expand Up @@ -7681,7 +7682,7 @@ public function testPostLinkSecurityHashBlockMode()
{
$hash = hash_hmac('sha1', '/posts/delete/1' . serialize([]) . session_id(), Security::getSalt());
$hash .= '%3A';
$this->Form->request->params['_Token']['key'] = 'test';
$this->Form->request = $this->Form->request->withParam('_Token.key', 'test');

$this->Form->create('Post', ['url' => ['action' => 'add']]);
$this->Form->control('title');
Expand All @@ -7705,7 +7706,8 @@ public function testPostLinkSecurityHashNoDebugMode()
Configure::write('debug', false);
$hash = hash_hmac('sha1', '/posts/delete/1' . serialize(['id' => '1']) . session_id(), Security::getSalt());
$hash .= '%3Aid';
$this->Form->request->params['_Token']['key'] = 'test';
$this->Form->request = $this->Form->request
->withParam('_Token.key', 'test');

$result = $this->Form->postLink(
'Delete',
Expand Down Expand Up @@ -7745,7 +7747,7 @@ public function testPostLinkNestedData()
'two' => [
3, 4, 5
]
]
]
];
$result = $this->Form->postLink('Send', '/', ['data' => $data]);
$this->assertContains('<input type="hidden" name="one[two][0]" value="3"', $result);
Expand All @@ -7762,8 +7764,9 @@ public function testPostLinkNestedData()
*/
public function testPostLinkAfterGetForm()
{
$this->Form->request->params['_csrfToken'] = 'testkey';
$this->Form->request->params['_Token'] = 'val';
$this->Form->request = $this->Form->request
->withParam('_csrfToken', 'testkey')
->withParam('_Token', 'val');

$this->Form->create($this->article, ['type' => 'get']);
$this->Form->end();
Expand Down Expand Up @@ -7977,7 +7980,7 @@ public function testSubmitImage()
*/
public function testSubmitUnlockedByDefault()
{
$this->Form->request->params['_Token'] = 'secured';
$this->Form->request = $this->Form->request->withParam('_Token', 'secured');
$this->Form->submit('Go go');
$this->Form->submit('Save', ['name' => 'save']);

Expand Down Expand Up @@ -8060,7 +8063,8 @@ public function testForMagicControlNonExistingNorValidated()
];
$this->assertHtml($expected, $result);

$this->Form->request->data = ['non_existing_nor_validated' => 'CakePHP magic'];
$this->Form->request = $this->Form->request->withData('non_existing_nor_validated', 'CakePHP magic');
$this->Form->create($this->article);
$result = $this->Form->control('non_existing_nor_validated');
$expected = [
'label' => ['for' => 'non-existing-nor-validated'],
Expand Down Expand Up @@ -8646,22 +8650,19 @@ public function testAutoDomId()
*/
public function testFormValueSourcesSettersGetters()
{
$this->Form->request = $this->Form->request
->withData('id', '1')
->withQueryParams(['id' => '2']);

$expected = ['context'];
$result = $this->Form->getValueSources();
$this->assertEquals($expected, $result);

$expected = null;
$result = $this->Form->getSourceValue('id');
$this->assertEquals($expected, $result);

$expected = ['query', 'data', 'context'];
$this->Form->setValueSources(['query', 'data', 'invalid', 'context', 'foo']);
$result = $this->Form->getValueSources();
$this->assertEquals($expected, $result);

$this->Form->request->data['id'] = '1';
$this->Form->request->query['id'] = '2';

$this->Form->setValueSources(['context']);
$expected = '1';
$result = $this->Form->getSourceValue('id');
Expand Down Expand Up @@ -8707,16 +8708,17 @@ public function testFormValueSourcesSingleSwitchRendering()
];
$this->assertHtml($expected, $result);

$this->Form->request->query['id'] = '5';
$this->Form->request = $this->Form->request->withQueryParams(['id' => 5]);
$this->Form->setValueSources(['query']);
$result = $this->Form->control('id');
$expected = [
['input' => ['type' => 'hidden', 'name' => 'id', 'id' => 'id', 'value' => '5']],
];
$this->assertHtml($expected, $result);

$this->Form->request->query['id'] = '5a';
$this->Form->request->data['id'] = '5b';
$this->Form->request = $this->Form->request
->withQueryParams(['id' => '5a'])
->withData('id', '5b');

$this->Form->setValueSources(['context']);
$this->Form->create($article);
Expand Down Expand Up @@ -8800,8 +8802,8 @@ public function testFormValueSourcesSwitchViaOptionsRendering()
$articles = TableRegistry::get('Articles');
$article = new Article();
$articles->patchEntity($article, ['id' => '3']);
$this->Form->request->data['id'] = '4';
$this->Form->request->query['id'] = '5';

$this->Form->request = $this->Form->request->withData('id', 4)->withQueryParams(['id' => 5]);

$this->Form->create($article, ['valueSources' => 'query']);
$result = $this->Form->control('id');
Expand Down Expand Up @@ -8856,8 +8858,7 @@ public function testFormValueSourcesSwitchViaOptionsAndSetterRendering()
$article = new Article();
$articles->patchEntity($article, ['id' => '3']);

$this->Form->request->data['id'] = '10';
$this->Form->request->query['id'] = '11';
$this->Form->request = $this->Form->request->withData('id', 10)->withQueryParams(['id' => 11]);

$this->Form->setValueSources(['context'])
->create($article, ['valueSources' => ['query', 'data']]);
Expand All @@ -8869,7 +8870,7 @@ public function testFormValueSourcesSwitchViaOptionsAndSetterRendering()
$result = $this->Form->getSourceValue('id');
$this->assertEquals('11', $result);

unset($this->Form->request->query['id']);
$this->Form->request = $this->Form->request->withQueryParams([]);
$this->Form->setValueSources(['context'])
->create($article, ['valueSources' => ['query', 'data']]);
$result = $this->Form->control('id');
Expand Down Expand Up @@ -8914,7 +8915,7 @@ public function testFormValueSourcesResetViaEnd()
*/
public function testFormValueSourcesDefaults()
{
$this->Form->request->query['password'] = 'open Sesame';
$this->Form->request = $this->Form->request->withQueryParams(['password' => 'open Sesame']);
$this->Form->create();

$result = $this->Form->password('password');
Expand Down

0 comments on commit cedd563

Please sign in to comment.