|
| 1 | +<?php |
| 2 | + |
| 3 | +use Livewire\Volt\ComponentFactory; |
| 4 | +use Livewire\Volt\ComponentResolver; |
| 5 | +use Livewire\Volt\FragmentAlias; |
| 6 | + |
| 7 | +it('resolves fragment paths within a mounted directory', function () { |
| 8 | + $path = __DIR__.'/../Feature/resources/views/functional-api-pages/page-with-fragment.blade.php'; |
| 9 | + $alias = FragmentAlias::encode('fragment', $path); |
| 10 | + |
| 11 | + $factory = Mockery::mock(ComponentFactory::class); |
| 12 | + $factory->shouldReceive('make') |
| 13 | + ->once() |
| 14 | + ->with($alias, realpath($path)) |
| 15 | + ->andReturn('ResolvedComponent'); |
| 16 | + |
| 17 | + expect((new ComponentResolver($factory))->resolve($alias, [dirname($path)])) |
| 18 | + ->toBe('ResolvedComponent'); |
| 19 | +}); |
| 20 | + |
| 21 | +it('resolves fragment paths within a configured view directory', function () { |
| 22 | + $path = __DIR__.'/../Feature/resources/views/functional-api-pages/page-with-fragment.blade.php'; |
| 23 | + $alias = FragmentAlias::encode('fragment', $path); |
| 24 | + |
| 25 | + config()->set('view.paths', [dirname($path)]); |
| 26 | + |
| 27 | + $factory = Mockery::mock(ComponentFactory::class); |
| 28 | + $factory->shouldReceive('make') |
| 29 | + ->once() |
| 30 | + ->with($alias, realpath($path)) |
| 31 | + ->andReturn('ResolvedComponent'); |
| 32 | + |
| 33 | + expect((new ComponentResolver($factory))->resolve($alias, [])) |
| 34 | + ->toBe('ResolvedComponent'); |
| 35 | +}); |
| 36 | + |
| 37 | +it('does not resolve fragment paths outside the trusted directories', function () { |
| 38 | + $factory = Mockery::mock(ComponentFactory::class); |
| 39 | + $factory->shouldNotReceive('make'); |
| 40 | + |
| 41 | + $alias = FragmentAlias::encode('proof', __FILE__); |
| 42 | + |
| 43 | + config()->set('view.paths', [ |
| 44 | + __DIR__.'/../Feature/resources/views', |
| 45 | + ]); |
| 46 | + |
| 47 | + expect((new ComponentResolver($factory))->resolve($alias, [ |
| 48 | + __DIR__.'/../Feature/resources/views/functional-api-pages', |
| 49 | + ]))->toBeNull(); |
| 50 | +}); |
0 commit comments