StringTemplateTraitTest.php 2.9 KB

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