|
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\Context; |
|
18
|
|
|
use Xabbuh\XApi\Model\Group; |
|
19
|
|
|
use Xabbuh\XApi\Model\InverseFunctionalIdentifier; |
|
20
|
|
|
use Xabbuh\XApi\Model\LanguageMap; |
|
21
|
|
|
use Xabbuh\XApi\Model\Result; |
|
22
|
|
|
use Xabbuh\XApi\Model\Statement; |
|
23
|
|
|
use Xabbuh\XApi\Model\StatementId; |
|
24
|
|
|
use Xabbuh\XApi\Model\StatementReference; |
|
25
|
|
|
use Xabbuh\XApi\Model\Verb; |
|
26
|
|
|
|
|
27
|
|
|
class StatementSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let() |
|
30
|
|
|
{ |
|
31
|
|
|
$id = StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'); |
|
32
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
33
|
|
|
$verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test'))); |
|
34
|
|
|
$object = new Activity('http://tincanapi.com/conformancetest/activityid'); |
|
35
|
|
|
$this->beConstructedWith($id, $actor, $verb, $object); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_creates_reference_to_itself() |
|
39
|
|
|
{ |
|
40
|
|
|
$reference = $this->getStatementReference(); |
|
41
|
|
|
$reference->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference'); |
|
42
|
|
|
$reference->getStatementId()->equals(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'))->shouldReturn(true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function it_creates_statement_voiding_itself() |
|
46
|
|
|
{ |
|
47
|
|
|
$voidingActor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
48
|
|
|
$voidingStatement = $this->getVoidStatement($voidingActor); |
|
49
|
|
|
$voidingStatement->getActor()->shouldBe($voidingActor); |
|
50
|
|
|
$voidingStatement->getVerb()->getId()->shouldReturn('http://adlnet.gov/expapi/verbs/voided'); |
|
51
|
|
|
|
|
52
|
|
|
$voidedStatement = $voidingStatement->getObject(); |
|
53
|
|
|
$voidedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference'); |
|
54
|
|
|
$voidedStatement->getStatementId()->equals(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'))->shouldReturn(true); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
function it_can_be_authorized() |
|
58
|
|
|
{ |
|
59
|
|
|
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
60
|
|
|
$authorizedStatement = $this->withAuthority($authority); |
|
61
|
|
|
$authorizedStatement->getAuthority()->shouldReturn($authority); |
|
62
|
|
|
|
|
63
|
|
|
$authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement'); |
|
64
|
|
|
$authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true); |
|
65
|
|
|
$authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true); |
|
66
|
|
|
$authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function it_overrides_existing_authority_when_it_is_authorized() |
|
70
|
|
|
{ |
|
71
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
72
|
|
|
$verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test'))); |
|
73
|
|
|
$object = new Activity('http://tincanapi.com/conformancetest/activityid'); |
|
74
|
|
|
$authority = new Group(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
75
|
|
|
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, $authority); |
|
76
|
|
|
|
|
77
|
|
|
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
78
|
|
|
$authorizedStatement = $this->withAuthority($authority); |
|
79
|
|
|
$authorizedStatement->getAuthority()->shouldReturn($authority); |
|
80
|
|
|
|
|
81
|
|
|
$authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement'); |
|
82
|
|
|
$authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true); |
|
83
|
|
|
$authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true); |
|
84
|
|
|
$authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true); |
|
85
|
|
|
$authorizedStatement->getAuthority()->equals($this->getAuthority())->shouldBe(false); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
function its_object_can_be_an_agent() |
|
89
|
|
|
{ |
|
90
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
91
|
|
|
$verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test'))); |
|
92
|
|
|
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
93
|
|
|
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object); |
|
94
|
|
|
|
|
95
|
|
|
$this->getObject()->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Object'); |
|
96
|
|
|
$this->getObject()->shouldBe($object); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
function it_does_not_equal_another_statement_with_different_timestamp() |
|
100
|
|
|
{ |
|
101
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
102
|
|
|
$verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test'))); |
|
103
|
|
|
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
104
|
|
|
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00')); |
|
105
|
|
|
|
|
106
|
|
|
$otherStatement = new Statement(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2015-07-23T12:34:02-05:00')); |
|
107
|
|
|
|
|
108
|
|
|
$this->equals($otherStatement)->shouldBe(false); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
function it_equals_another_statement_with_same_timestamp() |
|
112
|
|
|
{ |
|
113
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')); |
|
114
|
|
|
$verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test'))); |
|
115
|
|
|
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
116
|
|
|
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00')); |
|
117
|
|
|
|
|
118
|
|
|
$otherStatement = new Statement(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00')); |
|
119
|
|
|
|
|
120
|
|
|
$this->equals($otherStatement)->shouldBe(true); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function it_returns_a_new_instance_with_id() |
|
124
|
|
|
{ |
|
125
|
|
|
$id = StatementId::fromString('12345678-1234-5678-8234-567812345678'); |
|
126
|
|
|
$statement = $this->withId($id); |
|
127
|
|
|
|
|
128
|
|
|
$statement->shouldNotBe($this); |
|
129
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
130
|
|
|
$statement->getId()->shouldReturn($id); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function it_returns_a_new_instance_with_actor() |
|
134
|
|
|
{ |
|
135
|
|
|
$actor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
136
|
|
|
$statement = $this->withActor($actor); |
|
137
|
|
|
|
|
138
|
|
|
$statement->shouldNotBe($this); |
|
139
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
140
|
|
|
$statement->getActor()->shouldReturn($actor); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function it_returns_a_new_instance_with_verb() |
|
144
|
|
|
{ |
|
145
|
|
|
$verb = new Verb('http://adlnet.gov/expapi/verbs/voided'); |
|
146
|
|
|
$statement = $this->withVerb($verb); |
|
147
|
|
|
|
|
148
|
|
|
$statement->shouldNotBe($this); |
|
149
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
150
|
|
|
$statement->getVerb()->shouldReturn($verb); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function it_returns_a_new_instance_with_object() |
|
154
|
|
|
{ |
|
155
|
|
|
$statementReference = new StatementReference(StatementId::fromString('12345678-1234-5678-8234-567812345678')); |
|
156
|
|
|
$statement = $this->withObject($statementReference); |
|
157
|
|
|
|
|
158
|
|
|
$statement->shouldNotBe($this); |
|
159
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
160
|
|
|
$statement->getObject()->shouldReturn($statementReference); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function it_returns_a_new_instance_with_result() |
|
164
|
|
|
{ |
|
165
|
|
|
$result = new Result(); |
|
166
|
|
|
$statement = $this->withResult($result); |
|
167
|
|
|
|
|
168
|
|
|
$statement->shouldNotBe($this); |
|
169
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
170
|
|
|
$statement->getResult()->shouldReturn($result); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function it_returns_a_new_instance_with_authority() |
|
174
|
|
|
{ |
|
175
|
|
|
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com')); |
|
176
|
|
|
$statement = $this->withAuthority($authority); |
|
177
|
|
|
|
|
178
|
|
|
$statement->shouldNotBe($this); |
|
179
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
180
|
|
|
$statement->getAuthority()->shouldReturn($authority); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function it_returns_a_new_instance_with_timestamp() |
|
184
|
|
|
{ |
|
185
|
|
|
$timestamp = new \DateTime('2014-07-23T12:34:02-05:00'); |
|
186
|
|
|
$statement = $this->withTimestamp($timestamp); |
|
187
|
|
|
|
|
188
|
|
|
$statement->shouldNotBe($this); |
|
189
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
190
|
|
|
$statement->getTimestamp()->shouldReturn($timestamp); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function it_returns_a_new_instance_with_stored() |
|
194
|
|
|
{ |
|
195
|
|
|
$stored = new \DateTime('2014-07-23T12:34:02-05:00'); |
|
196
|
|
|
$statement = $this->withStored($stored); |
|
197
|
|
|
|
|
198
|
|
|
$statement->shouldNotBe($this); |
|
199
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
200
|
|
|
$statement->getStored()->shouldReturn($stored); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function it_returns_a_new_instance_with_context() |
|
204
|
|
|
{ |
|
205
|
|
|
$context = new Context(); |
|
206
|
|
|
$statement = $this->withContext($context); |
|
207
|
|
|
|
|
208
|
|
|
$statement->shouldNotBe($this); |
|
209
|
|
|
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement'); |
|
210
|
|
|
$statement->getContext()->shouldReturn($context); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|