Skip to content

Commit c3e2cb9

Browse files
committed
Create TemplateManagerTest.php
1 parent 64222b6 commit c3e2cb9

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Saaze\Tests\Templates;
4+
5+
use Saaze\Tests\TestCase;
6+
use Saaze\Interfaces\CollectionInterface;
7+
use Saaze\Interfaces\EntryManagerInterface;
8+
use Saaze\Interfaces\TemplateManagerInterface;
9+
use Saaze\Interfaces\CollectionManagerInterface;
10+
11+
class TemplateManagerTest extends TestCase
12+
{
13+
/**
14+
* @var CollectionInterface
15+
*/
16+
protected $collection;
17+
18+
/**
19+
* @var TemplateManagerInterface
20+
*/
21+
protected $templateManager;
22+
23+
public function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$collectionManager = $this->container->get(CollectionManagerInterface::class);
28+
$this->collection = $collectionManager->getCollection('posts');
29+
$this->templateManager = $this->container->get(TemplateManagerInterface::class);
30+
}
31+
32+
public function testRenderCollection()
33+
{
34+
$html = $this->templateManager->renderCollection($this->collection, 1);
35+
36+
$this->assertStringContainsString('<h2><a href="/blog/example-post-1">Hello World 1</a></h2>', $html);
37+
$this->assertStringContainsString('<a href="/blog/page/2">&larr; Older</a>', $html);
38+
$this->assertStringNotContainsString('Hello World 11', $html);
39+
$this->assertStringNotContainsString('Newer &rarr;', $html);
40+
41+
$html = $this->templateManager->renderCollection($this->collection, 2);
42+
43+
$this->assertStringContainsString('<h2><a href="/blog/example-post-11">Hello World 11</a></h2>', $html);
44+
$this->assertStringContainsString('<a href="/blog/page/1">Newer &rarr;</a>', $html);
45+
$this->assertStringNotContainsString('Hello World 5', $html);
46+
$this->assertStringNotContainsString('&larr; Older', $html);
47+
}
48+
49+
public function testRenderEntry()
50+
{
51+
$entryManager = $this->container->get(EntryManagerInterface::class);
52+
$entryManager->setCollection($this->collection);
53+
$entry = $entryManager->getEntry('example-post-1');
54+
55+
$html = $this->templateManager->renderEntry($entry);
56+
57+
$this->assertStringContainsString('<h1>Hello World 1</h1>', $html);
58+
$this->assertStringContainsString('<p><strong>Lorem ipsum</strong> <em>dolor</em> sit amet.</p>', $html);
59+
}
60+
61+
public function testRenderError()
62+
{
63+
$html = $this->templateManager->renderError('Not Found', 404);
64+
65+
$this->assertStringContainsString('<h1>404</h1>', $html);
66+
$this->assertStringContainsString('<div>Not Found</div>', $html);
67+
}
68+
}

0 commit comments

Comments
 (0)