StringTemplateTraitTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View;
  16. use Cake\Core\InstanceConfigTrait;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\View\StringTemplateTrait;
  19. /**
  20. * TestStringTemplate
  21. */
  22. class TestStringTemplate
  23. {
  24. use InstanceConfigTrait;
  25. use StringTemplateTrait;
  26. /**
  27. * _defaultConfig
  28. *
  29. * @var array
  30. */
  31. protected $_defaultConfig = [];
  32. }
  33. /**
  34. * StringTemplateTraitTest class
  35. */
  36. class StringTemplateTraitTest extends TestCase
  37. {
  38. /**
  39. * @var TestStringTemplate
  40. */
  41. public $Template;
  42. /**
  43. * setUp method
  44. *
  45. * @return void
  46. */
  47. public function setUp()
  48. {
  49. parent::setUp();
  50. $this->Template = new TestStringTemplate;
  51. }
  52. /**
  53. * testInitStringTemplates
  54. *
  55. * @return void
  56. */
  57. public function testInitStringTemplates()
  58. {
  59. $templates = [
  60. 'text' => '<p>{{text}}</p>',
  61. ];
  62. $this->Template->setTemplates($templates);
  63. $this->assertEquals(
  64. [
  65. 'text' => '<p>{{text}}</p>'
  66. ],
  67. $this->Template->getTemplates(),
  68. 'newly added template should be included in template list'
  69. );
  70. }
  71. /**
  72. * test settings['templates']
  73. *
  74. * @return void
  75. */
  76. public function testInitStringTemplatesArrayForm()
  77. {
  78. $this->Template->setConfig(
  79. 'templates.text',
  80. '<p>{{text}}</p>'
  81. );
  82. $this->assertEquals(
  83. [
  84. 'text' => '<p>{{text}}</p>'
  85. ],
  86. $this->Template->getTemplates(),
  87. 'Configured templates should be included in template list'
  88. );
  89. }
  90. /**
  91. * testFormatStringTemplate
  92. *
  93. * @return void
  94. */
  95. public function testFormatStringTemplate()
  96. {
  97. $templates = [
  98. 'text' => '<p>{{text}}</p>',
  99. ];
  100. $this->Template->setTemplates($templates);
  101. $result = $this->Template->formatTemplate('text', [
  102. 'text' => 'CakePHP'
  103. ]);
  104. $this->assertEquals(
  105. '<p>CakePHP</p>',
  106. $result
  107. );
  108. }
  109. /**
  110. * testGetTemplater
  111. *
  112. * @return void
  113. */
  114. public function testGetTemplater()
  115. {
  116. $templates = [
  117. 'text' => '<p>{{text}}</p>',
  118. ];
  119. $this->Template->setTemplates($templates);
  120. $result = $this->Template->templater();
  121. $this->assertInstanceOf('Cake\View\StringTemplate', $result);
  122. }
  123. }