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.
*
*/
private static $id2 = null;
public function testGetDepartmentById()
{
$department = \Resource\controllers\DepartmentController::getById(['id' => '75']);
$this->assertSame('Paris', $department);
$department = \Resource\controllers\DepartmentController::getById(['id' => 'not a french department']);
$this->assertIsString($department);
$this->assertEmpty($department);
}
$GLOBALS['login'] = 'cchaplin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$resController = new \Resource\controllers\ResController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$fileContent = file_get_contents('test/unitTests/samples/test.txt');
$encodedFile = base64_encode($fileContent);
$aArgs = [
'status' => 'NEW',
'encodedFile' => $encodedFile,
'confidentiality' => false,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2029-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->resId;
$this->assertIsInt(self::$id);
$aArgs = [
'modelId' => 2,
'status' => 'NEW',
'confidentiality' => false,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2029-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertIsInt($responseBody['resId']);
self::$id2 = $responseBody['resId'];
$res = \Resource\models\ResModel::getById(['resId' => self::$id, 'select' => ['*']]);
$this->assertIsArray($res);
$this->assertSame('Breaking News : Superman is alive - PHP unit', $res['subject']);
$this->assertSame(102, $res['type_id']);
$this->assertSame('txt', $res['format']);
$this->assertSame('NEW', $res['status']);
$this->assertSame(19, $res['typist']);
$this->assertNotNull($res['destination']);
$this->assertNotNull($res['initiator']);
104
105
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
// ERROR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$fileContent = file_get_contents('test/unitTests/samples/test.txt');
$encodedFile = base64_encode($fileContent);
$aArgs = [
'status' => 'NEW',
'encodedFile' => $encodedFile,
'format' => 'txt',
'confidentiality' => false,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2029-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'tags' => [1, 2],
'folders' => [1, 2],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Body modelId is empty or not an integer', $responseBody->errors);
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Service forbidden', $responseBody->errors);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testGetById()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $resController->getById($request, new \Slim\Http\Response(), ['resId' => self::$id2]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(self::$id2, $responseBody->resId);
$this->assertSame(2, $responseBody->modelId);
$this->assertSame('outgoing', $responseBody->categoryId);
$this->assertEmpty($responseBody->chrono);
$this->assertSame('NEW', $responseBody->status);
$this->assertEmpty($responseBody->closingDate);
$this->assertNotEmpty($responseBody->creationDate);
$this->assertNotEmpty($responseBody->modificationDate);
$this->assertIsBool($responseBody->integrations->inShipping);
$this->assertIsBool($responseBody->integrations->inSignatureBook);
$this->assertSame('Breaking News : Superman is alive - PHP unit', $responseBody->subject);
$this->assertSame('2029-01-01 00:00:00', $responseBody->processLimitDate);
$this->assertSame('poiuytre1357nbvc', $responseBody->priority);
$this->assertSame(102, $responseBody->doctype);
$this->assertSame(15, $responseBody->destination);
$this->assertSame('2019-01-01 17:18:47', $responseBody->documentDate);
$this->assertEmpty($responseBody->arrivalDate);
$this->assertNotEmpty($responseBody->destinationLabel);
$this->assertSame("Nouveau courrier pour le service", $responseBody->statusLabel);
$this->assertIsBool($responseBody->statusAlterable);
$this->assertSame('Normal', $responseBody->priorityLabel);
$this->assertSame('#009dc5', $responseBody->priorityColor);
$this->assertIsArray($responseBody->senders);
$this->assertIsArray($responseBody->customFields);
$this->assertIsArray($responseBody->folders);
foreach ($responseBody->folders as $value) {
$this->assertIsInt($value);
}
$this->assertIsArray($responseBody->tags);
foreach ($responseBody->tags as $value) {
$this->assertIsInt($value);
}
// ERROR
$GLOBALS['login'] = 'cchaplin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getById($request, new \Slim\Http\Response(), ['resId' => 123748]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Document out of perimeter', $responseBody->errors);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
// LIGHT
$aArgs = [
'light' => true
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $resController->getById($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(self::$id, $responseBody->resId);
$this->assertSame(1, $responseBody->modelId);
$this->assertSame('incoming', $responseBody->categoryId);
$this->assertEmpty($responseBody->chrono);
$this->assertSame('NEW', $responseBody->status);
$this->assertEmpty($responseBody->closingDate);
$this->assertNotEmpty($responseBody->creationDate);
$this->assertNotEmpty($responseBody->modificationDate);
$this->assertIsBool($responseBody->integrations->inShipping);
$this->assertIsBool($responseBody->integrations->inSignatureBook);
$this->assertSame('Breaking News : Superman is alive - PHP unit', $responseBody->subject);
$this->assertSame('2029-01-01 00:00:00', $responseBody->processLimitDate);
$this->assertSame('poiuytre1357nbvc', $responseBody->priority);
public function testUpdate()
{
$resController = new \Resource\controllers\ResController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$fileContent = file_get_contents('test/unitTests/samples/test.txt');
$encodedFile = base64_encode($fileContent);
$tag = \Tag\models\TagModel::get([
'select' => ['id'],
'limit' => 1
]);
$tag = $tag[0]['id'];
$folder = \Folder\models\FolderModel::create([
'label' => 'FOLDER TEST',
'public' => false,
'user_id' => $GLOBALS['id'],
'parent_id' => null,
'level' => 0
]);
'modelId' => 1,
'status' => 'NEW',
'encodedFile' => $encodedFile,
'format' => 'txt',
'confidentiality' => true,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2030-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
'recipients' => [['type' => 'contact', 'id' => 2]],
'tags' => [$tag],
'folders' => [$folder],
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(204, $response->getStatusCode());
$aArgs = [
'modelId' => 1,
'status' => 'NEW',
'encodedFile' => $encodedFile,
'format' => 'txt',
'confidentiality' => true,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2030-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(204, $response->getStatusCode());
// READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id, 'select' => ['*']]);
$this->assertIsArray($res);
$this->assertSame('Breaking News : Superman is alive - PHP unit', $res['subject']);
$this->assertSame(102, $res['type_id']);
$this->assertSame('txt', $res['format']);
$this->assertSame('NEW', $res['status']);
$this->assertSame(19, $res['typist']);
$this->assertNotNull($res['destination']);
$this->assertNotNull($res['initiator']);
$this->assertSame('Y', $res['confidentiality']);
$this->assertSame('2030-01-01 00:00:00', $res['process_limit_date']);
// ERROR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'modelId' => 1,
'status' => 'NEW',
'encodedFile' => $encodedFile,
'confidentiality' => true,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2030-01-01',
'doctype' => 102,
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Body format is empty or not a string', $responseBody['errors']);
'status' => 'NEW',
'encodedFile' => $encodedFile,
'format' => 'txt',
'confidentiality' => false,
'documentDate' => '2019-01-01 17:18:47',
'arrivalDate' => '2019-01-01 17:18:47',
'processLimitDate' => '2029-01-01',
'destination' => 15,
'initiator' => 15,
'subject' => 'Breaking News : Superman is alive - PHP unit',
'typist' => 19,
'priority' => 'poiuytre1357nbvc',
'tags' => [1, 2],
'folders' => [1, 2],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Body doctype is empty or not an integer', $responseBody['errors']);
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => 'wrong format']);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Route resId is not an integer', $responseBody['errors']);
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->update($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Service forbidden', $responseBody['errors']);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
\Folder\models\FolderModel::delete([
'where' => ['id = ?'],
'data' => [$folder]
]);
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $resController->getOriginalFileContent($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(null, $responseBody);
// GET FILE CONTENT
$response = $resController->getFileContent($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(null, $responseBody);
// GET FILE CONTENT
$aArgs = [
'mode' => 'base64'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $resController->getFileContent($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertNotEmpty($responseBody->encodedDocument);
$this->assertSame('txt', $responseBody->originalFormat);
$this->assertNotEmpty($responseBody->originalCreatorId);
$aArgs = [
'mode' => 'base64'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $resController->getOriginalFileContent($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertNotEmpty($responseBody['encodedDocument']);
$this->assertIsString($responseBody['encodedDocument']);
$this->assertSame('txt', $responseBody['extension']);
$this->assertNotEmpty($responseBody['mimeType']);
$this->assertIsString($responseBody['mimeType']);
$response = $resController->getFileContent($request, new \Slim\Http\Response(), ['resId' => -2]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document does not exist', $responseBody['errors']);
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
$response = $resController->getFileContent($request, new \Slim\Http\Response(), ['resId' => self::$id2]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document has no file', $responseBody['errors']);
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getFileContent($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document out of perimeter', $responseBody['errors']);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getOriginalFileContent($request, new \Slim\Http\Response(), ['resId' => -2]);
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document does not exist', $responseBody['errors']);
$response = $resController->getOriginalFileContent($request, new \Slim\Http\Response(), ['resId' => self::$id2]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document has no file', $responseBody['errors']);
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getOriginalFileContent($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document out of perimeter', $responseBody['errors']);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testGetThumbnailContent()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $resController->getThumbnailContent($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertEmpty($responseBody);
$response = $resController->getThumbnailContent($request, new \Slim\Http\Response(), ['resId' => -2]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document does not exist', $responseBody['errors']);
$response = $resController->getThumbnailContent($request, new \Slim\Http\Response(), ['resId' => 'wrong format']);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('resId param is not an integer', $responseBody['errors']);
}
public function testGetItems()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// Errors
$response = $resController->getItems($request, new \Slim\Http\Response(), ['resId' => 'wrong format']);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document out of perimeter', $responseBody['errors']);
$response = $resController->getItems($request, new \Slim\Http\Response(), ['resId' => -2]);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document does not exist', $responseBody['errors']);
// Success
$response = $resController->getItems($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(0, $responseBody['linkedResources']);
$this->assertSame(0, $responseBody['attachments']);
$this->assertSame(0, $responseBody['diffusionList']);
$this->assertSame(0, $responseBody['visaCircuit']);
$this->assertSame(0, $responseBody['opinionCircuit']);
$this->assertSame(0, $responseBody['notes']);
$this->assertSame(0, $responseBody['emails']);
}
public function testGetField()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
// Errors
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getField($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document out of perimeter', $responseBody['errors']);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->getField($request, new \Slim\Http\Response(), ['resId' => self::$id, 'fieldId' => 'initiator']);
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Field out of perimeter', $responseBody['errors']);
$response = $resController->getField($request, new \Slim\Http\Response(), ['resId' => self::$id * 1000, 'fieldId' => 'destination']);
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document does not exist', $responseBody['errors']);
// Success
$response = $resController->getField($request, new \Slim\Http\Response(), ['resId' => self::$id2, 'fieldId' => 'externalId']);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertIsArray($responseBody['field']);
$this->assertEmpty($responseBody['field']);
$fullRequest = $request->withQueryParams(['alt' => true]);
$response = $resController->getField($fullRequest, new \Slim\Http\Response(), ['resId' => self::$id2, 'fieldId' => 'destination']);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(15, $responseBody['field']);
}
public function testGetEncodedDocument()
{
$resController = new \Resource\controllers\ResController();
$response = $resController::getEncodedDocument(['resId' => self::$id, 'original' => false]);
$this->assertIsString($response['encodedDocument']);
$this->assertNotEmpty($response['encodedDocument']);
$this->assertSame('Breaking News _ Superman is al.pdf', $response['fileName']);
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
public function testGetCategories()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $resController->getCategories($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertNotEmpty($responseBody->categories);
foreach ($responseBody->categories as $value) {
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->label);
}
}
public function testIsAllowedForCurrentUser()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $resController->isAllowedForCurrentUser($request, new \Slim\Http\Response(), ['resId' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->isAllowed);
// NOT ALLOWED
$GLOBALS['login'] = 'bbain';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$response = $resController->isAllowedForCurrentUser($request, new \Slim\Http\Response(), ['resId' => 123456]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(false, $responseBody->isAllowed);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testSetInIntegrations()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'resources' => [self::$id],
'integrations' => ['inSignatureBook' => true, 'inShipping' => true]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->setInIntegrations($fullRequest, new \Slim\Http\Response());
$this->assertSame(204, $response->getStatusCode());
// ERROR
$GLOBALS['login'] = 'bbain';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$aArgs = [
'resources' => [12345],
'integrations' => ['inSignatureBook' => true, 'inShipping' => true]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->setInIntegrations($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Document out of perimeter', $responseBody->errors);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testUpdateStatus()
{
$resController = new \Resource\controllers\ResController();
// UPDATE STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
Pegane Nestor
committed
'resId' => [self::$id],
$fullRequest = \httpRequestCustom::addContentInBody($body, $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, 'select' => ['*']]);
$this->assertIsArray($res);
$this->assertSame('EVIS', $res['status']);
// UPDATE WITHOUT STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
Pegane Nestor
committed
'resId' => [self::$id]
$fullRequest = \httpRequestCustom::addContentInBody($body, $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, 'select' => ['*']]);
$this->assertIsArray($res);
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
$body = [
'status' => 'STATUS_THAT_DOES_NOT_EXIST'
];
$fullRequest = \httpRequestCustom::addContentInBody($body, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(_STATUS_NOT_FOUND, $responseBody['errors']);
$body = [
'status' => 'EVIS',
];
$fullRequest = \httpRequestCustom::addContentInBody($body, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request', $responseBody['errors']);
$body = [
'status' => 'EVIS',
'resId' => [self::$id * 1000]
];
$fullRequest = \httpRequestCustom::addContentInBody($body, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$this->assertSame(400, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(_DOCUMENT_NOT_FOUND, $responseBody['errors']);
$GLOBALS['login'] = 'ddur';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$body = [
'status' => 'EVIS',
'resId' => [self::$id]
];
$fullRequest = \httpRequestCustom::addContentInBody($body, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$this->assertSame(403, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Document out of perimeter', $responseBody['errors']);
$GLOBALS['login'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
public function testUpdateExternalInfos()
{
$resController = new \Resource\controllers\ResController();
// UPDATE STATUS
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
[
'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 = [
[
'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: invalid res_id', $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 STATUS
$aArgs = [
'externalInfos' => [
[
'res_id' => self::$id,
'external_id' => "BB981212IIYZ",
'external_link' => "https://publik.nancy.fr/res/BB981212BB65"
]
],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('Bad Request : status is empty', $responseBody->errors);
//MISSING EXTERNAL INFOS
'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 : externalInfos is empty', $responseBody->errors);
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'select' => 'sve_start_date',
'clause' => '1=1',
'withFile' => true,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertNotNull($arr_res[0]->fileBase64Content);
$this->assertIsInt($arr_res[0]->res_id);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertSame(null, $arr_res[0]->fileBase64Content);
$this->assertIsInt($arr_res[0]->res_id);
$aArgs = [
'select' => '',
'clause' => '1=1',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request: select is not valid', $responseBody['errors']);
$aArgs = [
'select' => 'res_id',
'clause' => '',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request: clause is not valid', $responseBody['errors']);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => 'wrong format',
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request: withFile parameter is not a boolean', $responseBody['errors']);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => false,
'orderBy' => 'wrong format',
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request: orderBy parameter not valid', $responseBody['errors']);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 'wrong format'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame('Bad Request: limit parameter not valid', $responseBody['errors']);
$aArgs = [
'select' => 'res_id',
'clause' => 'dundermifflin_clients.branch',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(_INVALID_REQUEST, $responseBody['errors']);
}
public function testGetProcessingData()
{
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);