themesPath = storage_path('framework/testing/stylist-inheritance-'.uniqid()); mkdir($this->themesPath, 0777, true); config([ 'stylist.themes_path' => $this->themesPath, 'stylist.default_theme' => 'common', ]); app(Loader::class)->flush(); } protected function tearDown(): void { app(Filesystem::class)->deleteDirectory($this->themesPath); parent::tearDown(); } public function test_child_theme_resolves_views_through_parent_without_copying_them(): void { $this->theme('common', null, ['components/layouts/app.blade.php' => '
{{ $slot }}
']); $this->theme('admin', 'common', ['dashboard.blade.php' => '

Dashboard

']); app(Loader::class)->flush(); $candidates = app(ThemeViewResolver::class)->candidatesForTheme('admin', 'components.layouts.app'); $this->assertSame('stylist-theme-admin::components.layouts.app', $candidates[0]); $this->assertContains('stylist-theme-common::components.layouts.app', $candidates); $this->assertLessThan( array_search('stylist-theme-common::components.layouts.app', $candidates, true), array_search('stylist-theme-admin::components.layouts.app', $candidates, true), ); } public function test_parent_alias_is_normalised_to_extends(): void { $path = $this->themesPath.'/child'; mkdir($path, 0777, true); file_put_contents($path.'/theme.json', json_encode([ 'name' => 'Child', 'parent' => 'common', ])); $theme = app(Loader::class)->fromPath($path); $this->assertSame('common', $theme->parent()); } public function test_duplicate_view_ownership_is_reported(): void { $this->theme('common', null, ['livewire/auth/login.blade.php' => 'common']); $this->theme('admin', 'common', ['livewire/auth/login.blade.php' => 'admin']); app(Loader::class)->flush(); $duplicates = app(ThemeInspector::class)->duplicateViews(); $this->assertArrayHasKey('livewire/auth/login.blade.php', $duplicates); $this->assertEqualsCanonicalizing(['common', 'admin'], array_column($duplicates['livewire/auth/login.blade.php'], 'theme')); } /** @param array $views */ private function theme(string $key, ?string $parent, array $views): void { $path = $this->themesPath.'/'.$key; mkdir($path.'/views', 0777, true); file_put_contents($path.'/theme.json', json_encode(array_filter([ 'name' => ucfirst($key), 'slug' => $key, 'extends' => $parent, ], fn ($value) => $value !== null))); foreach ($views as $relative => $contents) { $file = $path.'/views/'.$relative; mkdir(dirname($file), 0777, true); file_put_contents($file, $contents); } } }