'',
];
$this->templates = new StringTemplate($templates);
$this->context = $this->getMockBuilder('Cake\View\Form\ContextInterface')->getMock();
}
/**
* Test render in a simple case.
*
* @return void
*/
public function testRenderSimple()
{
$text = new BasicWidget($this->templates);
$result = $text->render(['name' => 'my_input'], $this->context);
$expected = [
'input' => ['type' => 'text', 'name' => 'my_input']
];
$this->assertHtml($expected, $result);
}
/**
* Test render with custom type
*
* @return void
*/
public function testRenderType()
{
$text = new BasicWidget($this->templates);
$data = [
'name' => 'my_input',
'type' => 'email',
];
$result = $text->render($data, $this->context);
$expected = [
'input' => ['type' => 'email', 'name' => 'my_input']
];
$this->assertHtml($expected, $result);
}
/**
* Test render with a value
*
* @return void
*/
public function testRenderWithValue()
{
$text = new BasicWidget($this->templates);
$data = [
'name' => 'my_input',
'type' => 'email',
'val' => 'Some '
];
$result = $text->render($data, $this->context);
$expected = [
'input' => [
'type' => 'email',
'name' => 'my_input',
'value' => 'Some <value>'
]
];
$this->assertHtml($expected, $result);
}
/**
* Test render with additional attributes.
*
* @return void
*/
public function testRenderAttributes()
{
$text = new BasicWidget($this->templates);
$data = [
'name' => 'my_input',
'type' => 'email',
'class' => 'form-control',
'required' => true
];
$result = $text->render($data, $this->context);
$expected = [
'input' => [
'type' => 'email',
'name' => 'my_input',
'class' => 'form-control',
'required' => 'required',
]
];
$this->assertHtml($expected, $result);
}
/**
* Test render with template params.
*
* @return void
*/
public function testRenderTemplateParams()
{
$text = new BasicWidget(new StringTemplate([
'input' => '{{help}}',
]));
$data = [
'name' => 'my_input',
'type' => 'email',
'class' => 'form-control',
'required' => true,
'templateVars' => ['help' => 'SOS']
];
$result = $text->render($data, $this->context);
$expected = [
'input' => [
'type' => 'email',
'name' => 'my_input',
'class' => 'form-control',
'required' => 'required',
],
'assertHtml($expected, $result);
}
}