Skip to content

Commit c1fcd60

Browse files
committed
test: added some missing Twig extension unit tests
1 parent 7f86de9 commit c1fcd60

11 files changed

+217
-4
lines changed

phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
/**
4+
* Twig extension to return the category name by category ID.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ\Template
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-04-26
16+
*/
17+
318
namespace phpMyFAQ\Template;
419

520
use phpMyFAQ\Category;

phpmyfaq/src/phpMyFAQ/Template/FaqTwigExtension.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
/**
4+
* Twig extension to return the FAQ question by FAQ ID.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ\Template
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-05-01
16+
*/
17+
318
namespace phpMyFAQ\Template;
419

520
use phpMyFAQ\Configuration;

phpmyfaq/src/phpMyFAQ/Template/FormatDateTwigExtension.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
/**
4+
* Twig extension to format the date
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ\Template
11+
* @author Jan Harms <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-04-27
16+
*/
17+
318
namespace phpMyFAQ\Template;
419

520
use phpMyFAQ\Configuration;

phpmyfaq/src/phpMyFAQ/Template/IsoDateTwigExtension.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
/**
4+
* Twig extension to create an ISO date.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ\Template
11+
* @author Jan Harms <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-04-27
16+
*/
17+
318
namespace phpMyFAQ\Template;
419

520
use phpMyFAQ\Date;

phpmyfaq/src/phpMyFAQ/Template/PermissionTranslationTwigExtension.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
/**
4+
* Twig extension to translate the permission string.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ\Template
11+
* @author Jan Harms <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-04-27
16+
*/
17+
318
namespace phpMyFAQ\Template;
419

520
use phpMyFAQ\Translation;
@@ -17,10 +32,7 @@ public function getFilters(): array
1732

1833
private function getPermissionTranslation(string $string): string
1934
{
20-
$translationCode = sprintf(
21-
'permission::%s',
22-
$string
23-
);
35+
$translationCode = sprintf('permission::%s', $string);
2436
return Translation::get($translationCode);
2537
}
2638
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Template;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Twig\TwigFilter;
7+
8+
class CategoryNameTwigExtensionTest extends TestCase
9+
{
10+
public function testGetFilters(): void
11+
{
12+
$extension = new CategoryNameTwigExtension();
13+
14+
$filters = $extension->getFilters();
15+
16+
$this->assertCount(1, $filters);
17+
18+
$this->assertInstanceOf(TwigFilter::class, $filters[0]);
19+
$this->assertEquals('categoryName', $filters[0]->getName());
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Template;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Twig\TwigFilter;
7+
8+
class FaqTwigExtensionTest extends TestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
$this->extension = new FaqTwigExtension();
13+
}
14+
15+
public function testGetFilters(): void
16+
{
17+
$filters = $this->extension->getFilters();
18+
19+
$this->assertCount(1, $filters);
20+
21+
$this->assertInstanceOf(TwigFilter::class, $filters[0]);
22+
$this->assertEquals('faqQuestion', $filters[0]->getName());
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Template;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Twig\TwigFilter;
7+
8+
class FormatBytesTwigExtensionTest extends TestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
$this->extension = new FormatBytesTwigExtension();
13+
}
14+
15+
public function testGetFilters()
16+
{
17+
$filters = $this->extension->getFilters();
18+
19+
$this->assertCount(1, $filters);
20+
21+
$this->assertInstanceOf(TwigFilter::class, $filters[0]);
22+
$this->assertEquals('formatBytes', $filters[0]->getName());
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Template;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Twig\TwigFilter;
7+
8+
class FormatDateTwigExtensionTest extends TestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
$this->extension = new FormatDateTwigExtension();
13+
}
14+
15+
public function testGetFilters(): void
16+
{
17+
$filters = $this->extension->getFilters();
18+
19+
$this->assertCount(1, $filters);
20+
21+
$this->assertInstanceOf(TwigFilter::class, $filters[0]);
22+
$this->assertEquals('formatDate', $filters[0]->getName());
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace phpMyFAQ\Template;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Twig\TwigFilter;
7+
8+
class IsoDateTwigExtensionTest extends TestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
$this->extension = new IsoDateTwigExtension();
13+
}
14+
15+
public function testGetFilters(): void
16+
{
17+
$filters = $this->extension->getFilters();
18+
19+
$this->assertCount(1, $filters);
20+
21+
$this->assertInstanceOf(TwigFilter::class, $filters[0]);
22+
$this->assertEquals('createIsoDate', $filters[0]->getName());
23+
}
24+
}

0 commit comments

Comments
 (0)