StringTemplateTraitTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\View;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\View\StringTemplate;
  19. use TestApp\View\TestStringTemplate;
  20. /**
  21. * StringTemplateTraitTest class
  22. */
  23. class StringTemplateTraitTest extends TestCase
  24. {
  25. /**
  26. * @var \TestApp\View\TestStringTemplate
  27. */
  28. protected $Template;
  29. /**
  30. * setUp method
  31. *
  32. * @return void
  33. */
  34. public function setUp(): void
  35. {
  36. parent::setUp();
  37. $this->Template = new TestStringTemplate();
  38. }
  39. /**
  40. * testInitStringTemplates
  41. *
  42. * @return void
  43. */
  44. public function testInitStringTemplates()
  45. {
  46. $templates = [
  47. 'text' => '<p>{{text}}</p>',
  48. ];
  49. $this->Template->setTemplates($templates);
  50. $this->assertEquals(
  51. [
  52. 'text' => '<p>{{text}}</p>',
  53. ],
  54. $this->Template->getTemplates(),
  55. 'newly added template should be included in template list'
  56. );
  57. }
  58. /**
  59. * test settings['templates']
  60. *
  61. * @return void
  62. */
  63. public function testInitStringTemplatesArrayForm()
  64. {
  65. $this->Template->setConfig(
  66. 'templates.text',
  67. '<p>{{text}}</p>'
  68. );
  69. $this->assertEquals(
  70. [
  71. 'text' => '<p>{{text}}</p>',
  72. ],
  73. $this->Template->getTemplates(),
  74. 'Configured templates should be included in template list'
  75. );
  76. }
  77. /**
  78. * testFormatStringTemplate
  79. *
  80. * @return void
  81. */
  82. public function testFormatStringTemplate()
  83. {
  84. $templates = [
  85. 'text' => '<p>{{text}}</p>',
  86. ];
  87. $this->Template->setTemplates($templates);
  88. $result = $this->Template->formatTemplate('text', [
  89. 'text' => 'CakePHP',
  90. ]);
  91. $this->assertEquals(
  92. '<p>CakePHP</p>',
  93. $result
  94. );
  95. }
  96. /**
  97. * testGetTemplater
  98. *
  99. * @return void
  100. */
  101. public function testGetTemplater()
  102. {
  103. $templates = [
  104. 'text' => '<p>{{text}}</p>',
  105. ];
  106. $this->Template->setTemplates($templates);
  107. $result = $this->Template->templater();
  108. $this->assertInstanceOf(StringTemplate::class, $result);
  109. }
  110. }