StringTemplateTraitTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 CakePHP(tm) v 3.0.0
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\TestSuite\TestCase;
  17. use Cake\View\Helper\StringTemplate;
  18. use Cake\View\Helper\StringTemplateTrait;
  19. /**
  20. * StringTemplateTraitTest class
  21. *
  22. */
  23. class StringTemplateTraitTest extends TestCase {
  24. /**
  25. * setUp method
  26. *
  27. * @return void
  28. */
  29. public function setUp() {
  30. parent::setUp();
  31. $this->Template = $this->getObjectForTrait('\Cake\View\Helper\StringTemplateTrait');
  32. }
  33. /**
  34. * testInitStringTemplates
  35. *
  36. * @return void
  37. */
  38. public function testInitStringTemplates() {
  39. $templates = [
  40. 'text' => '<p>{{text}}</p>',
  41. ];
  42. $this->Template->initStringTemplates($templates);
  43. $result = $this->Template->templates(null);
  44. $this->assertEquals($result, [
  45. 'attribute' => '{{name}}="{{value}}"',
  46. 'compactAttribute' => '{{name}}="{{value}}"',
  47. 'text' => '<p>{{text}}</p>'
  48. ]);
  49. }
  50. /**
  51. * test settings['templates']
  52. *
  53. * @return void
  54. */
  55. public function testInitStringTemplatesArrayForm() {
  56. $this->Template->settings['templates'] = [
  57. 'text' => '<p>{{text}}</p>',
  58. ];
  59. $this->Template->initStringTemplates();
  60. $result = $this->Template->templates(null);
  61. $this->assertEquals($result, [
  62. 'attribute' => '{{name}}="{{value}}"',
  63. 'compactAttribute' => '{{name}}="{{value}}"',
  64. 'text' => '<p>{{text}}</p>'
  65. ]);
  66. }
  67. /**
  68. * testFormatStringTemplate
  69. *
  70. * @return void
  71. */
  72. public function testFormatStringTemplate() {
  73. $templates = [
  74. 'text' => '<p>{{text}}</p>',
  75. ];
  76. $this->Template->initStringTemplates($templates);
  77. $result = $this->Template->formatTemplate('text', [
  78. 'text' => 'CakePHP'
  79. ]);
  80. $this->assertEquals($result, '<p>CakePHP</p>');
  81. }
  82. /**
  83. * testGetTemplater
  84. *
  85. * @return void
  86. */
  87. public function testGetTemplater() {
  88. $templates = [
  89. 'text' => '<p>{{text}}</p>',
  90. ];
  91. $this->Template->initStringTemplates($templates);
  92. $result = $this->Template->getTemplater();
  93. $this->assertInstanceOf('\Cake\View\StringTemplate', $result);
  94. }
  95. }