Skip to content

Commit

Permalink
test: added missing tests for Twig extenstions
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed May 10, 2024
1 parent 31ac751 commit b6a2810
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 0 deletions.
Empty file.
2 changes: 2 additions & 0 deletions tests/phpMyFAQ/Template/FaqTwigExtensionTest.php
Expand Up @@ -7,6 +7,8 @@

class FaqTwigExtensionTest extends TestCase
{
private FaqTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new FaqTwigExtension();
Expand Down
2 changes: 2 additions & 0 deletions tests/phpMyFAQ/Template/FormatBytesTwigExtensionTest.php
Expand Up @@ -7,6 +7,8 @@

class FormatBytesTwigExtensionTest extends TestCase
{
private FormatBytesTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new FormatBytesTwigExtension();
Expand Down
2 changes: 2 additions & 0 deletions tests/phpMyFAQ/Template/FormatDateTwigExtensionTest.php
Expand Up @@ -7,6 +7,8 @@

class FormatDateTwigExtensionTest extends TestCase
{
private FormatDateTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new FormatDateTwigExtension();
Expand Down
2 changes: 2 additions & 0 deletions tests/phpMyFAQ/Template/IsoDateTwigExtensionTest.php
Expand Up @@ -7,6 +7,8 @@

class IsoDateTwigExtensionTest extends TestCase
{
private IsoDateTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new IsoDateTwigExtension();
Expand Down
37 changes: 37 additions & 0 deletions tests/phpMyFAQ/Template/LanguageCodeTwigExtensionTest.php
@@ -0,0 +1,37 @@
<?php

namespace phpMyFAQ\Template;

use PHPUnit\Framework\TestCase;
use Twig\TwigFilter;
use Twig\TwigFunction;

class LanguageCodeTwigExtensionTest extends TestCase
{
private LanguageCodeTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new LanguageCodeTwigExtension();
}

public function testGetFunctions(): void
{
$functions = $this->extension->getFunctions();

$this->assertCount(1, $functions);

$this->assertInstanceOf(TwigFunction::class, $functions[0]);
$this->assertEquals('getFromLanguageCode', $functions[0]->getName());
}

public function testGetFilters(): void
{
$filters = $this->extension->getFilters();

$this->assertCount(1, $filters);

$this->assertInstanceOf(TwigFilter::class, $filters[0]);
$this->assertEquals('getFromLanguageCode', $filters[0]->getName());
}
}
Expand Up @@ -7,6 +7,8 @@

class PermissionTranslationTwigExtensionTest extends TestCase
{
private PermissionTranslationTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new PermissionTranslationTwigExtension();
Expand Down
30 changes: 30 additions & 0 deletions tests/phpMyFAQ/Template/TwigWrapperTest.php
@@ -0,0 +1,30 @@
<?php

namespace phpMyFAQ\Template;

use PHPUnit\Framework\TestCase;
use Twig\TemplateWrapper;

class TwigWrapperTest extends TestCase
{
private TwigWrapper $twigWrapper;

/**
*/
protected function setUp(): void
{
$this->twigWrapper = new TwigWrapper(PMF_TEST_DIR . '/assets/templates');
}

/**
* @throws TemplateException
*/
public function testLoadTemplate(): void
{
$templateFile = 'template.twig';

$result = $this->twigWrapper->loadTemplate($templateFile);

$this->assertInstanceOf(TemplateWrapper::class, $result);
}
}
26 changes: 26 additions & 0 deletions tests/phpMyFAQ/Template/UserNameTwigExtensionTest.php
@@ -0,0 +1,26 @@
<?php

namespace phpMyFAQ\Template;

use PHPUnit\Framework\TestCase;
use Twig\TwigFilter;

class UserNameTwigExtensionTest extends TestCase
{
private UserNameTwigExtension $extension;

protected function setUp(): void
{
$this->extension = new UserNameTwigExtension();
}

public function testGetFilters(): void
{
$filters = $this->extension->getFilters();

$this->assertCount(1, $filters);

$this->assertInstanceOf(TwigFilter::class, $filters[0]);
$this->assertEquals('userName', $filters[0]->getName());
}
}

0 comments on commit b6a2810

Please sign in to comment.