Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit bb661cd

Browse files
author
Nate Wiebe
committed
Add tests for the icon manager
1 parent a44b8f0 commit bb661cd

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

tests/IconManagerTest.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
use Feather\Exception\AliasDefinedException;
4+
use Feather\Exception\IconNotFoundException;
5+
use Feather\Icon;
6+
use Feather\IconManager;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class IconManagerTest extends TestCase
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $iconName = 'test';
15+
16+
/**
17+
* @var IconManager
18+
*/
19+
private $iconManager;
20+
21+
protected function setUp(): void
22+
{
23+
$iconManager = $this->getMockBuilder(IconManager::class)
24+
->disableOriginalConstructor()
25+
->onlyMethods(['__construct'])
26+
->getMock();
27+
28+
$reflector = new ReflectionClass(IconManager::class);
29+
30+
$property = $reflector->getProperty('icons');
31+
$property->setAccessible(true);
32+
$property->setValue($iconManager, [$this->iconName => '']);
33+
34+
$property = $reflector->getProperty('attributes');
35+
$property->setAccessible(true);
36+
$property->setValue($iconManager, []);
37+
38+
$this->iconManager = $iconManager;
39+
}
40+
41+
public function testIconRetrieval(): void
42+
{
43+
$icon = $this->iconManager->getIcon($this->iconName, [], '');
44+
45+
$this->assertInstanceOf(Icon::class, $icon);
46+
}
47+
48+
public function testIconNotFound(): void
49+
{
50+
$this->expectException(IconNotFoundException::class);
51+
52+
$this->iconManager->getIcon('icon-that-should-not-be-found');
53+
}
54+
55+
public function testIconAlias(): void
56+
{
57+
$this->iconManager->addAlias('test-alias', $this->iconName);
58+
59+
$icon = $this->iconManager->getIcon('test-alias');
60+
61+
$this->assertInstanceOf(Icon::class, $icon);
62+
$this->assertEquals($this->iconName, $icon->getName());
63+
}
64+
65+
public function testDuplicateIconAlias(): void
66+
{
67+
$this->expectException(AliasDefinedException::class);
68+
69+
$this->iconManager->addAlias('test-alias', $this->iconName);
70+
$this->iconManager->addAlias('test-alias', $this->iconName);
71+
}
72+
73+
public function testInvalidIconAlias(): void
74+
{
75+
$this->expectException(IconNotFoundException::class);
76+
77+
$this->iconManager->addAlias('test-alias', 'icon-that-should-not-be-found');
78+
}
79+
80+
public function testMissingIconAlias(): void
81+
{
82+
$this->expectException(IconNotFoundException::class);
83+
84+
$this->iconManager->getIcon('test-alias');
85+
}
86+
87+
public function testAttributePassing(): void
88+
{
89+
$attributes = [
90+
'width' => 24,
91+
'height' => 24,
92+
'color' => '#000',
93+
'data-custom-attribute' => 'custom-value',
94+
];
95+
96+
$this->iconManager->setAttributes($attributes);
97+
98+
$icon = $this->iconManager->getIcon($this->iconName);
99+
100+
$this->assertEquals($attributes, $icon->getAttributes());
101+
}
102+
103+
public function testAttributeOverwritting(): void
104+
{
105+
$attributes = [
106+
'data-custom-attribute' => 'custom-value',
107+
];
108+
109+
$this->iconManager->setAttributes($attributes);
110+
111+
$icon = $this->iconManager->getIcon($this->iconName, ['data-custom-attribute' => 'another-value']);
112+
113+
$this->assertEquals('another-value', $icon->getAttribute('data-custom-attribute'));
114+
}
115+
}

0 commit comments

Comments
 (0)