. // }}} License /** * This file test the Macro that Embeds SVG icons. * * @package Tests * * @author Ângelo D. Moura * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @author Hugo Sales * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Tests\Templates\Icons; use App\Twig\Extension; use App\Twig\Runtime; use DirectoryIterator; use PHPUnit\Framework\TestCase; class IconsExtensionTest extends TestCase { public function testIconsExtension() { // Get all Icon files names from "public/assets/icons" $icon_file_names = []; foreach (new DirectoryIterator('public/assets/icons/') as $file) { if ($file->isDot()) { continue; } $icon_file_names[] = $file->getFilename(); } $twig = self::$kernel->getContainer()->get('twig'); // Check if every icon file as a ".svg.twig" extension foreach ($icon_file_names as $icon_file_name) { static::assertRegExp('#.+\.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 self::assertEquals($icon_template_render, $iconsExtension_render); } } }