Skip to content
Snippets Groups Projects
Commit d5986371 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Use TemplateTest from test-framework

parent 7fc5a63d
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
bootstrap="./tests/bootstrap.php"> bootstrap="./tests/bootstrap.php">
<testsuites> <testsuites>
<testsuite name="Unit tests"> <testsuite name="Unit tests">
<directory>./tests/</directory> <directory>./vendor/simplesamlphp/simplesamlphp-test-framework/src</directory>
<directory>./tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
......
<?php
namespace SimpleSAML\Test\Web;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Configuration;
use SimpleSAML\XHTML\Template;
use SimpleSAML\Module;
use Twig\Error\SyntaxError;
/**
* Simple test for syntax-checking Twig-templates.
*
* @author Tim van Dijen <tvdijen@gmail.com>
* @package SimpleSAMLphp
*/
class TemplateTest extends TestCase
{
/**
* @return void
*/
public function testSyntax()
{
$config = Configuration::loadFromArray([
'usenewui' => true,
'module.enable' => array_fill_keys(Module::getModules(), true),
]);
Configuration::setPreLoadedConfig($config);
$basedir = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'templates';
// Base templates
$files = array_diff(scandir($basedir), ['.', '..']);
foreach ($files as $file) {
if (preg_match('/.twig$/', $file)) {
$t = new Template($config, $file);
ob_start();
try {
$t->show();
$this->addToAssertionCount(1);
} catch (SyntaxError $e) {
$this->fail($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine());
}
ob_end_clean();
}
}
// Module templates
foreach (Module::getModules() as $module) {
$basedir = Module::getModuleDir($module) . DIRECTORY_SEPARATOR . 'templates';
if (file_exists($basedir)) {
$files = array_diff(scandir($basedir), ['.', '..']);
foreach ($files as $file) {
if (preg_match('/.twig$/', $file)) {
$t = new Template($config, $module . ':' . $file);
ob_start();
try {
$t->show();
$this->addToAssertionCount(1);
} catch (SyntaxError $e) {
$this->fail($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine());
}
ob_end_clean();
}
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment