. */ namespace SP\Tests\Core\UI; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\Exception; use SP\Core\UI\ThemeIcons; use SP\Domain\Core\Context\Context; use SP\Domain\Core\Exceptions\InvalidClassException; use SP\Domain\Core\UI\ThemeContextInterface; use SP\Domain\Storage\Ports\FileCacheService; use SP\Html\Assets\FontIcon; use SP\Infrastructure\File\FileException; use SP\Tests\UnitaryTestCase; /** * Class ThemeIconsTest * */ #[Group('unitary')] class ThemeIconsTest extends UnitaryTestCase { public function testGetIconByNameWithUnknownIcon() { $themeIcons = new ThemeIcons(); $out = $themeIcons->getIconByName('test'); $this->assertInstanceOf(FontIcon::class, $out); $this->assertEquals('test', $out->getIcon()); $this->assertEquals('mdl-color-text--indigo-A200', $out->getClass()); } public function testGetIconByName() { $themeIcons = new ThemeIcons(); $themeIcons->addIcon('test', new FontIcon('test', 'testClass', 'testTitle')); $out = $themeIcons->getIconByName('test'); $this->assertInstanceOf(FontIcon::class, $out); $this->assertEquals('test', $out->getIcon()); $this->assertEquals('testClass', $out->getClass()); $this->assertEquals('testTitle', $out->getTitle()); } public function testAddIcon() { $themeIcons = new ThemeIcons(); $themeIcons->addIcon('test', new FontIcon('test', 'testClass', 'testTitle')); $out = $themeIcons->getIconByName('test'); $this->assertInstanceOf(FontIcon::class, $out); $this->assertEquals('test', $out->getIcon()); $this->assertEquals('testClass', $out->getClass()); $this->assertEquals('testTitle', $out->getTitle()); } /** * @throws InvalidClassException * @throws Exception * @throws FileException */ public function testLoadIconsWithCache() { $context = $this->createMock(Context::class); $fileCache = $this->createMock(FileCacheService::class); $themeContext = $this->createMock(ThemeContextInterface::class); $context->expects(self::once()) ->method('getAppStatus') ->willReturn('test'); $fileCache->expects(self::once()) ->method('isExpired') ->willReturn(true); $fileCache->expects(self::once()) ->method('load') ->willReturn(new ThemeIcons()); ThemeIcons::loadIcons($context, $fileCache, $themeContext); } }