-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathIntegrationTest.php
More file actions
104 lines (80 loc) · 3.04 KB
/
Copy pathIntegrationTest.php
File metadata and controls
104 lines (80 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
use Illuminate\Container\Container;
use Illuminate\Contracts\View\Engine;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Illuminate\View\Component;
use Livewire\Blaze\Blaze;
use Livewire\Blaze\BlazeManager;
use Livewire\Blaze\Runtime\BlazeRuntime;
beforeEach(fn () => Artisan::call('view:clear'));
test('renders components', function () {
view('mix')->render();
})->throwsNoExceptions();
test('renders components with blaze off', function () {
Blaze::disable();
view('mix')->render();
})->throwsNoExceptions();
test('renders components with blaze off and debug mode on', function () {
Blaze::disable();
Blaze::debug();
view('mix')->render();
})->throwsNoExceptions();
test('renders components after clearing compiled views in the same process', function () {
view('mix')->render();
Artisan::call('view:clear');
view('mix')->render();
})->throwsNoExceptions();
test('supports php engine', function () {
view('php-view')->render();
})->throwsNoExceptions();
test('supports decorated engine', function () {
$resolver = app('view.engine.resolver');
$blade = $resolver->resolve('blade');
// This replicates how Sentry wraps the blade engine...
$resolver->register('blade', function () use ($blade) {
return new class($blade) implements Engine {
public function __construct(private Engine $engine) {}
public function get($path, array $data = []): string {
return $this->engine->get($path, $data);
}
};
});
view('mix')->render();
})->throwsNoExceptions();
test('supports antlers engine', function () {
// Statamic serializes all view data, we need to make sure
// we don't inject BlazeRuntime which is not serializable.
app('view')->addExtension('antlers.html', 'antlers', function () {
return new class implements Engine {
public function get($path, array $data = []): string {
return isset($data['__blaze']) ? 'BLAZE' : 'NO_BLAZE';
}
};
});
expect(view('antlers-view')->render())->toBe('NO_BLAZE');
});
test('forwards $__this through component chain', function () {
app()->register(\Livewire\LivewireServiceProvider::class);
\Livewire\Livewire::test(new class extends \Livewire\Component {
public string $name = 'from-livewire';
public function render()
{
return '<x-this-parent />';
}
})->assertSee('from-livewire');
});
test('View::share variables are accessible in components', function () {
View::share('sharedValue', 'hello-from-share');
$html = Blade::render('<x-shared-var />');
expect($html)->toContain('hello-from-share');
});
test('folds and compiles the same component', function () {
Blade::render(<<<'BLADE'
<x-foldable.input required /> {{-- Folded --}}
<x-foldable.input :required="$required" /> {{-- Compiled (fallback) --}}
BLADE,
['required' => true]
);
})->throwsNoExceptions();