Skip to content

Commit 041af14

Browse files
committed
test: added some new Twig extension tests
1 parent 62e7517 commit 041af14

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)