forked from EFTEC/BladeOne
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopTest.php
More file actions
91 lines (87 loc) · 2.46 KB
/
Copy pathLoopTest.php
File metadata and controls
91 lines (87 loc) · 2.46 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
<?php
namespace eftec\tests;
/**
* @author G.J.W. Oolbekkink <g.j.w.oolbekkink@gmail.com>
* @since 17/09/2018
*/
class LoopTest extends AbstractBladeTestCase
{
/**
* @throws \Exception
*/
public function testFor()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@for($i = 1; $i <= 6; $i++)
Nr. {{ $i }}
@endfor
BLADE;
$this->assertEqualsIgnoringWhitespace("Nr. 1 Nr. 2 Nr. 3 Nr.4 Nr. 5 Nr. 6", $this->blade->runString($bladeSource, []));
}
/**
* @throws \Exception
*/
public function testForEach()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@foreach($items as $item)
Item {{ $item }}
@endforeach
BLADE;
$this->assertEqualsIgnoringWhitespace("Item a Item b", $this->blade->runString($bladeSource, ['items' => ['a', 'b']]));
}
/**
* @throws \Exception
*/
public function testForEachLoopVar()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@foreach($items as $item)
Item_index:{{$loop->index}},iteration:{{$loop->iteration}},first:{{$loop->first}}
,last:{{$loop->last}},remaining:{{$loop->remaining}}
,count:{{$loop->count}},depth:{{$loop->depth}},parent:{{$loop->parent}}
,even:{{$loop->even}},odd:{{$loop->odd}},value{{ $item }}
@endforeach
BLADE;
$this->assertEqualsIgnoringWhitespace("Item_index:0,iteration:1,first:1"."
,last:,remaining:2"."
,count:2,depth:1,parent:"."
,even:1,odd:,valuea"."
Item_index:1,iteration:2,first:"."
,last:1,remaining:1,count:2,depth:1,parent:"."
,even:,odd:1,valueb", $this->blade->runString($bladeSource, ['items' => ['a', 'b']]));
}
/**
* @throws \Exception
*/
public function testForElse()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@forelse($items as $item)
Item {{ $item }}
@empty
No Items
@endforelse
BLADE;
$this->assertEqualsIgnoringWhitespace("Item a Item b", $this->blade->runString($bladeSource, ['items' => ['a', 'b']]));
$this->assertEqualsIgnoringWhitespace("No Items", $this->blade->runString($bladeSource, ['items' => []]));
}
/**
* @throws \Exception
*/
public function testWhile()
{
$bladeSource = <<<'BLADE'
@php($i = 1)
@while($i < 5)
@php($i++)
Item {{ $i }}
@endwhile
BLADE;
$this->assertEqualsIgnoringWhitespace("Item 2 Item 3 Item 4 Item 5", $this->blade->runString($bladeSource, []));
}
}