diff --git a/templates/quiz/nav.html.twig b/templates/quiz/nav.html.twig new file mode 100644 index 0000000..db2eee8 --- /dev/null +++ b/templates/quiz/nav.html.twig @@ -0,0 +1,16 @@ +{% if is_granted('IS_AUTHENTICATED') or app.current_route() == 'tvdt_quiz_select_season' %} +
+ {% if is_granted('IS_AUTHENTICATED') %} + + {{ 'Backoffice'|trans }} + + + {{ 'Logout'|trans }} + + {% else %} + + {{ 'Manage Quiz'|trans }} + + {% endif %} +
+{% endif %} diff --git a/tests/Twig/TemplateReferencesTest.php b/tests/Twig/TemplateReferencesTest.php new file mode 100644 index 0000000..4cab460 --- /dev/null +++ b/tests/Twig/TemplateReferencesTest.php @@ -0,0 +1,63 @@ + */ + public static function templateReferenceProvider(): iterable + { + $templatesDir = \dirname(__DIR__, 2).'/templates'; + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($templatesDir, \RecursiveDirectoryIterator::SKIP_DOTS), + ); + + foreach ($iterator as $file) { + Assert::assertInstanceOf(\SplFileInfo::class, $file); + if ('twig' !== $file->getExtension()) { + continue; + } + + $content = file_get_contents($file->getPathname()); + $sourceFile = str_replace($templatesDir.'/', '', $file->getPathname()); + + // Match extends, include(), and embed tags — capture the quoted template name + preg_match_all( + '/(?:extends|include|embed)\s*\(?[\'"]([^\'"]+)[\'"]\)?/', + $content, + $matches, + ); + + foreach ($matches[1] as $referencedTemplate) { + yield \sprintf('%s → %s', $sourceFile, $referencedTemplate) => [$sourceFile, $referencedTemplate]; + } + } + } + + #[DataProvider('templateReferenceProvider')] + public function testReferencedTemplateExists(string $sourceFile, string $referencedTemplate): void + { + $absolutePath = self::$templatesDir.'/'.$referencedTemplate; + + $this->assertFileExists( + $absolutePath, + \sprintf("Template '%s' references '%s' which does not exist at '%s'.", $sourceFile, $referencedTemplate, $absolutePath), + ); + } +}