2017-09-19 23:55:24 +02:00
|
|
|
<?php
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Renderer;
|
2017-09-19 23:55:24 +02:00
|
|
|
|
|
|
|
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();
|
2018-12-03 23:39:50 +01:00
|
|
|
$engine->share('shared_data', 'tester');
|
2017-09-19 23:55:24 +02:00
|
|
|
|
2018-12-03 23:39:50 +01:00
|
|
|
$file = $this->createTempFile('<div>%main_content% is a %shared_data%</div>');
|
2017-09-19 23:55:24 +02:00
|
|
|
|
|
|
|
$data = $engine->get($file, ['main_content' => 'Lorem ipsum dolor sit']);
|
2018-12-03 23:39:50 +01:00
|
|
|
$this->assertEquals('<div>Lorem ipsum dolor sit is a tester</div>', $data);
|
2017-09-19 23:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
/**
|
|
|
|
* Remove files
|
|
|
|
*/
|
|
|
|
protected function tearDown(): void
|
2017-09-19 23:55:24 +02:00
|
|
|
{
|
|
|
|
foreach ($this->tmpFileNames as $fileName) {
|
|
|
|
unlink($fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|