diff --git a/phpunit.xml b/phpunit.xml index ee363fbb3eb2f71365d33621540f02458573fb01..9aaca30ba5e20d66a9709402cd42216caf266bce 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -28,6 +28,7 @@ <file>test/unitTests/app/resource/ExportControllerTest.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> <file>test/unitTests/app/user/UserControllerTest.php</file> <file>test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php</file> <file>test/unitTests/app/template/TemplateControllerTest.php</file> diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index a464cc05cd4583ac906bba61be95f7c48720c26e..5ba5b9291e90a60a4ec8eb58189292aacb93b9ef 100755 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -14,7 +14,6 @@ namespace Entity\controllers; -use Basket\models\BasketModel; use Basket\models\GroupBasketRedirectModel; use Entity\models\EntityModel; use Entity\models\ListInstanceModel; @@ -39,7 +38,7 @@ class EntityController public function getById(Request $request, Response $response, array $aArgs) { - $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id']]); + $entity = EntityModel::getByEntityId(['entityId' => $aArgs['id']]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -53,7 +52,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id']]); + $entity = EntityModel::getByEntityId(['entityId' => $aArgs['id']]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -122,7 +121,7 @@ class EntityController 'sequence' => $listTemplate['sequence'], 'title' => $listTemplate['title'], 'description' => $listTemplate['description'], - 'labelToDisplay' => entitymodel::getByEntityId(['entityId' => $listTemplate['item_id'], 'select' => ['entity_label']])['entity_label'], + 'labelToDisplay' => EntityModel::getByEntityId(['entityId' => $listTemplate['item_id'], 'select' => ['entity_label']])['entity_label'], 'descriptionToDisplay' => '' ]; } @@ -181,7 +180,7 @@ class EntityController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - $existingEntity = entitymodel::getByEntityId(['entityId' => $data['entity_id'], 'select' => [1]]); + $existingEntity = EntityModel::getByEntityId(['entityId' => $data['entity_id'], 'select' => [1]]); if (!empty($existingEntity)) { return $response->withStatus(400)->withJson(['errors' => _ENTITY_ID_ALREADY_EXISTS]); } @@ -224,7 +223,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = EntityModel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -301,7 +300,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = EntityModel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -346,8 +345,8 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $dyingEntity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => ['parent_entity_id']]); - $successorEntity = entitymodel::getByEntityId(['entityId' => $aArgs['newEntityId'], 'select' => [1]]); + $dyingEntity = EntityModel::getByEntityId(['entityId' => $aArgs['id'], 'select' => ['parent_entity_id']]); + $successorEntity = EntityModel::getByEntityId(['entityId' => $aArgs['newEntityId'], 'select' => [1]]); if (empty($dyingEntity) || empty($successorEntity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity does not exist']); } @@ -421,7 +420,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = EntityModel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } diff --git a/test/unitTests/app/home/HomeControllerTest.php b/test/unitTests/app/home/HomeControllerTest.php index d4ee53e6d1886a0dba050a8bdfe4c0fdbfc14a60..a0019921eaeaca744a8ceb58d868e34a2caf5a1c 100755 --- a/test/unitTests/app/home/HomeControllerTest.php +++ b/test/unitTests/app/home/HomeControllerTest.php @@ -10,6 +10,7 @@ * @author dev <dev@maarch.org> * @ingroup core */ + use PHPUnit\Framework\TestCase; class HomeControllerTest extends TestCase @@ -30,4 +31,17 @@ class HomeControllerTest extends TestCase $this->assertNotNull($responseBody->assignedBaskets); $this->assertNotEmpty($responseBody->homeMessage); } + + public function testGetLastRessources() + { + $homeController = new \Home\controllers\HomeController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $homeController->getLastRessources($request, new \Slim\Http\Response()); + $responseBody = json_decode((string) $response->getBody()); + + $this->assertInternalType('array', $responseBody->lastResources); + } } diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php index a859d85a397402889d1ad23d541051a87a3cc760..179040edd86e469845c5015ab217852cd3804408 100755 --- a/test/unitTests/app/user/UserControllerTest.php +++ b/test/unitTests/app/user/UserControllerTest.php @@ -272,6 +272,81 @@ class UserControllerTest extends TestCase $this->assertSame('Y', $responseBody->entities[0]->primary_entity); } + public function testGetUsersById() + { + $entityController = new \Entity\controllers\EntityController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'DGS']); + $responseBody = json_decode((string)$response->getBody()); + $entitySerialId = $responseBody->entity->id; + + $response = $entityController->getUsersById($request, new \Slim\Http\Response(), ['id' => $entitySerialId]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertNotNull($responseBody->users); + + $found = false; + foreach ($responseBody->users as $value) { + $this->assertNotNull($value->id); + $this->assertInternalType('integer', $value->id); + $this->assertNotNull($value->user_id); + $this->assertNotNull($value->firstname); + $this->assertNotNull($value->lastname); + $this->assertNotNull($value->labelToDisplay); + $this->assertNotNull($value->descriptionToDisplay); + + if ($value->id == self::$id) { + $this->assertSame('test-ckent', $value->user_id); + $this->assertSame('TEST-CLARK2', $value->firstname); + $this->assertSame('TEST-KENT2', $value->lastname); + $this->assertSame($value->firstname . ' ' . $value->lastname, $value->labelToDisplay); + $found = true; + } + } + + $this->assertSame(true, $found); + + //ERROR + $response = $entityController->getUsersById($request, new \Slim\Http\Response(), ['id' => 99989]); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('Entity not found', $responseBody->errors); + } + + public function testIsDeletable() + { + $userController = new \User\controllers\UserController(); + + // GET + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $userController->isDeletable($request, new \Slim\Http\Response(), ['id' => self::$id]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(true, $responseBody->isDeletable); + $this->assertInternalType('array', $responseBody->listTemplates); + $this->assertEmpty($responseBody->listTemplates); + $this->assertInternalType('array', $responseBody->listInstances); + $this->assertEmpty($responseBody->listInstances); + } + + public function testIsEntityDeletable() + { + $userController = new \User\controllers\UserController(); + + // GET + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $userController->isEntityDeletable($request, new \Slim\Http\Response(), ['id' => self::$id, 'entityId' => 'DGS']); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame(false, $responseBody->hasConfidentialityInstances); + $this->assertSame(false, $responseBody->hasListTemplates); + } + public function testUpdatePrimaryEntity() { $userController = new \User\controllers\UserController();