diff --git a/src/Twig/Functions/IconExtension.php b/src/Twig/Functions/IconExtension.php index 5ab97dc..f8fe0b1 100644 --- a/src/Twig/Functions/IconExtension.php +++ b/src/Twig/Functions/IconExtension.php @@ -81,18 +81,18 @@ final class IconExtension extends AbstractExtension $mainPallete = $this->getPallete($options['colour']); - $xml = new \SimpleXMLElement($cleanSvgMarkup); - $xml = $this->addAttributeToXmlElement($xml, 'class', $mainPallete['stroke'] . ' ' . $mainPallete['fill']); - $cleanSvgMarkup = $this->removeXMLDeclaration($xml->saveXML()); + + $colourClasses = "{$mainPallete['stroke']} {$mainPallete['fill']}"; if (null !== $options['hover']) { $hoverPallete = $this->getPallete($options['hover']); - $xml = new \SimpleXMLElement($cleanSvgMarkup); - $xml = $this->addAttributeToXmlElement($xml, 'class', 'hover:' . $hoverPallete['stroke'] . ' ' . 'hover:' . $hoverPallete['fill']); - $cleanSvgMarkup = $this->removeXMLDeclaration($xml->saveXML()); + $colourClasses .= " hover:{$hoverPallete['stroke']} hover:{$hoverPallete['fill']}"; } - $markup = $cleanSvgMarkup; + $xml = new \SimpleXMLElement($cleanSvgMarkup); + $xml = $this->addAttributeToXmlElement($xml, 'class', $colourClasses); + $markup = $this->removeXMLDeclaration($xml->saveXML()); + if ($this->isNonEmptyString($options['title'])) $markup = $this->addTitleToMarkup($markup, $options['title']); diff --git a/tests/Twig/Functions/IconExtensionTest.php b/tests/Twig/Functions/IconExtensionTest.php index 6a9482d..5b71469 100644 --- a/tests/Twig/Functions/IconExtensionTest.php +++ b/tests/Twig/Functions/IconExtensionTest.php @@ -253,5 +253,14 @@ class IconExtensionTest extends TestCase $this->assertMatchesRegularExpression('//', $contents); } + public function testSvgClassContainsHoverAndColourPalleteClasses(): void + { + $contents = $this->icon->renderIcon(['icon' => self::ICON, 'hover' => 'white', 'colour' => 'primary']); + $this->assertMatchesRegularExpression('//', $contents); + $this->assertMatchesRegularExpression('//', $contents); + $this->assertMatchesRegularExpression('//', $contents); + $this->assertMatchesRegularExpression('//', $contents); + } + }