LabelWidgetTest.php 2.7 KB

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