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.
* @brief ActionsControllerTest
* @author dev <dev@maarch.org>
* @ingroup core
*/
use PHPUnit\Framework\TestCase;
class AutocompleteControllerTest extends TestCase
{
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
public function testGetContacts()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET COLOR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maarch',
'color' => true
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContacts($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertSame('contact', $value->type);
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->contact);
$this->assertInternalType('string', $value->address);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertSame('#', substr($value->rateColor, 0, 1));
$this->assertInternalType('string', substr($value->rateColor, 0));
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->contact);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
$this->assertNotEmpty(substr($value->rateColor, 1));
}
// GET NO COLOR
$aArgs = [
'search' => 'maarch',
'color' => false
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContacts($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertSame('contact', $value->type);
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->contact);
$this->assertInternalType('string', $value->address);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->contact);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
$this->assertEmpty($value->rateColor);
}
}
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maarch',
'type' => 'all'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContactsForGroups($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertInternalType('int', $responseBody[0]->position);
$this->assertInternalType('int', $responseBody[0]->addressId);
$this->assertInternalType('string', $responseBody[0]->contact);
$this->assertInternalType('string', $responseBody[0]->address);
}
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
public function testGetContactsAndUsers()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maarch',
'color' => true,
'onlyContacts' => 'true'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContactsAndUsers($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
foreach ($responseBody as $value) {
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertNotEmpty($value->type);
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
if ($value->type == 'contact') {
$this->assertNotEmpty($value->rateColor);
}
}
}
public function testGetUsers()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'bain'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getUsers($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertSame('user', $responseBody[0]->type);
$this->assertInternalType('string', $responseBody[0]->id);
$this->assertNotEmpty($responseBody[0]->id);
$this->assertInternalType('string', $responseBody[0]->idToDisplay);
$this->assertNotEmpty($responseBody[0]->idToDisplay);
$this->assertInternalType('string', $responseBody[0]->otherInfo);
}
public function testGetUsersForAdministration()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'bern',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getUsersForAdministration($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertSame('user', $responseBody[0]->type);
$this->assertInternalType('int', $responseBody[0]->id);
$this->assertNotEmpty($responseBody[0]->id);
$this->assertInternalType('string', $responseBody[0]->idToDisplay);
$this->assertNotEmpty($responseBody[0]->idToDisplay);
}
public function testGetUsersForVisa()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'dau',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getUsersForVisa($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertSame('user', $responseBody[0]->type);
$this->assertInternalType('string', $responseBody[0]->id);
$this->assertNotEmpty($responseBody[0]->id);
$this->assertInternalType('string', $responseBody[0]->idToDisplay);
$this->assertNotEmpty($responseBody[0]->idToDisplay);
$this->assertInternalType('string', $responseBody[0]->otherInfo);
}
public function testGetEntities()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'mai',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getEntities($fullRequest, new \Slim\Http\Response());
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertSame('entity', $responseBody[0]->type);
$this->assertInternalType('string', $responseBody[0]->id);
$this->assertNotEmpty($responseBody[0]->id);
$this->assertInternalType('string', $responseBody[0]->idToDisplay);
$this->assertNotEmpty($responseBody[0]->idToDisplay);
$this->assertInternalType('string', $responseBody[0]->otherInfo);
}
public function testGetStatuses()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $autocompleteController->getStatuses($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertSame('status', $responseBody[0]->type);
$this->assertInternalType('string', $responseBody[0]->id);
$this->assertNotEmpty($responseBody[0]->id);
$this->assertInternalType('string', $responseBody[0]->idToDisplay);
$this->assertNotEmpty($responseBody[0]->idToDisplay);
$this->assertInternalType('string', $responseBody[0]->otherInfo);
}
public function testGetBanAddresses()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'department' => '75',
'address' => 'italie'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getBanAddresses($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
$this->assertInternalType('string', $responseBody[0]->banId);
$this->assertNotEmpty($responseBody[0]->banId);
$this->assertInternalType('string', $responseBody[0]->number);
$this->assertNotEmpty($responseBody[0]->number);
$this->assertInternalType('string', $responseBody[0]->afnorName);
$this->assertNotEmpty($responseBody[0]->afnorName);
$this->assertInternalType('string', $responseBody[0]->postalCode);
$this->assertNotEmpty($responseBody[0]->postalCode);
$this->assertInternalType('string', $responseBody[0]->city);
$this->assertNotEmpty($responseBody[0]->city);
$this->assertInternalType('string', $responseBody[0]->address);
$this->assertNotEmpty($responseBody[0]->address);
// Errors
$aArgs = [
'department' => '100',
'address' => 'italie'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getBanAddresses($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Department indexes do not exist', $responseBody->errors);
$response = $autocompleteController->getBanAddresses($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Bad Request', $responseBody->errors);
}
}