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