Skip to content

Commit 2fbb4b6

Browse files
Added a template parser test
1 parent cef544a commit 2fbb4b6

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/ParserTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Coreplex\Notifier\Tests;
4+
5+
class ParserTest extends BaseTest
6+
{
7+
public function testParseReturnsString()
8+
{
9+
$parser = $this->parser();
10+
$template = 'hello world';
11+
12+
$this->assertInternalType('string', $parser->parse($template));
13+
}
14+
15+
public function testParserReplacesPlaceholders()
16+
{
17+
$parser = $this->parser();
18+
$template = '{{ foo }} [if:baz] {{ baz }} [endif]';
19+
$parsed = $parser->parse($template, [
20+
'foo' => 'bar',
21+
'baz' => 'qux'
22+
]);
23+
24+
$this->assertContains('bar', $parsed);
25+
$this->assertContains('qux', $parsed);
26+
}
27+
28+
public function testIfStatementsAreRemovedIfReplacementIsNotSet()
29+
{
30+
$parser = $this->parser();
31+
$template = '{{ foo }} [if:baz] {{ baz }} [endif]';
32+
$parsed = $parser->parse($template, [
33+
'foo' => 'bar',
34+
]);
35+
36+
$this->assertContains('bar', $parsed);
37+
$this->assertNotContains('qux', $parsed);
38+
}
39+
}

0 commit comments

Comments
 (0)