TextareaTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Widget;
  16. use Cake\TestSuite\TestCase;
  17. use Cake\View\StringTemplate;
  18. use Cake\View\Widget\Textarea;
  19. /**
  20. * Textarea input test.
  21. */
  22. class TextareaTest extends TestCase {
  23. /**
  24. * setup
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. $templates = [
  31. 'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
  32. ];
  33. $this->context = $this->getMock('Cake\View\Form\ContextInterface');
  34. $this->templates = new StringTemplate($templates);
  35. }
  36. /**
  37. * Test render in a simple case.
  38. *
  39. * @return void
  40. */
  41. public function testRenderSimple() {
  42. $input = new Textarea($this->templates);
  43. $result = $input->render(['name' => 'comment'], $this->context);
  44. $expected = [
  45. 'textarea' => ['name' => 'comment'],
  46. '/textarea',
  47. ];
  48. $this->assertTags($result, $expected);
  49. }
  50. /**
  51. * Test render with a value
  52. *
  53. * @return void
  54. */
  55. public function testRenderWithValue() {
  56. $input = new Textarea($this->templates);
  57. $data = ['name' => 'comment', 'data-foo' => '<val>', 'val' => 'some <html>'];
  58. $result = $input->render($data, $this->context);
  59. $expected = [
  60. 'textarea' => ['name' => 'comment', 'data-foo' => '&lt;val&gt;'],
  61. 'some &lt;html&gt;',
  62. '/textarea',
  63. ];
  64. $this->assertTags($result, $expected);
  65. $data['escape'] = false;
  66. $result = $input->render($data, $this->context);
  67. $expected = [
  68. 'textarea' => ['name' => 'comment', 'data-foo' => '<val>'],
  69. 'some <html>',
  70. '/textarea',
  71. ];
  72. $this->assertTags($result, $expected);
  73. }
  74. }