[TWIG][TESTS] Update IconsExtension test

This commit is contained in:
Angelo D. Moura 2020-11-09 19:43:39 +00:00 committed by Hugo Sales
parent 5acfda8ae5
commit d2208d15d8
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 19 additions and 15 deletions

View File

@ -19,8 +19,8 @@
namespace App\Tests\EventListener; namespace App\Tests\EventListener;
use App\Core\DB\UpdateListener;
use App\Entity\GSActor; use App\Entity\GSActor;
use App\EventListener\UpdateListener;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs;

View File

@ -34,9 +34,9 @@ namespace App\Tests\Templates\Icons;
use App\Twig\Extension; use App\Twig\Extension;
use App\Twig\Runtime; use App\Twig\Runtime;
use DirectoryIterator; use DirectoryIterator;
use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class IconsExtensionTest extends TestCase class IconsExtensionTest extends KernelTestCase
{ {
public function testIconsExtension() public function testIconsExtension()
{ {
@ -49,20 +49,24 @@ class IconsExtensionTest extends TestCase
$icon_file_names[] = $file->getFilename(); $icon_file_names[] = $file->getFilename();
} }
$twig = self::$kernel->getContainer()->get('twig');
//Check if every icon file as a ".svg.twig" extension //Check if every icon file as a ".svg.twig" extension
foreach ($icon_file_names as $icon_file_name) { foreach ($icon_file_names as $icon_file_name) {
static::assertRegExp('#.+\.svg\.twig$#', $icon_file_name); static::assertRegExp('#([a-zA-Z0-9\s_\\.\-\(\):])+(.svg.twig)$#', $icon_file_name);
}
$icon_name = explode('.', basename($icon_file_name))[0];
$icon_template_render = $twig->render($icon_file_name, ['iconClass' => 'icon icon-' . $icon_name]);
$icons_extension = new Runtime();
$icon_extension_render = $icons_extension->embedSvgIcon($twig, $icon_name, 'icon icon-' . $icon_name);
//Check if the function gives a valid HTML with a class attribute equal to the one passed //Check if the function gives a valid HTML with a class attribute equal to the one passed
self::assertEquals($icon_template_render, $iconsExtension_render); static::bootKernel();
} $twig = self::$kernel->getContainer()->get('twig');
foreach ($icon_file_names as $icon_file_name) {
$icon_name = basename($icon_file_name, '.svg.twig');
$icon_template_render = $twig->render('@public_path/assets/icons/' . $icon_file_name, ['iconClass' => 'icon icon-' . $icon_name]);
$icons_extension = new IconsExtension();
$icon_extension_render = $icons_extension->embedSvgIcon($twig, $icon_name, 'icon icon-' . $icon_name);
static::assertSame($icon_template_render, $icon_extension_render);
}
} }
} }