LabelTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Label;
  19. /**
  20. * Label test case.
  21. */
  22. class LabelTest extends TestCase {
  23. /**
  24. * setup method.
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. $templates = [
  31. 'label' => '<label{{attrs}}>{{text}}</label>',
  32. ];
  33. $this->templates = new StringTemplate($templates);
  34. $this->context = $this->getMock('Cake\View\Form\ContextInterface');
  35. }
  36. /**
  37. * test render
  38. *
  39. * @return void
  40. */
  41. public function testRender() {
  42. $label = new Label($this->templates);
  43. $data = [
  44. 'text' => 'My text',
  45. ];
  46. $result = $label->render($data, $this->context);
  47. $expected = [
  48. 'label' => [],
  49. 'My text',
  50. '/label'
  51. ];
  52. $this->assertTags($result, $expected);
  53. }
  54. /**
  55. * test render escape
  56. *
  57. * @return void
  58. */
  59. public function testRenderEscape() {
  60. $label = new Label($this->templates);
  61. $data = [
  62. 'text' => 'My > text',
  63. 'for' => 'Some > value',
  64. 'escape' => false,
  65. ];
  66. $result = $label->render($data, $this->context);
  67. $expected = [
  68. 'label' => ['for' => 'Some > value'],
  69. 'My > text',
  70. '/label'
  71. ];
  72. $this->assertTags($result, $expected);
  73. }
  74. /**
  75. * test render escape
  76. *
  77. * @return void
  78. */
  79. public function testRenderAttributes() {
  80. $label = new Label($this->templates);
  81. $data = [
  82. 'text' => 'My > text',
  83. 'for' => 'some-id',
  84. 'id' => 'some-id',
  85. 'data-foo' => 'value',
  86. ];
  87. $result = $label->render($data, $this->context);
  88. $expected = [
  89. 'label' => ['id' => 'some-id', 'data-foo' => 'value', 'for' => 'some-id'],
  90. 'My &gt; text',
  91. '/label'
  92. ];
  93. $this->assertTags($result, $expected);
  94. }
  95. }