StringTemplateTraitTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\Helper;
  16. use Cake\Core\InstanceConfigTrait;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\View\Helper\StringTemplate;
  19. use Cake\View\Helper\StringTemplateTrait;
  20. /**
  21. * TestStringTemplate
  22. *
  23. */
  24. class TestStringTemplate {
  25. use InstanceConfigTrait;
  26. use StringTemplateTrait;
  27. /**
  28. * _defaultConfig
  29. *
  30. * @var array
  31. */
  32. protected $_defaultConfig = [];
  33. }
  34. /**
  35. * StringTemplateTraitTest class
  36. *
  37. */
  38. class StringTemplateTraitTest extends TestCase {
  39. /**
  40. * setUp method
  41. *
  42. * @return void
  43. */
  44. public function setUp() {
  45. parent::setUp();
  46. $this->Template = new TestStringTemplate;
  47. }
  48. /**
  49. * testInitStringTemplates
  50. *
  51. * @return void
  52. */
  53. public function testInitStringTemplates() {
  54. $templates = [
  55. 'text' => '<p>{{text}}</p>',
  56. ];
  57. $this->Template->templates($templates);
  58. $this->assertEquals(
  59. [
  60. 'text' => '<p>{{text}}</p>'
  61. ],
  62. $this->Template->templates(),
  63. 'newly added template should be included in template list'
  64. );
  65. }
  66. /**
  67. * test settings['templates']
  68. *
  69. * @return void
  70. */
  71. public function testInitStringTemplatesArrayForm() {
  72. $this->Template->config(
  73. 'templates.text',
  74. '<p>{{text}}</p>'
  75. );
  76. $this->assertEquals(
  77. [
  78. 'text' => '<p>{{text}}</p>'
  79. ],
  80. $this->Template->templates(),
  81. 'Configured templates should be included in template list'
  82. );
  83. }
  84. /**
  85. * testFormatStringTemplate
  86. *
  87. * @return void
  88. */
  89. public function testFormatStringTemplate() {
  90. $templates = [
  91. 'text' => '<p>{{text}}</p>',
  92. ];
  93. $this->Template->templates($templates);
  94. $result = $this->Template->formatTemplate('text', [
  95. 'text' => 'CakePHP'
  96. ]);
  97. $this->assertEquals(
  98. '<p>CakePHP</p>',
  99. $result
  100. );
  101. }
  102. /**
  103. * testGetTemplater
  104. *
  105. * @return void
  106. */
  107. public function testGetTemplater() {
  108. $templates = [
  109. 'text' => '<p>{{text}}</p>',
  110. ];
  111. $this->Template->templates($templates);
  112. $result = $this->Template->templater();
  113. $this->assertInstanceOf('\Cake\View\StringTemplate', $result);
  114. }
  115. }