StringTemplateTraitTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 CakePHP(tm) v 3.0.0
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\TestSuite\TestCase;
  17. use Cake\View\Helper\StringTemplate;
  18. use Cake\View\Helper\StringTemplateTrait;
  19. /**
  20. * StringTemplateTraitTest class
  21. *
  22. */
  23. class StringTemplateTraitTest extends TestCase {
  24. /**
  25. * setUp method
  26. *
  27. * @return void
  28. */
  29. public function setUp() {
  30. parent::setUp();
  31. $this->Template = $this->getObjectForTrait('\Cake\View\Helper\StringTemplateTrait');
  32. }
  33. /**
  34. * testInitStringTemplates
  35. *
  36. * @return void
  37. */
  38. public function testInitStringTemplates() {
  39. $templates = [
  40. 'text' => '<p>{{text}}</p>',
  41. ];
  42. $this->Template->initStringTemplates($templates);
  43. $result = $this->Template->templates(null);
  44. $this->assertEquals($result, [
  45. 'attribute' => '{{name}}="{{value}}"',
  46. 'compactAttribute' => '{{name}}="{{value}}"',
  47. 'text' => '<p>{{text}}</p>'
  48. ]);
  49. }
  50. /**
  51. * testFormatStringTemplate
  52. *
  53. * @return void
  54. */
  55. public function testFormatStringTemplate() {
  56. $templates = [
  57. 'text' => '<p>{{text}}</p>',
  58. ];
  59. $this->Template->initStringTemplates($templates);
  60. $result = $this->Template->formatTemplate('text', [
  61. 'text' => 'CakePHP'
  62. ]);
  63. $this->assertEquals($result, '<p>CakePHP</p>');
  64. }
  65. /**
  66. * testGetTemplater
  67. *
  68. * @return void
  69. */
  70. public function testGetTemplater() {
  71. $templates = [
  72. 'text' => '<p>{{text}}</p>',
  73. ];
  74. $this->Template->initStringTemplates($templates);
  75. $result = $this->Template->getTemplater();
  76. $this->assertInstanceOf('\Cake\View\StringTemplate', $result);
  77. }
  78. }