blob: 4a31e4bc51bc6d20e88d4dc3a752ee4452b8944f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
namespace Engelsystem\Test\Unit\Renderer;
use Engelsystem\Renderer\HtmlEngine;
use PHPUnit\Framework\TestCase;
class HtmlEngineTest extends TestCase
{
/** @var string[] */
protected $tmpFileNames = [];
/**
* @covers \Engelsystem\Renderer\HtmlEngine::get
*/
public function testGet()
{
$engine = new HtmlEngine();
$file = $this->createTempFile('<div>%main_content%</div>');
$data = $engine->get($file, ['main_content' => 'Lorem ipsum dolor sit']);
$this->assertEquals('<div>Lorem ipsum dolor sit</div>', $data);
}
/**
* @covers \Engelsystem\Renderer\HtmlEngine::canRender
*/
public function testCanRender()
{
$engine = new HtmlEngine();
$this->assertFalse($engine->canRender('/dev/null'));
$file = $this->createTempFile();
$this->assertTrue($engine->canRender($file));
$htmFile = $this->createTempFile('', '.htm');
$this->assertTrue($engine->canRender($htmFile));
}
/**
* @param string $content
* @param string $extension
* @return string
*/
protected function createTempFile($content = '', $extension = '.html')
{
$tmpFileName = tempnam(sys_get_temp_dir(), 'EngelsystemUnitTest');
$fileName = $tmpFileName . $extension;
rename($tmpFileName, $fileName);
file_put_contents($fileName, $content);
$this->tmpFileNames[] = $fileName;
return $fileName;
}
/**
* Remove files
*/
protected function tearDown(): void
{
foreach ($this->tmpFileNames as $fileName) {
unlink($fileName);
}
}
}
|