1313use Symfony \Bridge \Twig \Extension \TranslationExtension ;
1414use Symfony \Component \Finder \Finder ;
1515use Symfony \Component \Finder \SplFileInfo ;
16+ use Twig \Environment ;
17+ use Twig \Extra \Intl \IntlExtension ;
18+ use Twig \Loader \FilesystemLoader ;
1619use Twig \TwigFilter ;
1720use Twig \TwigFunction ;
1821
2124 */
2225class TemplateTranslationTest extends TestCase
2326{
24- public function testCoreCardinalityErrorTemplate (): void {
27+ public function testCoreCardinalityErrorTemplate (): void
28+ {
2529 $ c = Configuration::loadFromArray ([], '' , 'simplesaml ' );
2630 $ t = new Template ($ c , 'core:cardinality_error.twig ' );
2731
@@ -30,18 +34,18 @@ public function testCoreCardinalityErrorTemplate(): void {
3034 'test 2 ' => [1 , 2 ],
3135 ];
3236
33- $ getContent = function () {
34- /** @var Template $this */
37+ $ getContent = function () {
38+ /** @var \SimpleSAML\XHTML\ Template $this */
3539 return $ this ->getContents ();
3640 };
3741 $ html = $ getContent ->call ($ t );
3842
3943 $ this ->assertStringContainsString ('got 0 values, want 1 ' , $ html );
4044 $ this ->assertStringContainsString ('got 1 values, want 2 ' , $ html );
41-
4245 }
4346
44- public function testCoreLoginUserPassTemplate (): void {
47+ public function testCoreLoginUserPassTemplate (): void
48+ {
4549 $ c = Configuration::loadFromArray ([], '' , 'simplesaml ' );
4650 $ t = new Template ($ c , 'core:loginuserpass.twig ' );
4751
@@ -53,16 +57,17 @@ public function testCoreLoginUserPassTemplate(): void {
5357 $ t ->data ['rememberMeEnabled ' ] = false ;
5458 $ t ->data ['stateparams ' ] = [];
5559
56- $ getContent = function () {
57- /** @var Template $this */
60+ $ getContent = function () {
61+ /** @var \SimpleSAML\XHTML\ Template $this */
5862 return $ this ->getContents ();
5963 };
6064 $ html = $ getContent ->call ($ t );
6165
6266 $ this ->assertStringContainsString ('value="h.c oersted" ' , $ html );
6367 }
6468
65- public function testCoreLogoutIframeTemplate (): void {
69+ public function testCoreLogoutIframeTemplate (): void
70+ {
6671 $ c = Configuration::loadFromArray ([], '' , 'simplesaml ' );
6772 $ t = new Template ($ c , 'core:logout-iframe.twig ' );
6873
@@ -86,8 +91,8 @@ public function testCoreLogoutIframeTemplate(): void {
8691 ],
8792 ];
8893
89- $ getContent = function () {
90- /** @var Template $this */
94+ $ getContent = function () {
95+ /** @var \SimpleSAML\XHTML\ Template $this */
9196 return $ this ->getContents ();
9297 };
9398 $ html = $ getContent ->call ($ t );
@@ -96,7 +101,8 @@ public function testCoreLogoutIframeTemplate(): void {
96101 $ this ->assertStringContainsString ('ze missing service ' , $ html );
97102 }
98103
99- public function testAuthStatusTemplate (): void {
104+ public function testAuthStatusTemplate (): void
105+ {
100106 $ c = Configuration::loadFromArray ([], '' , 'simplesaml ' );
101107 $ t = new Template ($ c , 'auth_status.twig ' );
102108
@@ -106,44 +112,78 @@ public function testAuthStatusTemplate(): void {
106112 $ t ->data ['trackid ' ] = '' ;
107113 $ t ->data ['authData ' ] = false ;
108114
109- $ getContent = function () {
110- /** @var Template $this */
115+ $ getContent = function () {
116+ /** @var \SimpleSAML\XHTML\ Template $this */
111117 return $ this ->getContents ();
112118 };
113119 $ html = $ getContent ->call ($ t );
114120
115- $ this ->assertStringContainsString ('Your session is valid for ' . $ t ->data ['remaining ' ] . ' seconds from now. ' , $ html );
121+ $ this ->assertStringContainsString (
122+ 'Your session is valid for ' . $ t ->data ['remaining ' ] . ' seconds from now. ' ,
123+ $ html
124+ );
116125 }
117126
118- public function testValidateTwigFiles ()
127+ public function testValidateTwigFiles (): void
119128 {
120129 $ root = dirname (dirname ((dirname (dirname (__DIR__ )))));
121130
122131 // Setup basic twig environment
123- $ loader = new \ Twig \ Loader \ FilesystemLoader (['templates ' , 'modules ' ], $ root );
124- $ twig = new \ Twig \ Environment ($ loader , ['cache ' => false ]);
132+ $ loader = new FilesystemLoader (['templates ' , 'modules ' ], $ root );
133+ $ twig = new Environment ($ loader , ['cache ' => false ]);
125134
126135 $ twigTranslator = new TwigTranslator ([Translate::class, 'translateSingularGettext ' ]);
127136 $ twig ->addExtension (new TranslationExtension ($ twigTranslator ));
128- $ twig ->addExtension (new \ Twig \ Extra \ Intl \ IntlExtension ());
137+ $ twig ->addExtension (new IntlExtension ());
129138
130139 // Fake functions
131- $ twig ->addFunction (new TwigFunction ('asset ' , function () { return '' ; }));
132- $ twig ->addFunction (new TwigFunction ('moduleURL ' , function () { return '' ; }));
140+ $ twig ->addFunction (
141+ new TwigFunction (
142+ 'asset ' ,
143+ function () {
144+ return '' ;
145+ }
146+ )
147+ );
148+ $ twig ->addFunction (
149+ new TwigFunction (
150+ 'moduleURL ' ,
151+ function () {
152+ return '' ;
153+ }
154+ )
155+ );
133156
134157 // Fake filters
135- $ twig ->addFilter (new TwigFilter ('translateFromArray ' , function () { return '' ; }, ['needs_context ' => true ]));
136- $ twig ->addFilter (new TwigFilter ('entityDisplayName ' , function () { return '' ; }));
158+ $ twig ->addFilter (
159+ new TwigFilter (
160+ 'translateFromArray ' ,
161+ function () {
162+ return '' ;
163+ },
164+ ['needs_context ' => true ]
165+ )
166+ );
167+ $ twig ->addFilter (
168+ new TwigFilter (
169+ 'entityDisplayName ' ,
170+ function () {
171+ return '' ;
172+ }
173+ )
174+ );
137175
138176 $ files = Finder::create ()
139177 ->name ('*.twig ' )
140- ->in ([
141- $ root . '/templates ' ,
142- $ root . '/modules '
143- ]);
178+ ->in (
179+ [
180+ $ root . '/templates ' ,
181+ $ root . '/modules '
182+ ]
183+ );
144184
145185 foreach ($ files as $ file ) {
146- /** @var SplFileInfo $file */
186+ /** @var \Symfony\Component\Finder\ SplFileInfo $file */
147187 $ twig ->load ($ file ->getRelativePathname ());
148188 }
149189
0 commit comments