Verified Commit 7263fbe1 authored by Damien's avatar Damien

FEAT #12765 TIME 0:45 Unit tests

parent cbdde595
......@@ -31,6 +31,7 @@
<file>test/unitTests/app/resource/ResourceListControllerTest.php</file>
<file>test/unitTests/app/resource/ExportControllerTest.php</file>
<file>test/unitTests/app/resource/LinkControllerTest.php</file>
<file>test/unitTests/app/resource/ListInstanceControllerTest.php</file>
<file>test/unitTests/app/resource/SummarySheetControllerTest.php</file>
<file>test/unitTests/app/status/StatusControllerTest.php</file>
<file>test/unitTests/app/shipping/ShippingControllerTest.php</file>
......
......@@ -921,7 +921,12 @@ class PreProcessActionController
$isSignatory = ListInstanceModel::get(['select' => ['signatory', 'requested_signature'], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$resId, 'VISA_CIRCUIT'], 'orderBy' => ['listinstance_id'], 'limit' => 1]);
if (empty($isSignatory[0])) {
$resourcesInformations['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
$hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'VISA_CIRCUIT']]);
if (!empty($hasCircuit)) {
$resourcesInformations['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit'];
} else {
$resourcesInformations['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
}
} elseif ($isSignatory[0]['requested_signature'] && !$isSignatory[0]['signatory']) {
$resourcesInformations['warning'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'userHasntSigned'];
} else {
......
......@@ -34,7 +34,6 @@ class SearchController
{
$queryParams = $request->getQueryParams();
$entities = UserModel::getEntitiesByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$entities = array_column($entities, 'id');
$entities = empty($entities) ? [0] : $entities;
......
<?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.
*
*/
use PHPUnit\Framework\TestCase;
class ListInstanceControllerTest extends TestCase
{
private static $resourceId = null;
public function testUpdateCircuits()
{
$GLOBALS['userId'] = 'cchaplin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$resController = new \Resource\controllers\ResController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'modelId' => 1,
'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' => 'Du matin au soir, ils disent du mal de la vie, et ils ne peuvent se résoudre à la quitter !',
'typist' => 19,
'priority' => 'poiuytre1357nbvc'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody(), true);
self::$resourceId = $responseBody['resId'];
$this->assertInternalType('int', self::$resourceId);
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$listInstanceController = new \Entity\controllers\ListInstanceController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'resources' => [
[
'resId' => self::$resourceId,
'listInstances' => [
["item_id" => 19, "requested_signature" => false],
["item_id" => 18, "requested_signature" => true]
]
],
],
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $listInstanceController->updateCircuits($fullRequest, new \Slim\Http\Response(), ['type' => 'visaCircuit']);
$this->assertSame(204, $response->getStatusCode());
}
public function testGetVisaCircuitByResId()
{
$listInstanceController = new \Entity\controllers\ListInstanceController();
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $listInstanceController->getVisaCircuitByResId($request, new \Slim\Http\Response(), ['resId' => self::$resourceId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody(), true);
$this->assertSame(19, $responseBody[0]['item_id']);
$this->assertSame('user', $responseBody[0]['item_type']);
$this->assertSame(false, $responseBody[0]['requested_signature']);
$this->assertNotEmpty($responseBody[0]['labelToDisplay']);
$this->assertSame(18, $responseBody[1]['item_id']);
$this->assertSame('user', $responseBody[1]['item_type']);
$this->assertSame(true, $responseBody[1]['requested_signature']);
$this->assertNotEmpty($responseBody[1]['labelToDisplay']);
\SrcCore\models\DatabaseModel::delete([
'table' => 'res_letterbox',
'where' => ['res_id = ?'],
'data' => [self::$resourceId]
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'listinstance',
'where' => ['res_id = ?'],
'data' => [self::$resourceId]
]);
}
}
......@@ -45,11 +45,13 @@ class LinkControllerTest extends TestCase
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
self::$firstResourceId = $responseBody->resId;
$this->assertInternalType('int', self::$firstResourceId);
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
self::$secondResourceId = $responseBody->resId;
$this->assertInternalType('int', self::$secondResourceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment