diff --git a/phpunit.xml b/phpunit.xml index 79edad44b80f0882fa2330b9ff4aad40b02a8c8c..cb6eb99a317cb840c09c1bc33e78b506513c380e 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,6 +19,7 @@ <file>test/unitTests/app/group/GroupControllerTest.php</file> <file>test/unitTests/app/entity/ListTemplateControllerTest.php</file> <file>test/unitTests/app/indexingModel/IndexingModelControllerTest.php</file> + <file>test/unitTests/app/indexing/IndexingControllerTest.php</file> <file>test/unitTests/app/notification/NotificationControllerTest.php</file> <file>test/unitTests/app/notification/NotificationScheduleControllerTest.php</file> <file>test/unitTests/app/parameter/ParameterControllerTest.php</file> diff --git a/src/app/group/models/GroupModelAbstract.php b/src/app/group/models/GroupModelAbstract.php index baa7d04b69a3423ff1ff296b3e55861149d5d687..378d8f19a7e1ea98c2f130f4bc72558e582ebe38 100755 --- a/src/app/group/models/GroupModelAbstract.php +++ b/src/app/group/models/GroupModelAbstract.php @@ -219,7 +219,8 @@ abstract class GroupModelAbstract public static function getGroupByLogin(array $aArgs = []) { ValidatorModel::notEmpty($aArgs, ['login', 'groupId']); - ValidatorModel::stringType($aArgs, ['login', 'groupId']); + ValidatorModel::stringType($aArgs, ['login']); + ValidatorModel::intVal($aArgs, ['groupId']); $aGroups = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], diff --git a/test/unitTests/app/indexing/IndexingControllerTest.php b/test/unitTests/app/indexing/IndexingControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c436d4169f93d12c6df6a566b201a9a2dc26cc01 --- /dev/null +++ b/test/unitTests/app/indexing/IndexingControllerTest.php @@ -0,0 +1,75 @@ +<?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 IndexingControllerTest extends TestCase +{ + public function testGetIndexingActions() + { + $GLOBALS['userId'] = 'bbain'; + + $indexingController = new \Resource\controllers\IndexingController(); + + // GET + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $indexingController->getIndexingActions($request, new \Slim\Http\Response(), ['groupId' => 2]); + $this->assertSame(200, $response->getStatusCode()); + + $responseBody = json_decode((string)$response->getBody()); + + $this->assertNotEmpty($responseBody->actions); + foreach ($responseBody->actions as $action) { + $this->assertNotEmpty($action->id); + $this->assertInternalType('int', $action->id); + $this->assertNotEmpty($action->label_action); + $this->assertNotEmpty($action->component); + } + + //ERROR + $response = $indexingController->getIndexingActions($request, new \Slim\Http\Response(), ['groupId' => 99999]); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('This user is not in this group', $responseBody->errors); + + $GLOBALS['userId'] = 'superadmin'; + } + + public function testGetIndexingEntities() + { + $GLOBALS['userId'] = 'bbain'; + + $indexingController = new \Resource\controllers\IndexingController(); + + // GET + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $indexingController->getIndexingEntities($request, new \Slim\Http\Response(), ['groupId' => 2]); + $this->assertSame(200, $response->getStatusCode()); + + $responseBody = json_decode((string)$response->getBody()); + + $this->assertNotEmpty($responseBody->entities); + foreach ($responseBody->entities as $entity) { + $this->assertNotEmpty($entity->id); + $this->assertInternalType('int', $entity->id); + $this->assertNotEmpty($entity->entity_label); + $this->assertNotEmpty($entity->entity_id); + } + + //ERROR + $response = $indexingController->getIndexingActions($request, new \Slim\Http\Response(), ['groupId' => 99999]); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('This user is not in this group', $responseBody->errors); + + $GLOBALS['userId'] = 'superadmin'; + } +}