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 Xabbuh\XApi\Client\Tests\Api; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Client\Api\StateApiClient; |
15
|
|
|
use Xabbuh\XApi\DataFixtures\DocumentFixtures; |
16
|
|
|
use Xabbuh\XApi\Model\Activity; |
17
|
|
|
use Xabbuh\XApi\Model\Agent; |
18
|
|
|
use Xabbuh\XApi\Model\InverseFunctionalIdentifier; |
19
|
|
|
use Xabbuh\XApi\Model\IRI; |
20
|
|
|
use Xabbuh\XApi\Model\State; |
21
|
|
|
use Xabbuh\XApi\Serializer\ActorSerializer; |
22
|
|
|
use Xabbuh\XApi\Serializer\DocumentDataSerializer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Christian Flothmann <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class StateApiClientTest extends ApiClientTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var StateApiClient |
31
|
|
|
*/ |
32
|
|
|
private $client; |
33
|
|
|
|
34
|
|
|
protected function setUp() |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
$this->client = new StateApiClient( |
38
|
|
|
$this->requestHandler, |
39
|
|
|
'1.0.1', |
40
|
|
|
new DocumentDataSerializer($this->serializer), |
41
|
|
|
new ActorSerializer($this->serializer) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCreateOrUpdateDocument() |
46
|
|
|
{ |
47
|
|
|
$document = DocumentFixtures::getStateDocument(); |
48
|
|
|
|
49
|
|
|
$this->validateStoreApiCall( |
50
|
|
|
'post', |
51
|
|
|
'activities/state', |
52
|
|
|
array( |
53
|
|
|
'activityId' => 'activity-id', |
54
|
|
|
'agent' => 'agent-as-json', |
55
|
|
|
'stateId' => 'state-id', |
56
|
|
|
), |
57
|
|
|
204, |
58
|
|
|
'', |
59
|
|
|
$document->getData(), |
60
|
|
|
array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json')) |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->client->createOrUpdateDocument($document); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testCreateOrReplaceDocument() |
67
|
|
|
{ |
68
|
|
|
$document = DocumentFixtures::getStateDocument(); |
69
|
|
|
|
70
|
|
|
$this->validateStoreApiCall( |
71
|
|
|
'put', |
72
|
|
|
'activities/state', |
73
|
|
|
array( |
74
|
|
|
'activityId' => 'activity-id', |
75
|
|
|
'agent' => 'agent-as-json', |
76
|
|
|
'stateId' => 'state-id', |
77
|
|
|
), |
78
|
|
|
204, |
79
|
|
|
'', |
80
|
|
|
$document->getData(), |
81
|
|
|
array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json')) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->client->createOrReplaceDocument($document); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testDeleteDocument() |
88
|
|
|
{ |
89
|
|
|
$state = $this->createState(); |
90
|
|
|
|
91
|
|
|
$this->validateDeleteDocumentCall( |
92
|
|
|
'activities/state', |
93
|
|
|
array( |
94
|
|
|
'activityId' => 'activity-id', |
95
|
|
|
'agent' => 'agent-as-json', |
96
|
|
|
'stateId' => 'state-id', |
97
|
|
|
), |
98
|
|
|
array(array('data' => $state->getActor(), 'result' => 'agent-as-json')) |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->client->deleteDocument($state); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testGetDocument() |
105
|
|
|
{ |
106
|
|
|
$document = DocumentFixtures::getStateDocument(); |
107
|
|
|
$state = $document->getState(); |
108
|
|
|
|
109
|
|
|
$this->validateRetrieveApiCall( |
110
|
|
|
'get', |
111
|
|
|
'activities/state', |
112
|
|
|
array( |
113
|
|
|
'activityId' => 'activity-id', |
114
|
|
|
'agent' => 'agent-as-json', |
115
|
|
|
'stateId' => 'state-id', |
116
|
|
|
), |
117
|
|
|
200, |
118
|
|
|
'DocumentData', |
119
|
|
|
$document->getData(), |
120
|
|
|
array(array('data' => $state->getActor(), 'result' => 'agent-as-json')) |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$document = $this->client->getDocument($state); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf('Xabbuh\XApi\Model\StateDocument', $document); |
126
|
|
|
$this->assertEquals($state, $document->getState()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
private function createState() |
130
|
|
|
{ |
131
|
|
|
$agent = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]'))); |
132
|
|
|
$activity = new Activity(IRI::fromString('activity-id')); |
133
|
|
|
$state = new State($activity, $agent, 'state-id'); |
134
|
|
|
|
135
|
|
|
return $state; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|