tests / lint (push) Successful in 1m3s
tests / feature (8.4) (push) Successful in 1m14s
tests / feature (8.5) (push) Successful in 1m14s
tests / browser (chrome, chromium) (push) Successful in 3m16s
tests / browser (firefox, firefox) (push) Successful in 4m36s
tests / browser (safari, webkit) (push) Successful in 5m8s
Without a prefix, Blade named the components' view namespace after the folder's absolute path, while compiled views are named relative to the application. A view compiled on a laptop and served from a container sharing storage/framework/views (or from another release directory) printed 'eb5f…::input' as text. The components now register under the prefix livewire-material when none is configured, which unprefixed tags still resolve through, and the path's namespace stays registered for views compiled before. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9NnLxnPp8vaaurb3Z1MFy
70 lines
3.1 KiB
PHP
70 lines
3.1 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use NoNameWeb\LivewireMaterial\LivewireMaterialServiceProvider;
|
|
|
|
/**
|
|
* The anonymous component paths Blade holds for this package's components.
|
|
*
|
|
* @return Collection<int, array{path: string, prefix: ?string, prefixHash: string}>
|
|
*/
|
|
function packageComponentPaths(): Collection
|
|
{
|
|
$components = realpath(__DIR__.'/../../resources/views/components');
|
|
|
|
return collect(Blade::getAnonymousComponentPaths())
|
|
->filter(fn (array $entry): bool => realpath($entry['path']) === $components)
|
|
->values();
|
|
}
|
|
|
|
it('registers the components under its own name when no prefix is configured', function () {
|
|
expect(packageComponentPaths())->toHaveCount(1)
|
|
->and(packageComponentPaths()->first()['prefix'])->toBe('livewire-material')
|
|
->and(Blade::render('<x-badge value="New" tonal />'))->toContain('New');
|
|
});
|
|
|
|
it('compiles an unprefixed component to the same view on every machine', function () {
|
|
$compiled = Blade::compileString('<x-input label="Name" />');
|
|
|
|
expect($compiled)->toContain("'view' => '".hash('xxh128', 'livewire-material')."::input'")
|
|
->not->toContain(hash('xxh128', LivewireMaterialServiceProvider::componentPath()));
|
|
});
|
|
|
|
it('still renders a view compiled when the namespace came from the component path', function () {
|
|
$legacy = hash('xxh128', LivewireMaterialServiceProvider::componentPath());
|
|
|
|
expect(view()->exists($legacy.'::input'))->toBeTrue();
|
|
});
|
|
|
|
it('registers the components under a configured prefix', function () {
|
|
config(['livewire-material.prefix' => 'm']);
|
|
|
|
$provider = app()->getProvider(LivewireMaterialServiceProvider::class);
|
|
(fn () => $this->registerComponents())->call($provider);
|
|
|
|
expect(packageComponentPaths()->last()['prefix'])->toBe('m');
|
|
});
|
|
|
|
it('keeps blade-icons from registering an <x-icon> that would shadow ours', function () {
|
|
expect(Blade::getClassComponentAliases())->not->toHaveKey('icon');
|
|
});
|
|
|
|
it('publishes the error pages into the application\'s errors folder', function () {
|
|
expect(ServiceProvider::pathsToPublish(LivewireMaterialServiceProvider::class, 'livewire-material-errors'))->toBe([
|
|
LivewireMaterialServiceProvider::errorViewPath().'/errors' => resource_path('views/errors'),
|
|
]);
|
|
});
|
|
|
|
it('publishes the mail components where Laravel looks for them', function () {
|
|
expect(ServiceProvider::pathsToPublish(LivewireMaterialServiceProvider::class, 'livewire-material-mail'))->toBe([
|
|
LivewireMaterialServiceProvider::mailComponentPath().'/html' => resource_path('views/vendor/mail/html'),
|
|
LivewireMaterialServiceProvider::mailComponentPath().'/text' => resource_path('views/vendor/mail/text'),
|
|
])->and(config('mail.markdown.paths'))->toContain(resource_path('views/vendor/mail'));
|
|
|
|
expect(File::files(LivewireMaterialServiceProvider::mailComponentPath().'/html'))->not->toBeEmpty()
|
|
->and(File::files(LivewireMaterialServiceProvider::mailComponentPath().'/text'))->not->toBeEmpty();
|
|
});
|