TemplateTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Codeception\Util;
  3. class TemplateTest extends \PHPUnit\Framework\TestCase
  4. {
  5. public function testTemplateCanPassValues()
  6. {
  7. $template = new Template("hello, {{name}}");
  8. $template->place('name', 'davert');
  9. $this->assertEquals('hello, davert', $template->produce());
  10. }
  11. public function testTemplateCanHaveOtherPlaceholder()
  12. {
  13. $template = new Template("hello, %name%", '%', '%');
  14. $template->place('name', 'davert');
  15. $this->assertEquals('hello, davert', $template->produce());
  16. }
  17. public function testTemplateSupportsDotNotationForArrays()
  18. {
  19. $template = new Template("hello, {{user.data.name}}");
  20. $template->place('user', ['data' => ['name' => 'davert']]);
  21. $this->assertEquals('hello, davert', $template->produce());
  22. }
  23. public function testShouldSkipUnmatchedPlaceholder()
  24. {
  25. $template = new Template("hello, {{name}}");
  26. $this->assertEquals('hello, {{name}}', $template->produce());
  27. }
  28. }