|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenForgeProject\MageForge\Test\Unit\Service\Hyva; |
| 6 | + |
| 7 | +use Magento\Framework\Filesystem\Driver\File; |
| 8 | +use OpenForgeProject\MageForge\Service\Hyva\HyvaThemeDetector; |
| 9 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class HyvaThemeDetectorTest extends TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @return array<string, array{0: string|null, 1: array<string, mixed>|null, 2: bool}> |
| 16 | + */ |
| 17 | + public static function themeFilesProvider(): array |
| 18 | + { |
| 19 | + return [ |
| 20 | + 'hyva in theme.xml' => ['<theme><parent>Hyva/default</parent></theme>', null, true], |
| 21 | + 'hyva in theme.xml, other composer name' => [ |
| 22 | + '<theme><parent>Hyva/default</parent></theme>', |
| 23 | + ['name' => 'vendor/custom-theme'], |
| 24 | + true, |
| 25 | + ], |
| 26 | + 'neutral theme.xml, hyva composer name' => [ |
| 27 | + '<theme><title>Custom</title></theme>', |
| 28 | + ['name' => 'hyva-themes/theme-default'], |
| 29 | + true, |
| 30 | + ], |
| 31 | + 'neutral theme.xml and composer name' => [ |
| 32 | + '<theme><title>Custom</title></theme>', |
| 33 | + ['name' => 'vendor/custom-theme'], |
| 34 | + false, |
| 35 | + ], |
| 36 | + 'composer json without name' => [null, ['require' => []], false], |
| 37 | + 'no theme files' => [null, null, false], |
| 38 | + ]; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @param string|null $themeXml |
| 43 | + * @param array<string, mixed>|null $composerJson |
| 44 | + * @param bool $expected |
| 45 | + */ |
| 46 | + #[DataProvider('themeFilesProvider')] |
| 47 | + public function testIsHyvaTheme(?string $themeXml, ?array $composerJson, bool $expected): void |
| 48 | + { |
| 49 | + $fileDriver = $this->createStub(File::class); |
| 50 | + $fileDriver->method('isExists')->willReturnMap([ |
| 51 | + ['/theme/theme.xml', $themeXml !== null], |
| 52 | + ['/theme/composer.json', $composerJson !== null], |
| 53 | + ]); |
| 54 | + $fileDriver->method('fileGetContents')->willReturnMap([ |
| 55 | + ['/theme/theme.xml', null, null, (string) $themeXml], |
| 56 | + ['/theme/composer.json', null, null, json_encode($composerJson)], |
| 57 | + ]); |
| 58 | + |
| 59 | + $this->assertSame($expected, (new HyvaThemeDetector($fileDriver))->isHyvaTheme('/theme/')); |
| 60 | + } |
| 61 | +} |
0 commit comments