1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Xabbuh\XApi\Model; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Xabbuh\XApi\Model\Activity; |
7
|
|
|
use Xabbuh\XApi\Model\Agent; |
8
|
|
|
use Xabbuh\XApi\Model\InverseFunctionalIdentifier; |
9
|
|
|
use Xabbuh\XApi\Model\Verb; |
10
|
|
|
|
11
|
|
|
class StatementsFilterSpec extends ObjectBehavior |
12
|
|
|
{ |
13
|
|
|
function it_does_not_filter_anything_by_default() |
14
|
|
|
{ |
15
|
|
|
$filter = $this->getFilter(); |
16
|
|
|
$filter->shouldHaveCount(0); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_can_filter_by_actor() |
20
|
|
|
{ |
21
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
22
|
|
|
$this->byActor($actor); |
23
|
|
|
|
24
|
|
|
$filter = $this->getFilter(); |
25
|
|
|
$filter->shouldHaveCount(1); |
26
|
|
|
$filter->shouldHaveKeyWithValue('agent', $actor); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_can_filter_by_verb() |
30
|
|
|
{ |
31
|
|
|
$this->byVerb(new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'))); |
32
|
|
|
|
33
|
|
|
$filter = $this->getFilter(); |
34
|
|
|
$filter->shouldHaveCount(1); |
35
|
|
|
$filter->shouldHaveKeyWithValue('verb', 'http://tincanapi.com/conformancetest/verbid'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_can_filter_by_activity() |
39
|
|
|
{ |
40
|
|
|
$this->byActivity(new Activity('http://tincanapi.com/conformancetest/activityid')); |
41
|
|
|
|
42
|
|
|
$filter = $this->getFilter(); |
43
|
|
|
$filter->shouldHaveCount(1); |
44
|
|
|
$filter->shouldHaveKeyWithValue('activity', 'http://tincanapi.com/conformancetest/activityid'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_can_filter_by_registration() |
48
|
|
|
{ |
49
|
|
|
$this->byRegistration('foo'); |
50
|
|
|
|
51
|
|
|
$filter = $this->getFilter(); |
52
|
|
|
$filter->shouldHaveCount(1); |
53
|
|
|
$filter->shouldHaveKeyWithValue('registration', 'foo'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_can_enable_to_filter_related_activities() |
57
|
|
|
{ |
58
|
|
|
$this->enableRelatedActivityFilter(); |
59
|
|
|
|
60
|
|
|
$filter = $this->getFilter(); |
61
|
|
|
$filter->shouldHaveCount(1); |
62
|
|
|
$filter->shouldHaveKeyWithValue('related_activities', true); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_can_disable_to_filter_related_activities() |
66
|
|
|
{ |
67
|
|
|
$this->disableRelatedActivityFilter(); |
68
|
|
|
|
69
|
|
|
$filter = $this->getFilter(); |
70
|
|
|
$filter->shouldHaveCount(1); |
71
|
|
|
$filter->shouldHaveKeyWithValue('related_activities', false); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
function it_can_enable_to_filter_related_agents() |
75
|
|
|
{ |
76
|
|
|
$this->enableRelatedAgentFilter(); |
77
|
|
|
|
78
|
|
|
$filter = $this->getFilter(); |
79
|
|
|
$filter->shouldHaveCount(1); |
80
|
|
|
$filter->shouldHaveKeyWithValue('related_agents', true); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function it_can_disable_to_filter_related_agents() |
84
|
|
|
{ |
85
|
|
|
$this->disableRelatedAgentFilter(); |
86
|
|
|
|
87
|
|
|
$filter = $this->getFilter(); |
88
|
|
|
$filter->shouldHaveCount(1); |
89
|
|
|
$filter->shouldHaveKeyWithValue('related_agents', false); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function it_can_include_attachments() |
93
|
|
|
{ |
94
|
|
|
$this->includeAttachments(); |
95
|
|
|
|
96
|
|
|
$filter = $this->getFilter(); |
97
|
|
|
$filter->shouldHaveCount(1); |
98
|
|
|
$filter->shouldHaveKeyWithValue('attachments', true); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
function it_can_exclude_attachments() |
102
|
|
|
{ |
103
|
|
|
$this->excludeAttachments(); |
104
|
|
|
|
105
|
|
|
$filter = $this->getFilter(); |
106
|
|
|
$filter->shouldHaveCount(1); |
107
|
|
|
$filter->shouldHaveKeyWithValue('attachments', false); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function it_can_filter_by_timestamp() |
111
|
|
|
{ |
112
|
|
|
$this->since(\DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z')); |
113
|
|
|
$this->getFilter()->shouldHaveKeyWithValue('since', '2013-05-18T05:32:34+00:00'); |
114
|
|
|
|
115
|
|
|
$this->until(\DateTime::createFromFormat(\DateTime::ISO8601, '2014-05-18T05:32:34Z')); |
116
|
|
|
$this->getFilter()->shouldHaveKeyWithValue('until', '2014-05-18T05:32:34+00:00'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function it_can_sort_the_result_in_ascending_order() |
120
|
|
|
{ |
121
|
|
|
$this->ascending(); |
122
|
|
|
|
123
|
|
|
$filter = $this->getFilter(); |
124
|
|
|
$filter->shouldHaveCount(1); |
125
|
|
|
$filter->shouldHaveKeyWithValue('ascending', 'True'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
function it_can_sort_the_result_in_descending_order() |
129
|
|
|
{ |
130
|
|
|
$this->descending(); |
131
|
|
|
|
132
|
|
|
$filter = $this->getFilter(); |
133
|
|
|
$filter->shouldHaveCount(1); |
134
|
|
|
$filter->shouldHaveKeyWithValue('ascending', 'False'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
function it_can_limit_the_number_of_results() |
138
|
|
|
{ |
139
|
|
|
$this->limit(10); |
140
|
|
|
|
141
|
|
|
$filter = $this->getFilter(); |
142
|
|
|
$filter->shouldHaveCount(1); |
143
|
|
|
$filter->shouldHaveKeyWithValue('limit', 10); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function it_rejects_choosing_a_negative_number_of_results() |
147
|
|
|
{ |
148
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringLimit(-1); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
function it_can_change_the_result_format() |
152
|
|
|
{ |
153
|
|
|
$this->format('ids'); |
154
|
|
|
$this->getFilter()->shouldHaveKeyWithValue('format', 'ids'); |
155
|
|
|
|
156
|
|
|
$this->format('exact'); |
157
|
|
|
$this->getFilter()->shouldHaveKeyWithValue('format', 'exact'); |
158
|
|
|
|
159
|
|
|
$this->format('canonical'); |
160
|
|
|
$this->getFilter()->shouldHaveKeyWithValue('format', 'canonical'); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
function it_rejects_invalid_format_filter() |
164
|
|
|
{ |
165
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringFormat('minimal'); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|