Skip to content

Commit

Permalink
Use templateParams in BasicWidget.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 28, 2015
1 parent 25bcfaa commit 4d33d69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/View/Widget/BasicWidget.php
Expand Up @@ -66,13 +66,15 @@ public function render(array $data, ContextInterface $context)
'val' => null,
'type' => 'text',
'escape' => true,
'templateParams' => []
];
$data['value'] = $data['val'];
unset($data['val']);

return $this->_templates->format('input', [
'name' => $data['name'],
'type' => $data['type'],
'templateParams' => $data['templateParams'],
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type']
Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase/View/Widget/BasicWidgetTest.php
Expand Up @@ -117,4 +117,34 @@ public function testRenderAttributes()
];
$this->assertHtml($expected, $result);
}

/**
* Test render with template params.
*
* @return void
*/
public function testRenderTemplateParams()
{
$text = new BasicWidget(new StringTemplate([
'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}><span>{{help}}</span>',
]));
$data = [
'name' => 'my_input',
'type' => 'email',
'class' => 'form-control',
'required' => true,
'templateParams' => ['help' => 'SOS']
];
$result = $text->render($data, $this->context);
$expected = [
'input' => [
'type' => 'email',
'name' => 'my_input',
'class' => 'form-control',
'required' => 'required',
],
'<span', 'SOS', '/span'
];
$this->assertHtml($expected, $result);
}
}

0 comments on commit 4d33d69

Please sign in to comment.