Skip to content

Commit 82bc6a4

Browse files
authored
Create TemplateTest.php
1 parent 41eca79 commit 82bc6a4

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/www/TemplateTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Simple test for syntax-checking Twig-templates.
4+
*
5+
* @author Tim van Dijen <tvdijen@gmail.com>
6+
* @package SimpleSAMLphp
7+
*/
8+
9+
namespace SimpleSAML\Test\Web;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use SimpleSAML\Configuration;
13+
use SimpleSAML\XHTML\Template;
14+
use SimpleSAML\Module;
15+
use Twig\Error\SyntaxError;
16+
17+
class TemplateTest extends TestCase
18+
{
19+
public function testSyntax()
20+
{
21+
$config = Configuration::loadFromArray([
22+
'language.i18n.backend' => 'gettext/gettext',
23+
'module.enable' => array_fill_keys(Module::getModules(), true),
24+
]);
25+
26+
Configuration::setPreLoadedConfig($config);
27+
$basedir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'templates';
28+
29+
// Base templates
30+
$files = array_diff(scandir($basedir), ['.', '..']);
31+
foreach ($files as $file) {
32+
if (preg_match('/.twig$/', $file)) {
33+
$t = new Template($config, 'adfs:'.basename($file));
34+
ob_start();
35+
try {
36+
$t->show();
37+
$this->addToAssertionCount(1);
38+
} catch (SyntaxError $e) {
39+
$this->fail($e->getMessage().' in '.$e->getFile().':'.$e->getLine());
40+
}
41+
ob_end_clean();
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)