Completed
Push — master ( 2bedd9...b42c0c )
by Christian
02:23
created

StatementsFilterSpec   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

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