Skip to content

Commit

Permalink
Fix deprecated method use in formhelper/tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 9adee92 commit 5c879ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
17 changes: 13 additions & 4 deletions src/View/Helper/FormHelper.php
Expand Up @@ -402,7 +402,7 @@ public function create($context = null, array $options = [])
unset($options['templates']);

if ($options['action'] === false || $options['url'] === false) {
$url = $this->request->here(false);
$url = $this->request->getRequestTarget();
$action = null;
} else {
$url = $this->_formUrl($context, $options);
Expand Down Expand Up @@ -481,7 +481,7 @@ public function create($context = null, array $options = [])
protected function _formUrl($context, $options)
{
if ($options['action'] === null && $options['url'] === null) {
return $this->request->here(false);
return $this->request->getRequestTarget();
}

if (is_string($options['url']) ||
Expand Down Expand Up @@ -2855,14 +2855,23 @@ public function setValueSources($sources)
*/
public function getSourceValue($fieldname, $options = [])
{
$valueMap = [
'data' => 'getData',
'query' => 'getQuery'
];
foreach ($this->getValueSources() as $valuesSource) {
if ($valuesSource === 'context') {
$val = $this->_getContext()->val($fieldname, $options);
if ($val !== null) {
return $val;
}
} elseif ($this->request->{$valuesSource}($fieldname) !== null) {
return $this->request->{$valuesSource}($fieldname);
}
if (isset($valueMap[$valuesSource])) {
$method = $valueMap[$valuesSource];
$value = $this->request->{$method}($fieldname);
if ($value !== null) {
return $value;
}
}
}

Expand Down
20 changes: 11 additions & 9 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -719,8 +719,9 @@ public function testCreateUpdateForm()
{
$encoding = strtolower(Configure::read('App.encoding'));

$this->Form->request->here = '/articles/edit/1';
$this->Form->request->params['action'] = 'edit';
$this->Form->request = $this->Form->request
->withRequestTarget('/articles/edit/1')
->withParam('action', 'edit');

$this->article['defaults']['id'] = 1;

Expand All @@ -747,9 +748,9 @@ public function testCreateAutoUrl()
{
$encoding = strtolower(Configure::read('App.encoding'));

$this->Form->request->params['action'] = 'delete';
$this->Form->request->here = '/articles/delete/10';
$this->Form->request->base = '';
$this->Form->request = $this->Form->request
->withRequestTarget('/articles/delete/10')
->withParam('action', 'delete');
$result = $this->Form->create($this->article);
$expected = [
'form' => [
Expand Down Expand Up @@ -8741,7 +8742,7 @@ public function testFormValueSourcesListSwitchRendering()
$articles = TableRegistry::get('Articles');
$article = new Article();
$articles->patchEntity($article, ['id' => '3']);
$this->Form->request->query['id'] = '9';
$this->Form->request = $this->Form->request->withQueryParams(['id' => '9']);

$this->Form->create($article);
$this->Form->setValueSources(['context', 'query']);
Expand All @@ -8765,8 +8766,9 @@ public function testFormValueSourcesListSwitchRendering()
];
$this->assertHtml($expected, $result);

$this->Form->request->data['id'] = '8';
$this->Form->request->query['id'] = '9';
$this->Form->request = $this->Form->request
->withData('id', '8')
->withQueryParams(['id' => '9']);
$this->Form->setValueSources(['data', 'query', 'context']);
$result = $this->Form->control('id');
$expected = [
Expand Down Expand Up @@ -8929,7 +8931,7 @@ public function testFormValueSourcesDefaults()
*/
public function testSourcesValueDoesntExistPassThrough()
{
$this->Form->request->query['category'] = 'sesame-cookies';
$this->Form->request = $this->Form->request->withQueryParams(['category' => 'sesame-cookies']);

$articles = TableRegistry::get('Articles');
$entity = $articles->newEntity();
Expand Down

0 comments on commit 5c879ae

Please sign in to comment.