Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
private static $id = null;
public function testCreate()
{
$resController = new \Resource\controllers\ResController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$fileContent = file_get_contents('modules/convert/Test/Samples/test.txt');
$encodedFile = base64_encode($fileContent);
$data = [
[
'column' => 'subject',
'value' => 'Breaking News : Superman is alive',
'type' => 'string',
],
[
'column' => 'type_id',
'value' => 102,
'type' => 'integer',
],
[
'column' => 'typist',
'value' => 'LLane',
'type' => 'string',
]
];
$aArgs = [
'collId' => 'letterbox_coll',
'table' => 'res_letterbox',
'status' => 'NEW',
'encodedFile' => $encodedFile,
'fileFormat' => 'txt',
'data' => $data
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->resId;
$this->assertInternalType('int', self::$id);
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertInternalType('array', $res);
$this->assertSame('Breaking News : Superman is alive', $res['subject']);
$this->assertSame(null, $res['title']);
$this->assertSame(null, $res['description']);
$this->assertSame(102, $res['type_id']);
$this->assertSame('txt', $res['format']);
$this->assertSame('NEW', $res['status']);
$this->assertSame('LLane', $res['typist']);
$this->assertSame(null, $res['destination']);
}
public function testUpdateStatus()
{
$resController = new \Resource\controllers\ResController();
// UPDATE STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
Pegane Nestor
committed
'resId' => [self::$id],
'status' => 'EVIS'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertInternalType('array', $res);
$this->assertSame('EVIS', $res['status']);
// UPDATE WITHOUT STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
Pegane Nestor
committed
'resId' => [self::$id]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertInternalType('array', $res);
$this->assertSame('COU', $res['status']);
}
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
public function testUpdateExternalInfos(){
$resController = new \Resource\controllers\ResController();
// UPDATE STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
//ALL OK
$aArgs = [
'externalInfos' => [
[
'res_id' => self::$id,
'external_id' => "BB981212IIYZ",
'external_link' => "https://publik.nancy.fr/res/BB981212BB65"
]
],
'status' => "GRCSENT"
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('success', $responseBody->success);
// EXTERNAL INFOS EMPTY AND RES ID IS NOT INTEGER
$aArgs = [
'externalInfos' => [
[
'res_id' => "res_id",
'external_id' => "",
'external_link' => ""
]
],
'status' => "GRCSENT"
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('Bad Request', $responseBody->errors);
// DOCUMENT DOES NOT EXIST
$aArgs = [
'externalInfos' => [
[
'res_id' => 123456789,
'external_id' => "BB981212IIYZ",
'external_link' => "https://publik.nancy.fr/res/BB981212BB65"
]
],
'status' => 'GRCSENT'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame(_DOCUMENT_NOT_FOUND, $responseBody->errors);
//MISSING EXTERNAL INFO
$aArgs = [
'externalInfos' => [
[
'res_id' => 123456789,
'external_id' => "BB981212IIYZ",
'external_link' => "https://publik.nancy.fr/res/BB981212BB65"
]
],
'status' => NULL
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('Bad Request', $responseBody->errors);
//MISSING STATUS
$aArgs = [
'externalInfos' => NULL,
'status' => "GRCSENT"
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('Bad Request', $responseBody->errors);
}
public function testDelete()
{
// DELETE
\Resource\models\ResModel::delete(['resId' => self::$id]);
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertInternalType('array', $res);
$this->assertSame('DEL', $res['status']);
// REAL DELETE
'table' => 'res_letterbox',
'where' => ['res_id = ?'],
'data' => [self::$id]
]);
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertSame(null, $res);
}