/**
  * Test render with a value
  *
  * @return void
  */
 public function testRenderWithValue()
 {
     $input = new TextareaWidget($this->templates);
     $data = ['name' => 'comment', 'data-foo' => '<val>', 'val' => 'some <html>'];
     $result = $input->render($data, $this->context);
     $expected = ['textarea' => ['name' => 'comment', 'data-foo' => '&lt;val&gt;'], 'some &lt;html&gt;', '/textarea'];
     $this->assertHtml($expected, $result);
     $data['escape'] = false;
     $result = $input->render($data, $this->context);
     $expected = ['textarea' => ['name' => 'comment', 'data-foo' => '<val>'], 'some <html>', '/textarea'];
     $this->assertHtml($expected, $result);
 }
 /**
  * Ensure templateVars option is hooked up.
  *
  * @return void
  */
 public function testRenderTemplateVars()
 {
     $this->templates->add(['textarea' => '<textarea custom="{{custom}}" name="{{name}}"{{attrs}}>{{value}}</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);
 }
 /**
  * @see Cake\View\Widget\Checkbox::render();
  */
 public function render(array $data, ContextInterface $context)
 {
     $labelData['text'] = $data['label'];
     $label = $this->_label->render($labelData, $context);
     unset($data['label']);
     if (!isset($data['class'])) {
         $data['class'] = '';
     }
     if (!isset($data['rows'])) {
         $data['rows'] = 5;
     }
     $data['class'] .= ' form-control';
     $textarea = parent::render($data, $context);
     return $this->_templates->format('textareaWrapper', ['input' => $textarea, 'label' => $label]);
 }
示例#4
0
 /**
  * Render a text area form widget.
  *
  * Data supports the following keys:
  *
  * - `name` - Set the input name.
  * - `val` - A string of the option to mark as selected.
  * - `escape` - Set to false to disable HTML escaping.
  *
  * All other keys will be converted into HTML attributes.
  *
  * @param array $data The data to build a textarea with.
  * @param \Cake\View\Form\ContextInterface $context The current form context.
  * @return string HTML elements.
  */
 public function render(array $data, ContextInterface $context)
 {
     $data = $this->injectClasses('form-control', $data);
     return parent::render($data, $context);
 }