0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-05-05 09:40:08 +00:00
kevinpapst_kimai2/tests/Twig/RuntimeExtensionsTest.php
Kevin Papst 8069e332fe
release 2.0 beta (#3722)
* remove twitter link
* remove WIP file
* adjust release draft message
* reset code coverage threshold back to 0.5
* changed wordings
* re-activate wizard for fixture accounts
* fix repo url and license
* license identifier
* bump version
* moved Kimai 1 import command from core to plugin
* do not traverse into invoice template subdirectories (#3735)
* fix branch alias
* composer update
* switch language on wizard select
* new twig function to create qr code
* fix daily stats in timesheet listing
* improved html invoice templates
2023-01-12 12:10:11 +01:00

106 lines
3.3 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Twig;
use App\Twig\RuntimeExtensions;
use PHPUnit\Framework\TestCase;
use Twig\Node\Node;
use Twig\TwigFilter;
use Twig\TwigFunction;
/**
* @covers \App\Twig\RuntimeExtensions
*/
class RuntimeExtensionsTest extends TestCase
{
public function testGetFilters()
{
$expected = ['md2html', 'desc2html', 'comment2html', 'comment1line', 'colorize', 'icon'];
$i = 0;
$sut = new RuntimeExtensions();
$twigFilters = $sut->getFilters();
$this->assertCount(\count($expected), $twigFilters);
foreach ($twigFilters as $filter) {
$this->assertInstanceOf(TwigFilter::class, $filter);
$this->assertEquals($expected[$i++], $filter->getName());
}
}
public function testGetFunctions()
{
$expected = [
'trigger',
'actions',
'get_title',
'progressbar_color',
'javascript_translations',
'form_time_presets',
'active_timesheets',
'favorite_timesheets',
'encore_entry_css_source',
'render_widget',
'icon',
'qr_code_data_uri',
];
$i = 0;
$sut = new RuntimeExtensions();
$twigFunctions = $sut->getFunctions();
$this->assertCount(\count($expected), $twigFunctions);
/** @var TwigFunction $filter */
foreach ($twigFunctions as $filter) {
$this->assertInstanceOf(TwigFunction::class, $filter);
$this->assertEquals($expected[$i++], $filter->getName());
}
}
public function testGetFilterDefinition()
{
$sut = new RuntimeExtensions();
$filters = $sut->getFilters();
$found_md2html = false;
$found_desc2html = false;
$found_comment2html = false;
$found_comment1line = false;
foreach ($filters as $filter) {
switch ($filter->getName()) {
case 'md2html':
self::assertEquals('html', $filters[0]->getPreEscape());
self::assertEquals(['html'], $filters[0]->getSafe(new Node()));
$found_md2html = true;
break;
case 'desc2html':
self::assertEquals(['html'], $filters[1]->getSafe(new Node()));
$found_desc2html = true;
break;
case 'comment2html':
self::assertEquals(['html'], $filters[2]->getSafe(new Node()));
$found_comment2html = true;
break;
case 'comment1line':
self::assertEquals('html', $filters[3]->getPreEscape());
self::assertEquals(['html'], $filters[3]->getSafe(new Node()));
$found_comment1line = true;
break;
}
}
self::assertTrue($found_md2html, 'Missing filter: md2html');
self::assertTrue($found_desc2html, 'Missing filter: desc2html');
self::assertTrue($found_comment2html, 'Missing filter: comment2html');
self::assertTrue($found_comment1line, 'Missing filter: comment1line');
}
}