File tree 3 files changed +93
-0
lines changed
tests/phpMyFAQ/Twig/Extensions 3 files changed +93
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace phpMyFAQ \Twig \Extensions ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Twig \Environment ;
7
+ use Twig \Error \LoaderError ;
8
+ use Twig \Error \RuntimeError ;
9
+ use Twig \Error \SyntaxError ;
10
+ use Twig \Extension \AttributeExtension ;
11
+ use Twig \Loader \ArrayLoader ;
12
+
13
+ class FormatBytesTwigExtensionTest extends TestCase
14
+ {
15
+ /**
16
+ * @throws SyntaxError
17
+ * @throws RuntimeError
18
+ * @throws LoaderError
19
+ */
20
+ public function testFormatBytesFilter (): void
21
+ {
22
+ $ loader = new ArrayLoader ([
23
+ 'index ' => '{{ 1536|formatBytes }} ' ,
24
+ ]);
25
+ $ twig = new Environment ($ loader );
26
+ $ twig ->addExtension (new AttributeExtension (FormatBytesTwigExtension::class));
27
+
28
+ $ output = $ twig ->render ('index ' );
29
+ $ this ->assertSame ('1.5 KB ' , $ output );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace phpMyFAQ \Twig \Extensions ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Twig \Environment ;
7
+ use Twig \Error \LoaderError ;
8
+ use Twig \Error \RuntimeError ;
9
+ use Twig \Error \SyntaxError ;
10
+ use Twig \Extension \AttributeExtension ;
11
+ use Twig \Loader \ArrayLoader ;
12
+
13
+ class IsoDateTwigExtensionTest extends TestCase
14
+ {
15
+ /**
16
+ * @throws SyntaxError
17
+ * @throws RuntimeError
18
+ * @throws LoaderError
19
+ */
20
+ public function testCreateIsoDateFilter (): void
21
+ {
22
+ $ loader = new ArrayLoader ([
23
+ 'index ' => '{{ 202504011230 | createIsoDate }} ' ,
24
+ ]);
25
+ $ twig = new Environment ($ loader );
26
+ $ twig ->addExtension (new AttributeExtension (IsoDateTwigExtension::class));
27
+
28
+ $ output = $ twig ->render ('index ' );
29
+ $ this ->assertSame ('2025-04-01 12:30 ' , $ output );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace phpMyFAQ \Twig \Extensions ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Twig \Environment ;
7
+ use Twig \Error \LoaderError ;
8
+ use Twig \Error \RuntimeError ;
9
+ use Twig \Error \SyntaxError ;
10
+ use Twig \Extension \AttributeExtension ;
11
+ use Twig \Loader \ArrayLoader ;
12
+
13
+ class LanguageCodeTwigExtensionTest extends TestCase
14
+ {
15
+ /**
16
+ * @throws SyntaxError
17
+ * @throws RuntimeError
18
+ * @throws LoaderError
19
+ */
20
+ public function testGetFromLanguageCodeFilter (): void
21
+ {
22
+ $ loader = new ArrayLoader ([
23
+ 'index ' => "{{ 'en' | getFromLanguageCode }} " ,
24
+ ]);
25
+ $ twig = new Environment ($ loader );
26
+ $ twig ->addExtension (new AttributeExtension (LanguageCodeTwigExtension::class));
27
+
28
+ $ output = $ twig ->render ('index ' );
29
+ $ this ->assertSame ('English ' , $ output );
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments