1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jhoff\BladeVue\Testing\Integration; |
4
|
|
|
|
5
|
|
|
use Jhoff\BladeVue\Testing\TestCase; |
6
|
|
|
|
7
|
|
|
class BladeTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @test |
11
|
|
|
*/ |
12
|
|
|
public function bladeRendersBasicVueDirective() |
13
|
|
|
{ |
14
|
|
|
$output = $this->renderBasicBlade('"my-component"'); |
15
|
|
|
|
16
|
|
|
$this->assertStringContainsString('<component', $output); |
17
|
|
|
$this->assertStringContainsString('is="my-component"', $output); |
18
|
|
|
$this->assertStringContainsString('</component>', $output); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
*/ |
24
|
|
|
public function bladeRendersAdvancedVueDirective() |
25
|
|
|
{ |
26
|
|
|
$output = $this->renderBasicBlade('"my-component", ["foo" => "bar"]'); |
27
|
|
|
|
28
|
|
|
$this->assertStringContainsString('<component', $output); |
29
|
|
|
$this->assertStringContainsString('is="my-component"', $output); |
30
|
|
|
$this->assertStringContainsString('foo="bar"', $output); |
31
|
|
|
$this->assertStringContainsString('</component>', $output); |
32
|
|
|
} |
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function bladeRendersInlineVueDirective() |
37
|
|
|
{ |
38
|
|
|
$output = $this->renderInlineBlade('"my-component"'); |
39
|
|
|
|
40
|
|
|
$this->assertStringContainsString('<component', $output); |
41
|
|
|
$this->assertStringContainsString('inline-template', $output); |
42
|
|
|
$this->assertStringContainsString('is="my-component"', $output); |
43
|
|
|
$this->assertStringContainsString('</component>', $output); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function bladeRendersAdvancedInlineVueDirective() |
50
|
|
|
{ |
51
|
|
|
$output = $this->renderInlineBlade('"my-component", ["foo" => "bar"]'); |
52
|
|
|
|
53
|
|
|
$this->assertStringContainsString('<component', $output); |
54
|
|
|
$this->assertStringContainsString('inline-template', $output); |
55
|
|
|
$this->assertStringContainsString('is="my-component"', $output); |
56
|
|
|
$this->assertStringContainsString('foo="bar"', $output); |
57
|
|
|
$this->assertStringContainsString('</component>', $output); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Creates a vue file in the testbench views directory and renders it |
62
|
|
|
* |
63
|
|
|
* @param string $expression |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
protected function renderBasicBlade(string $expression) |
67
|
|
|
{ |
68
|
|
|
@file_put_contents( |
|
|
|
|
69
|
|
|
resource_path('views/vue.blade.php'), |
70
|
|
|
"@vue($expression)\n<div>Testing</div>\n@endvue" |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return view()->make('vue')->render(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Creates a vue file in the testbench views directory and renders it |
78
|
|
|
* |
79
|
|
|
* @param string $expression |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function renderInlineBlade(string $expression) |
83
|
|
|
{ |
84
|
|
|
@file_put_contents( |
|
|
|
|
85
|
|
|
resource_path('views/vue.blade.php'), |
86
|
|
|
"@inlinevue($expression)\n<div>Testing</div>\n@endinlinevue" |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
return view()->make('vue')->render(); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: