-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added some missing Twig extension unit tests
- Loading branch information
Showing
11 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Twig extension to return the category name by category ID. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ\Template | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-04-26 | ||
*/ | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use phpMyFAQ\Category; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Twig extension to return the FAQ question by FAQ ID. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ\Template | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-05-01 | ||
*/ | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use phpMyFAQ\Configuration; | ||
|
15 changes: 15 additions & 0 deletions
15
phpmyfaq/src/phpMyFAQ/Template/FormatDateTwigExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Twig extension to format the date | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ\Template | ||
* @author Jan Harms <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-04-27 | ||
*/ | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use phpMyFAQ\Configuration; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Twig extension to create an ISO date. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ\Template | ||
* @author Jan Harms <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-04-27 | ||
*/ | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use phpMyFAQ\Date; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Twig extension to translate the permission string. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ\Template | ||
* @author Jan Harms <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-04-27 | ||
*/ | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use phpMyFAQ\Translation; | ||
|
@@ -17,10 +32,7 @@ public function getFilters(): array | |
|
||
private function getPermissionTranslation(string $string): string | ||
{ | ||
$translationCode = sprintf( | ||
'permission::%s', | ||
$string | ||
); | ||
$translationCode = sprintf('permission::%s', $string); | ||
return Translation::get($translationCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class CategoryNameTwigExtensionTest extends TestCase | ||
{ | ||
public function testGetFilters(): void | ||
{ | ||
$extension = new CategoryNameTwigExtension(); | ||
|
||
$filters = $extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('categoryName', $filters[0]->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class FaqTwigExtensionTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->extension = new FaqTwigExtension(); | ||
} | ||
|
||
public function testGetFilters(): void | ||
{ | ||
$filters = $this->extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('faqQuestion', $filters[0]->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class FormatBytesTwigExtensionTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->extension = new FormatBytesTwigExtension(); | ||
} | ||
|
||
public function testGetFilters() | ||
{ | ||
$filters = $this->extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('formatBytes', $filters[0]->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class FormatDateTwigExtensionTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->extension = new FormatDateTwigExtension(); | ||
} | ||
|
||
public function testGetFilters(): void | ||
{ | ||
$filters = $this->extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('formatDate', $filters[0]->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class IsoDateTwigExtensionTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->extension = new IsoDateTwigExtension(); | ||
} | ||
|
||
public function testGetFilters(): void | ||
{ | ||
$filters = $this->extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('createIsoDate', $filters[0]->getName()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/phpMyFAQ/Template/PermissionTranslationTwigExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Template; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Twig\TwigFilter; | ||
|
||
class PermissionTranslationTwigExtensionTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->extension = new PermissionTranslationTwigExtension(); | ||
} | ||
|
||
public function testGetFilters() | ||
{ | ||
$filters = $this->extension->getFilters(); | ||
|
||
$this->assertCount(1, $filters); | ||
|
||
$this->assertInstanceOf(TwigFilter::class, $filters[0]); | ||
$this->assertEquals('permission', $filters[0]->getName()); | ||
} | ||
} |