Skip to content
Snippets Groups Projects
Verified Commit 050387f5 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #10387 TIME 2 improve unit test

parent b56e5f53
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
......@@ -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']);
}
......
......@@ -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);
}
}
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment