LabelTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }
  35. /**
  36. * test render
  37. *
  38. * @return void
  39. */
  40. public function testRender() {
  41. $label = new Label($this->templates);
  42. $data = [
  43. 'text' => 'My text',
  44. ];
  45. $result = $label->render($data);
  46. $expected = [
  47. 'label' => [],
  48. 'My text',
  49. '/label'
  50. ];
  51. $this->assertTags($result, $expected);
  52. }
  53. /**
  54. * test render escape
  55. *
  56. * @return void
  57. */
  58. public function testRenderEscape() {
  59. $label = new Label($this->templates);
  60. $data = [
  61. 'text' => 'My > text',
  62. 'for' => 'Some > value',
  63. 'escape' => false,
  64. ];
  65. $result = $label->render($data);
  66. $expected = [
  67. 'label' => ['for' => 'Some > value'],
  68. 'My > text',
  69. '/label'
  70. ];
  71. $this->assertTags($result, $expected);
  72. }
  73. /**
  74. * test render escape
  75. *
  76. * @return void
  77. */
  78. public function testRenderAttributes() {
  79. $label = new Label($this->templates);
  80. $data = [
  81. 'text' => 'My > text',
  82. 'for' => 'some-id',
  83. 'id' => 'some-id',
  84. 'data-foo' => 'value',
  85. ];
  86. $result = $label->render($data);
  87. $expected = [
  88. 'label' => ['id' => 'some-id', 'data-foo' => 'value', 'for' => 'some-id'],
  89. 'My &gt; text',
  90. '/label'
  91. ];
  92. $this->assertTags($result, $expected);
  93. }
  94. }