|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Stempler; |
|
13
|
|
|
|
|
14
|
|
|
use Spiral\Views\Exception\CompileException; |
|
15
|
|
|
use Spiral\Views\Exception\RenderException; |
|
16
|
|
|
use Spiral\Views\ViewContext; |
|
17
|
|
|
|
|
18
|
|
|
class DirectiveTest extends BaseTest |
|
19
|
|
|
{ |
|
20
|
|
|
public function testRenderDirectiveEx(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->expectException(RenderException::class); |
|
23
|
|
|
|
|
24
|
|
|
$s = $this->getStempler(); |
|
25
|
|
|
|
|
26
|
|
|
$s->get('directive', new ViewContext()) |
|
27
|
|
|
->render() |
|
28
|
|
|
; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testRenderDirective(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$s = $this->getStempler(); |
|
34
|
|
|
$this->container->bind(TestInjection::class, new TestInjection('abc')); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertSame('abc', $s->get('directive', new ViewContext())->render()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testRenderDirectiveAsArray(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$s = $this->getStempler(); |
|
42
|
|
|
$this->container->bind(TestInjection::class, new TestInjection('abc')); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertSame('abc', $s->get('directive2', new ViewContext())->render()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testBadDirective(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->expectException(CompileException::class); |
|
50
|
|
|
|
|
51
|
|
|
$s = $this->getStempler(); |
|
52
|
|
|
$this->container->bind(TestInjection::class, new TestInjection('abc')); |
|
53
|
|
|
|
|
54
|
|
|
$s->get('bad-directive', new ViewContext()) |
|
55
|
|
|
->render() |
|
56
|
|
|
; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testRouteDirective(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$s = $this->getStempler() |
|
62
|
|
|
->getBuilder(new ViewContext()) |
|
63
|
|
|
; |
|
64
|
|
|
$this->assertSame( |
|
65
|
|
|
"<?php echo \$this->container->get(\Spiral\Stempler\Directive\RouteDirective::class)" |
|
66
|
|
|
. "->uri('home', ['action' => 'index']); ?>", |
|
67
|
|
|
$s->compile('route') |
|
68
|
|
|
->getContent() |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|