diff --git a/phpunit.xml b/phpunit.xml index 6a5511deba114d9334412e1ea243509ed90f7435..946f1a378dffa8d92b345138fb2aa2fb1a8c8786 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true" bootstrap="test/unitTests/define.php"> <testsuites> - <testsuite name="Maarch Test Suite"> + <testsuite name="Maarch Parapheur Test Suite"> <!-- <file>test/unitTests/core/AuthenticationControllerTest.php</file> --> <file>test/unitTests/core/PasswordControllerTest.php</file> <file>test/unitTests/app/user/UserControllerTest.php</file> + <file>test/unitTests/app/configuration/ConfigurationControllerTest.php</file> <file>test/unitTests/app/document/DocumentControllerTest.php</file> <file>test/unitTests/app/group/GroupControllerTest.php</file> </testsuite> diff --git a/src/app/configuration/controllers/ConfigurationController.php b/src/app/configuration/controllers/ConfigurationController.php index 68d362320634b629c0b1b245ef16c9c00feb8475..f6d23bff3d6c3cd3d1c8f0f9ec921aa07f468a69 100755 --- a/src/app/configuration/controllers/ConfigurationController.php +++ b/src/app/configuration/controllers/ConfigurationController.php @@ -173,17 +173,6 @@ class ConfigurationController $body['value']['password'] = null; } - if ($body['value']['auth'] && empty($body['value']['password'])) { - $configuration['value'] = json_decode($configuration['value'], true); - if (!empty($configuration['value']['password'])) { - $body['value']['password'] = $configuration['value']['password']; - } - } elseif ($body['value']['auth'] && !empty($body['value']['password'])) { - $body['value']['password'] = AuthenticationModel::encrypt(['password' => $body['value']['password']]); - } elseif (!$body['value']['auth']) { - $body['value']['user'] = null; - $body['value']['password'] = null; - } $data = json_encode([ 'type' => $body['value']['type'], 'host' => $body['value']['host'], @@ -288,6 +277,8 @@ class ConfigurationController return $response->withStatus(400)->withJson(['errors' => 'QueryParams login is empty or not a string']); } elseif (!Validator::stringType()->notEmpty()->validate($queryParams['password'])) { return $response->withStatus(400)->withJson(['errors' => 'QueryParams password is empty or not a string']); + } elseif (!Validator::intVal()->notEmpty()->validate($args['id'])) { + return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); } $configuration = ConfigurationModel::getById(['id' => $args['id']]); @@ -304,7 +295,7 @@ class ConfigurationController $ldap = @ldap_connect($uri); if ($ldap === false) { $error = 'Ldap connect failed : uri is maybe wrong'; - return $response->withJson(['errors' => $error, 'connection' => false]); + return $response->withJson(['connection' => false, 'informations' => $error]); } ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); @@ -315,7 +306,7 @@ class ConfigurationController $search = @ldap_search($ldap, $ldapConfiguration['baseDN'], "(uid={$login})", ['dn']); if ($search === false) { $error = 'Ldap search failed : baseDN is maybe wrong => ' . ldap_error($ldap); - return $response->withJson(['errors' => $error, 'connection' => false]); + return $response->withJson(['connection' => false, 'informations' => $error]); } $entries = ldap_get_entries($ldap, $search); $login = $entries[0]['dn']; @@ -323,10 +314,10 @@ class ConfigurationController $authenticated = @ldap_bind($ldap, $login, $queryParams['password']); if (!$authenticated) { $error = ldap_error($ldap); - return $response->withJson(['errors' => $error, 'connection' => false]); + return $response->withJson(['connection' => false, 'informations' => $error]); } - return $response->withJson(['connection' => true]); + return $response->withJson(['connection' => true, 'informations' => 'success']); } private static function checkMailer(array $args) diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index 400de979e70426aa14ac3a34775285e1aa8eb380..e007d84104b5d4fdc26b54b6f58abcdc824319f3 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -55,6 +55,13 @@ class DocumentController $workflowSelect = "SELECT id FROM workflows ws WHERE workflows.main_document_id = main_document_id AND process_date IS NULL AND status IS NULL ORDER BY \"order\" LIMIT 1"; $where = ['user_id in (?)', "(id) in ({$workflowSelect})"]; $data = [$users]; + $countWorkflows = WorkflowModel::get([ + 'select' => ['count(mode)', 'mode'], + 'where' => $where, + 'data' => $data, + 'groupBy' => ['mode'] + ]); + if (!empty($queryParams['mode']) && in_array($queryParams['mode'], DocumentController::MODES)) { $where[] = 'mode = ?'; $data[] = $queryParams['mode']; @@ -92,12 +99,16 @@ class DocumentController ]); } - $count = empty($documents[0]['count']) ? 0 : $documents[0]['count']; + $count = ['visa' => 0, 'sign' => 0, 'note' => 0, 'current' => empty($documents[0]['count']) ? 0 : $documents[0]['count']]; foreach ($documents as $key => $document) { unset($documents[$key]['count']); $documents[$key]['mode'] = $workflowsShortcut[$document['id']]['mode']; $documents[$key]['owner'] = $workflowsShortcut[$document['id']]['user_id'] == $GLOBALS['id']; } + + foreach ($countWorkflows as $mode) { + $count[$mode['mode']] = $mode['count']; + } return $response->withJson(['documents' => $documents, 'count' => $count]); } diff --git a/src/app/workflow/models/WorkflowModel.php b/src/app/workflow/models/WorkflowModel.php index e5d00c6bf5d57f4cfd85dc2e64544913808a9f40..62e00f485b23d0376e049445384873a73f33278c 100755 --- a/src/app/workflow/models/WorkflowModel.php +++ b/src/app/workflow/models/WorkflowModel.php @@ -22,7 +22,7 @@ class WorkflowModel public static function get(array $args) { ValidatorModel::notEmpty($args, ['select']); - ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy']); + ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy', 'groupBy']); ValidatorModel::intType($args, ['limit', 'offset']); $workflows = DatabaseModel::select([ @@ -31,6 +31,7 @@ class WorkflowModel 'where' => empty($args['where']) ? [] : $args['where'], 'data' => empty($args['data']) ? [] : $args['data'], 'orderBy' => empty($args['orderBy']) ? [] : $args['orderBy'], + 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'], 'offset' => empty($args['offset']) ? 0 : $args['offset'], 'limit' => empty($args['limit']) ? 0 : $args['limit'], ]); diff --git a/src/frontend/app/modal/confirm-modal.component.ts b/src/frontend/app/modal/confirm-modal.component.ts index 5fcb06e7567cfe4b77f0e84dd8a8052354cdfaff..d999e84e755cee70a10f083c95d3f2121fcb95e4 100644 --- a/src/frontend/app/modal/confirm-modal.component.ts +++ b/src/frontend/app/modal/confirm-modal.component.ts @@ -61,8 +61,8 @@ export class ConfirmModalComponent { .subscribe(() => { if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList] !== undefined) { this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1); - if (this.signaturesService.documentsListCount > 0) { - this.signaturesService.documentsListCount--; + if (this.signaturesService.documentsListCount.current > 0) { + this.signaturesService.documentsListCount.current--; } } this.dialogRef.close('sucess'); diff --git a/src/frontend/app/modal/warn-modal.component.ts b/src/frontend/app/modal/warn-modal.component.ts index dba35b88882f88d728826adbedca79ae407c3f90..3863e7fd936af1adc8075edc1944ac5e6806062e 100644 --- a/src/frontend/app/modal/warn-modal.component.ts +++ b/src/frontend/app/modal/warn-modal.component.ts @@ -64,8 +64,8 @@ export class WarnModalComponent { if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList] !== undefined) { this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1); - if (this.signaturesService.documentsListCount > 0) { - this.signaturesService.documentsListCount--; + if (this.signaturesService.documentsListCount.current > 0) { + this.signaturesService.documentsListCount.current--; } } this.dialogRef.close('sucess'); diff --git a/src/frontend/app/sidebar/sidebar.component.html b/src/frontend/app/sidebar/sidebar.component.html index 05d35bcb1e196ffc20593202972c65325f7527d4..a2ff46ddf149736fd6012ff8e643db7c73e600b9 100755 --- a/src/frontend/app/sidebar/sidebar.component.html +++ b/src/frontend/app/sidebar/sidebar.component.html @@ -22,7 +22,7 @@ <header class="sidebar-header"> <div *ngIf="!searchMode" (click)="search();" style="cursor: pointer;"> <span - [class.primary]="signaturesService.mode != ''">{{signaturesService.documentsListCount}}</span> {{'lang.documents' | translate}} <span + [class.primary]="signaturesService.mode != ''">{{signaturesService.documentsListCount.current}}</span> {{'lang.documents' | translate}} <span class="primary" *ngIf="signaturesService.mode != ''">{{'lang.'+signaturesService.mode+'Label' | translate}}</span> </div> diff --git a/src/frontend/app/sidebar/sidebar.component.ts b/src/frontend/app/sidebar/sidebar.component.ts index 42d56fd225e2699f39af8afa46f16f556b5a0071..32d9b01cacbd76ac562b602a67d3392eda8f0012 100755 --- a/src/frontend/app/sidebar/sidebar.component.ts +++ b/src/frontend/app/sidebar/sidebar.component.ts @@ -54,7 +54,7 @@ export class SidebarComponent implements OnInit { } handleScroll(event: ScrollEvent) { - if (event.isReachingBottom && !this.loadingList && this.signaturesService.documentsList.length < this.signaturesService.documentsListCount) { + if (event.isReachingBottom && !this.loadingList && this.signaturesService.documentsList.length < this.signaturesService.documentsListCount.current) { this.loadingList = true; this.listContent.nativeElement.style.overflowY = 'hidden'; diff --git a/test/unitTests/app/configuration/ConfigurationControllerTest.php b/test/unitTests/app/configuration/ConfigurationControllerTest.php new file mode 100755 index 0000000000000000000000000000000000000000..d047dde1346ef039ca8eeac1f88688baf5e8e80d --- /dev/null +++ b/test/unitTests/app/configuration/ConfigurationControllerTest.php @@ -0,0 +1,369 @@ +<?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 ConfigurationControllerTest extends TestCase +{ + private static $ldapId = null; + private static $emailId = null; + private static $ldapLabel = null; + private static $emailLabel = null; + + public function testCreate() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + //EMAIL + self::$emailLabel = 'Mon serveur email de secours ' . rand(); + $args = [ + 'identifier' => 'emailServer', + 'label' => self::$emailLabel, + 'value' => [ + 'type' => 'smtp', + 'host' => '1.2.3.4', + 'port' => 22, + 'user' => 'mor', + 'password' => 'pheus', + 'auth' => true, + 'secure' => 'tls', + 'from' => 'test@test.com' + ] + ]; + + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(204, $response->getStatusCode()); + + //LDAP + self::$ldapLabel = 'Mon serveur ldap de secours ' . rand(); + $args = [ + 'identifier' => 'ldapServer', + 'label' => self::$ldapLabel, + 'value' => [ + 'uri' => '1.2.3.4', + 'ssl' => false, + 'prefix' => 'one', + 'suffix' => 'sion', + 'baseDN' => null + ] + ]; + + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(204, $response->getStatusCode()); + + + //Errors + unset($args['value']['uri']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame("Body['value'] uri is empty or not a string", $responseBody->errors); + + unset($args['value']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame("Body value is empty or not an array", $responseBody->errors); + + unset($args['label']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame("Body label is empty or not a string", $responseBody->errors); + + unset($args['identifier']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->create($fullRequest, new \Slim\Http\Response()); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame("Body is not set or empty", $responseBody->errors); + } + + public function testGet() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + //LDAP + $fullRequest = $request->withQueryParams(['identifier' => 'ldapServer']); + $response = $configurationController->get($fullRequest, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertInternalType('array', $responseBody->configurations); + $this->assertNotEmpty($responseBody->configurations); + foreach ($responseBody->configurations as $configuration) { + if ($configuration->label == self::$ldapLabel) { + self::$ldapId = $configuration->id; + } + } + $this->assertNotEmpty(self::$ldapId); + + //EMAIL + $fullRequest = $request->withQueryParams(['identifier' => 'emailServer']); + $response = $configurationController->get($fullRequest, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertInternalType('array', $responseBody->configurations); + $this->assertNotEmpty($responseBody->configurations); + foreach ($responseBody->configurations as $configuration) { + if ($configuration->label == self::$emailLabel) { + self::$emailId = $configuration->id; + } + } + $this->assertNotEmpty(self::$emailId); + + //CONNECTION + $fullRequest = $request->withQueryParams(['identifier' => 'connection']); + $response = $configurationController->get($fullRequest, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertNotEmpty($responseBody->configurations); + $this->assertInternalType('string', $responseBody->configurations->value); + $this->assertInternalType('array', $responseBody->configurations->availableConnections); + + + //Errors + $response = $configurationController->get($request, new \Slim\Http\Response()); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('QueryParams identifier is empty or not a string', $responseBody->errors); + } + + public function testGetById() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + //LDAP + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(200, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$ldapId, $responseBody->configuration->id); + $this->assertSame('ldapServer', $responseBody->configuration->identifier); + $this->assertSame(self::$ldapLabel, $responseBody->configuration->label); + $this->assertSame('1.2.3.4', $responseBody->configuration->value->uri); + $this->assertSame(false, $responseBody->configuration->value->ssl); + $this->assertSame('one', $responseBody->configuration->value->prefix); + $this->assertSame('sion', $responseBody->configuration->value->suffix); + $this->assertSame(null, $responseBody->configuration->value->baseDN); + + //EMAIL + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$emailId]); + $this->assertSame(200, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$emailId, $responseBody->configuration->id); + $this->assertSame('emailServer', $responseBody->configuration->identifier); + $this->assertSame(self::$emailLabel, $responseBody->configuration->label); + $this->assertSame('smtp', $responseBody->configuration->value->type); + $this->assertSame('1.2.3.4', $responseBody->configuration->value->host); + $this->assertSame(22, $responseBody->configuration->value->port); + $this->assertSame('mor', $responseBody->configuration->value->user); + $this->assertSame(true, $responseBody->configuration->value->auth); + $this->assertSame('tls', $responseBody->configuration->value->secure); + $this->assertSame('test@test.com', $responseBody->configuration->value->from); + } + + public function testTestConnection() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $fullRequest = $request->withQueryParams(['login' => 'smith', 'password' => 'agent']); + $response = $configurationController->testConnection($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(200, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(false, $responseBody->connection); + $this->assertSame('Can\'t contact LDAP server', $responseBody->informations); + + + //Errors + $fullRequest = $request->withQueryParams(['login' => 'smith']); + $response = $configurationController->testConnection($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('QueryParams password is empty or not a string', $responseBody->errors); + + $response = $configurationController->testConnection($request, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('QueryParams login is empty or not a string', $responseBody->errors); + } + + public function testUpdate() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + //EMAIL + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $args = [ + 'label' => 'new label', + 'value' => [ + 'type' => 'mail', + 'host' => '5.6.7.8', + 'port' => 24, + 'user' => 'tri', + 'auth' => true, + 'secure' => 'ssl', + 'from' => 'test2@test.com' + ] + ]; + + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$emailId]); + $this->assertSame(204, $response->getStatusCode()); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$emailId]); + $this->assertSame(200, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$emailId, $responseBody->configuration->id); + $this->assertSame('emailServer', $responseBody->configuration->identifier); + $this->assertSame('new label', $responseBody->configuration->label); + $this->assertSame('mail', $responseBody->configuration->value->type); + $this->assertSame('5.6.7.8', $responseBody->configuration->value->host); + $this->assertSame(24, $responseBody->configuration->value->port); + $this->assertSame('tri', $responseBody->configuration->value->user); + $this->assertSame(true, $responseBody->configuration->value->auth); + $this->assertSame('ssl', $responseBody->configuration->value->secure); + $this->assertSame('test2@test.com', $responseBody->configuration->value->from); + + //LDAP + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $args = [ + 'label' => 'new label', + 'value' => [ + 'uri' => '5.6.7.8', + 'ssl' => true, + 'prefix' => 'neo', + 'suffix' => 'smith', + 'baseDN' => 'DC=maarch,DC=com' + ] + ]; + + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(204, $response->getStatusCode()); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(200, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(self::$ldapId, $responseBody->configuration->id); + $this->assertSame('ldapServer', $responseBody->configuration->identifier); + $this->assertSame('new label', $responseBody->configuration->label); + $this->assertSame('5.6.7.8', $responseBody->configuration->value->uri); + $this->assertSame(true, $responseBody->configuration->value->ssl); + $this->assertSame('neo', $responseBody->configuration->value->prefix); + $this->assertSame('smith', $responseBody->configuration->value->suffix); + $this->assertSame('DC=maarch,DC=com', $responseBody->configuration->value->baseDN); + + + //Errors + unset($args['value']['uri']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(400, $response->getStatusCode()); + $this->assertSame("Body['value'] uri is empty or not a string", $responseBody->errors); + + unset($args['value']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(400, $response->getStatusCode()); + $this->assertSame("Body value is empty or not an array", $responseBody->errors); + + unset($args['label']); + $fullRequest = \httpRequestCustom::addContentInBody($args, $request); + $response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(400, $response->getStatusCode()); + $this->assertSame("Body is not set or empty", $responseBody->errors); + } + + public function testDelete() + { + $configurationController = new \Configuration\controllers\ConfigurationController(); + + //LDAP + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->delete($request, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(204, $response->getStatusCode()); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$ldapId]); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('Configuration does not exist', $responseBody->errors); + + //EMAIL + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->delete($request, new \Slim\Http\Response(), ['id' => self::$emailId]); + $this->assertSame(204, $response->getStatusCode()); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $configurationController->getById($request, new \Slim\Http\Response(), ['id' => self::$emailId]); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('Configuration does not exist', $responseBody->errors); + + + //Errors + $response = $configurationController->update($request, new \Slim\Http\Response(), ['id' => 'test']); + $this->assertSame(400, $response->getStatusCode()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('Route id is not an integer', $responseBody->errors); + } +} diff --git a/test/unitTests/define.php b/test/unitTests/define.php index bf6fdae3e86fbb7348cf7cd4bb502dc24e5fd526..ef5d7187740ddd8d11ec0636e0f54b66c5f810e7 100755 --- a/test/unitTests/define.php +++ b/test/unitTests/define.php @@ -9,7 +9,7 @@ require_once 'vendor/autoload.php'; -$id = 2; +$id = 1; $_SERVER['CONFIG_DIR'] = "/var/www/html/MaarchParapheur/config/"; class httpRequestCustom