Skip to content

Commit

Permalink
Adding ability to pass templateVars to Form->create()
Browse files Browse the repository at this point in the history
Adding test for Form->create() templateVars

Simplifying test for Form->create() templateVars

Spacing for stickler-ci
  • Loading branch information
NickBusey committed Sep 2, 2016
1 parent c214ede commit 28ca77b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -435,7 +435,8 @@ public function create($model = null, array $options = [])
$actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);

return $this->formatTemplate('formStart', [
'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr
'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr,
'templateVars' => isset($options['templateVars']) ? $options['templateVars'] : []
]) . $append;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -654,6 +654,32 @@ public function testCreateTypeOptions($type, $method, $override)
$this->assertHtml($expected, $result);
}

/**
* Test using template vars in Create (formStart template)
*
* @return void
*/
public function testCreateTemplateVars()
{
$result = $this->Form->create($this->article, [
'templates' => [
'formStart' => '<h4 class="mb">{{header}}</h4><form{{attrs}}>',
],
'templateVars' => ['header' => 'headertext']
]);
$expected = [
'h4' => ['class'],
'headertext',
'/h4',
'form' => [
'method' => 'post',
'action' => '/articles/add',
'accept-charset' => 'utf-8'
]
];
$this->assertHtml($expected, $result);
}

/**
* Test opening a form for an update operation.
*
Expand Down

0 comments on commit 28ca77b

Please sign in to comment.