StringTemplateTraitTest.php 2.9 KB

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