StringTemplateTraitTest.php 2.5 KB

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