/
LeaveBreadcrumbsTest.php
105 lines (87 loc) · 3.58 KB
/
LeaveBreadcrumbsTest.php
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
105
<?php
namespace spec\watoki\qrator;
use watoki\curir\cookie\Cookie;
use watoki\qrator\web\ExecuteResource;
use watoki\scrut\Specification;
/**
* @property \spec\watoki\qrator\fixtures\ResourceFixture resource <-
* @property \spec\watoki\reflect\fixtures\ClassFixture class <-
* @property \spec\watoki\qrator\fixtures\DispatcherFixture dispatcher <-
*/
class LeaveBreadcrumbsTest extends Specification {
protected function background() {
$this->class->givenTheClass('test\SomeAction');
$this->dispatcher->givenISet_AsHandlerFor('myHandler', 'test\SomeAction');
}
function testStoreBreadcrumbsInCookie() {
$this->class->givenTheClass_WithTheBody('test\FooAction', '
public $foo;
');
$this->resource->givenTheActionArgument_Is('foo', 'bar');
$this->whenIExecuteTheAction('test\SomeAction');
$this->thenTheBreadcrumbs_ShouldBeStored([
['Some Action', 'test\SomeAction', ['foo' => 'bar']]
]);
}
function testNoBreadcrumbsToShow() {
$this->whenIExecuteTheAction('test\SomeAction');
$this->thenThereShouldBe_Breadcrumbs(1);
$this->thenBreadcrumb_ShouldHaveTheCaption(1, 'Some Action');
}
function testShowBreadcrumbs() {
$this->givenTheStoredBreadcrumbs([
['one', 'first', []],
['two', 'second', []]
]);
$this->whenIExecuteTheAction('test\SomeAction');
$this->thenThereShouldBe_Breadcrumbs(3);
$this->thenBreadcrumb_ShouldHaveTheCaption(1, 'one');
$this->thenBreadcrumb_ShouldHaveTheLinkTarget(1, 'execute?action=first');
}
function testPushAction() {
$this->givenTheStoredBreadcrumbs([
['one', 'first', []]
]);
$this->whenIExecuteTheAction('test\SomeAction');
$this->thenTheBreadcrumbs_ShouldBeStored([
['one', 'first', []],
['Some Action', 'test\SomeAction', []]
]);
}
function testPopAction() {
$this->givenTheStoredBreadcrumbs([
['one', 'first', []],
['two', 'test\SomeAction', []],
['three', 'test\SomeAction', ['foo' => 'bar']],
['four', '?action=second']
]);
$this->whenIExecuteTheAction('test\SomeAction');
$this->thenTheBreadcrumbs_ShouldBeStored([
['one', 'first', []],
['Some Action', 'test\SomeAction', []]
]);
}
################################################################################################
private function whenIExecuteTheAction($action) {
$this->resource->whenIDo_With(function (ExecuteResource $resource) use ($action) {
return $resource->doGet($action, $this->resource->args);
}, ExecuteResource::class);
}
private function thenTheBreadcrumbs_ShouldBeStored($array) {
$this->resource->thenThePayloadOfCookie_ShouldBe(ExecuteResource::BREADCRUMB_COOKIE, $array);
}
private function givenTheStoredBreadcrumbs($array) {
$this->resource->cookies->create(new Cookie($array), ExecuteResource::BREADCRUMB_COOKIE);
}
private function thenThereShouldBe_Breadcrumbs($int) {
$this->resource->thenThereShouldBe_Of($int, 'breadcrumbs/breadcrumb');
}
private function thenBreadcrumb_ShouldHaveTheCaption($int, $string) {
$int--;
$this->resource->then_ShouldBe("breadcrumbs/breadcrumb/$int/caption", $string);
}
private function thenBreadcrumb_ShouldHaveTheLinkTarget($int, $string) {
$int--;
$this->resource->then_ShouldBe("breadcrumbs/breadcrumb/$int/link/href", $string);
}
}