'',
];
$this->context = $this->getMockBuilder('Cake\View\Form\ContextInterface')->getMock();
$this->templates = new StringTemplate($templates);
}
/**
* Test render in a simple case.
*
* @return void
*/
public function testRenderSimple()
{
$input = new TextareaWidget($this->templates);
$result = $input->render(['name' => 'comment'], $this->context);
$expected = [
'textarea' => ['name' => 'comment', 'rows' => 5],
'/textarea',
];
$this->assertHtml($expected, $result);
}
/**
* Test render with a value
*
* @return void
*/
public function testRenderWithValue()
{
$input = new TextareaWidget($this->templates);
$data = ['name' => 'comment', 'data-foo' => '', 'val' => 'some '];
$result = $input->render($data, $this->context);
$expected = [
'textarea' => ['name' => 'comment', 'rows' => 5, 'data-foo' => '<val>'],
'some <html>',
'/textarea',
];
$this->assertHtml($expected, $result);
$data['escape'] = false;
$result = $input->render($data, $this->context);
$expected = [
'textarea' => ['name' => 'comment', 'rows' => 5, 'data-foo' => ''],
'some ',
'/textarea',
];
$this->assertHtml($expected, $result);
}
/**
* Ensure templateVars option is hooked up.
*
* @return void
*/
public function testRenderTemplateVars()
{
$this->templates->add([
'textarea' => '',
]);
$input = new TextareaWidget($this->templates);
$data = [
'templateVars' => ['custom' => 'value'],
'name' => 'comment',
'val' => 'body'
];
$result = $input->render($data, $this->context);
$expected = [
'textarea' => ['name' => 'comment', 'rows' => 5, 'custom' => 'value'],
'body',
'/textarea',
];
$this->assertHtml($expected, $result);
}
}