Skip to content

Commit

Permalink
Fix Assets Twig extension
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Mar 21, 2022
1 parent ba57f5b commit b41755b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
23 changes: 11 additions & 12 deletions Tests/Twig/Extension/AssetsTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
*/
class AssetsTwigExtensionTest extends AbstractTestCase {

/**
* Tests renderIcon()
*
* @return void
*/
public function testRenderIcon(): void {

$this->assertNull(AssetsTwigExtension::renderIcon($this->twigEnvironment, "::"));
$this->assertNull(AssetsTwigExtension::renderIcon($this->twigEnvironment, null));
}

/**
* Tests renderIcon()
*
Expand Down Expand Up @@ -71,18 +82,6 @@ public function testRenderIconWithOther(): void {
$this->assertEquals($res, AssetsTwigExtension::renderIcon($this->twigEnvironment, "fa:home"));
}

/**
* Tests renderIcon()
*
* @return void
*/
public function testRenderIconWithoutArguments(): void {

$res = "";

$this->assertEquals($res, AssetsTwigExtension::renderIcon($this->twigEnvironment, "::"));
}

/**
* Tests __construct()
*
Expand Down
5 changes: 2 additions & 3 deletions Twig/Extension/AssetsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ class AssetsTwigExtension extends BaseTwigExtension {
*/
public static function renderIcon(Environment $twigEnvironment, ?string $name, string $style = null): ?string {

// Determines the handler.
$handler = explode(":", $name);
if (1 === count($handler)) {
array_unshift($handler, "g");
}
if (2 !== count($handler)) {
if (2 !== count($handler) || null === $name) {
return null;
}

switch ($handler[0]) {

case "b": // Bootstrap
case "bi": // Bootstrap icons
$output = (new IconTwigExtension($twigEnvironment))->renderIcon($handler[1], $style);
break;

case "b": // Bootstrap
case "g": // Glyphicon
$output = (new GlyphiconTwigExtension($twigEnvironment))->renderIcon($handler[1], $style);
break;
Expand Down

0 comments on commit b41755b

Please sign in to comment.