File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments