Get tests passing
This commit is contained in:
@@ -16,7 +16,8 @@ final class IconExtension extends AbstractExtension
|
|||||||
'icon' => null,
|
'icon' => null,
|
||||||
'title' => null,
|
'title' => null,
|
||||||
'size' => self::DEFAULT_SIZE,
|
'size' => self::DEFAULT_SIZE,
|
||||||
'colour' => 'primary'
|
'colour' => 'primary',
|
||||||
|
'hover' => null
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(private array $directories, private array $palletes)
|
public function __construct(private array $directories, private array $palletes)
|
||||||
@@ -66,6 +67,7 @@ final class IconExtension extends AbstractExtension
|
|||||||
* 'title' => (?string) Text to appear on mouse hover
|
* 'title' => (?string) Text to appear on mouse hover
|
||||||
* 'size' => (int) Height and width in px
|
* 'size' => (int) Height and width in px
|
||||||
* 'colour' => (string) Main colour pallete
|
* 'colour' => (string) Main colour pallete
|
||||||
|
* 'hover' => (?string) Hover colour pallete
|
||||||
* ]
|
* ]
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@@ -81,8 +83,16 @@ final class IconExtension extends AbstractExtension
|
|||||||
|
|
||||||
$xml = new \SimpleXMLElement($cleanSvgMarkup);
|
$xml = new \SimpleXMLElement($cleanSvgMarkup);
|
||||||
$xml = $this->addAttributeToXmlElement($xml, 'class', $mainPallete['stroke'] . ' ' . $mainPallete['fill']);
|
$xml = $this->addAttributeToXmlElement($xml, 'class', $mainPallete['stroke'] . ' ' . $mainPallete['fill']);
|
||||||
$markup = $this->removeXMLDeclaration($xml->saveXML());
|
$cleanSvgMarkup = $this->removeXMLDeclaration($xml->saveXML());
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
$markup = $cleanSvgMarkup;
|
||||||
if ($this->isNonEmptyString($options['title']))
|
if ($this->isNonEmptyString($options['title']))
|
||||||
$markup = $this->addTitleToMarkup($markup, $options['title']);
|
$markup = $this->addTitleToMarkup($markup, $options['title']);
|
||||||
|
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ class IconExtensionTest extends TestCase
|
|||||||
$this->assertDoesNotMatchRegularExpression('/fill:\s*rgb\(0,\s*0,\s*0\)\s*/', $content);
|
$this->assertDoesNotMatchRegularExpression('/fill:\s*rgb\(0,\s*0,\s*0\)\s*/', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsIfPalleteIsNotFound(): void
|
public function testThrowsIfColourPalleteIsNotFound(): void
|
||||||
{
|
{
|
||||||
$this->expectException(PalleteNotFound::class);
|
$this->expectException(PalleteNotFound::class);
|
||||||
$this->icon->renderIcon(['icon' => self::ICON, 'colour' => 'red']);
|
$this->icon->renderIcon(['icon' => self::ICON, 'colour' => 'red']);
|
||||||
@@ -240,5 +240,18 @@ class IconExtensionTest extends TestCase
|
|||||||
$this->assertMatchesRegularExpression('/<svg.*?class=".*?stroke-white?.*>/', $contents);
|
$this->assertMatchesRegularExpression('/<svg.*?class=".*?stroke-white?.*>/', $contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testThrowsIfHoverPalleteIsNotFound(): void
|
||||||
|
{
|
||||||
|
$this->expectException(PalleteNotFound::class);
|
||||||
|
$this->icon->renderIcon(['icon' => self::ICON, 'hover' => 'red']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSvgClassContainsHoverPalleteClasses(): void
|
||||||
|
{
|
||||||
|
$contents = $this->icon->renderIcon(['icon' => self::ICON, 'hover' => 'white']);
|
||||||
|
$this->assertMatchesRegularExpression('/<svg.+class=".*hover:fill-white.*".*>/', $contents);
|
||||||
|
$this->assertMatchesRegularExpression('/<svg.+class=".*hover:stroke-white.*".*>/', $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user