Test size
This commit is contained in:
@@ -71,4 +71,76 @@ class IconExtensionTest extends TestCase
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->icon->renderIcon(['icon' => self::ICON, 'title' => '']);
|
||||
}
|
||||
|
||||
public function testThrowsWhenPassedNegativeSizeValue(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->icon->renderIcon(['icon' => self::ICON, 'size' => -1]);
|
||||
}
|
||||
|
||||
public function testThrowsWhenSizeIsNotAnInt(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->icon->renderIcon(['icon' => self::ICON, 'size' => 1.0]);
|
||||
}
|
||||
|
||||
public function testSvgWidthIsSet(): void
|
||||
{
|
||||
$regex = '/^<svg.+?width="99"/';
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON, 'size' => 99]);
|
||||
$this->assertMatchesRegularExpression($regex, $content);
|
||||
}
|
||||
|
||||
public function testSvgHeightIsSet(): void
|
||||
{
|
||||
$regex = '/^<svg.+?width="99"/';
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON, 'size' => 99]);
|
||||
$this->assertMatchesRegularExpression($regex, $content);
|
||||
}
|
||||
|
||||
public function testNoXmlDeclarationIsAdded(): void
|
||||
{
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON, 'size' => 99]);
|
||||
$this->assertStringNotContainsString('<xml', $content);
|
||||
}
|
||||
|
||||
public function testOnlyOneWidthAttributeIsSet(): void
|
||||
{
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON, 'size' => 99]);
|
||||
$timesMatched = preg_match_all('/width="99"/', $content);
|
||||
$this->assertSame(1, $timesMatched);
|
||||
}
|
||||
|
||||
public function testOnlyOneHeightAttributeIsSet(): void
|
||||
{
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON, 'size' => 99]);
|
||||
$timesMatched = preg_match_all('/height="99"/', $content);
|
||||
$this->assertSame(1, $timesMatched);
|
||||
}
|
||||
|
||||
public function testDefaultSizeIsSetOnSvgIfNoSizeOptionPassed(): void
|
||||
{
|
||||
$defaultSize = IconExtension::DEFAULT_SIZE;
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON]);
|
||||
|
||||
$regex = "/^<svg.+?width=\"{$defaultSize}\"/";
|
||||
$this->assertMatchesRegularExpression($regex, $content);
|
||||
|
||||
$regex = "/^<svg.+?height=\"{$defaultSize}\"/";
|
||||
$this->assertMatchesRegularExpression($regex, $content);
|
||||
}
|
||||
|
||||
public function testDefaultSizeIsOnlySetOnce(): void
|
||||
{
|
||||
$defaultSize = IconExtension::DEFAULT_SIZE;
|
||||
$content = $this->icon->renderIcon(['icon' => self::ICON]);
|
||||
|
||||
$widthRegex = "/width=\"{$defaultSize}\"/";
|
||||
$timesMatched = preg_match_all($widthRegex, $content);
|
||||
$this->assertSame(1, $timesMatched);
|
||||
|
||||
$heightRegex = "/height=\"{$defaultSize}\"/";
|
||||
$timesMatched = preg_match_all($heightRegex, $content);
|
||||
$this->assertSame(1, $timesMatched);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user