Skip to content

Commit

Permalink
test: added some missing Twig extension unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed May 9, 2024
1 parent 7f86de9 commit c1fcd60
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 4 deletions.
15 changes: 15 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php
@@ -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 <thorsten@phpmyfaq.de>
* @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;
Expand Down
15 changes: 15 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Template/FaqTwigExtension.php
@@ -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 <thorsten@phpmyfaq.de>
* @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;
Expand Down
15 changes: 15 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Template/FormatDateTwigExtension.php
@@ -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 <model_railroader@gmx-topmail.de>
* @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;
Expand Down
15 changes: 15 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Template/IsoDateTwigExtension.php
@@ -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 <model_railroader@gmx-topmail.de>
* @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;
Expand Down
@@ -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 <model_railroader@gmx-topmail.de>
* @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;
Expand All @@ -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);
}
}
21 changes: 21 additions & 0 deletions tests/phpMyFAQ/Template/CategoryNameTwigExtensionTest.php
@@ -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());
}
}
24 changes: 24 additions & 0 deletions tests/phpMyFAQ/Template/FaqTwigExtensionTest.php
@@ -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());
}
}
24 changes: 24 additions & 0 deletions tests/phpMyFAQ/Template/FormatBytesTwigExtensionTest.php
@@ -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());
}
}
24 changes: 24 additions & 0 deletions tests/phpMyFAQ/Template/FormatDateTwigExtensionTest.php
@@ -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());
}
}
24 changes: 24 additions & 0 deletions tests/phpMyFAQ/Template/IsoDateTwigExtensionTest.php
@@ -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 tests/phpMyFAQ/Template/PermissionTranslationTwigExtensionTest.php
@@ -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());
}
}

0 comments on commit c1fcd60

Please sign in to comment.