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

FEAT #13676 TIME 2:45 unit tests

parent d0f482f6
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@
<file>test/unitTests/app/configuration/ConfigurationControllerTest.php</file>
<file>test/unitTests/app/tag/TagControllerTest.php</file>
<file>test/unitTests/app/resource/UserFollowedResourceControllerTest.php</file>
<file>test/unitTests/app/search/SearchControllerTest.php</file>
<!-- The last one should be history -->
<file>test/unitTests/app/history/HistoryControllerTest.php</file>
</testsuite>
......
......@@ -18,7 +18,7 @@ class NoteControllerTest extends TestCase
public function testCreate()
{
//get last notes
// GET LAST MAIL
$getResId = DatabaseModel::select([
'select' => ['res_id'],
'table' => ['res_letterbox'],
......@@ -126,6 +126,10 @@ class NoteControllerTest extends TestCase
public function testGetById()
{
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$noteController = new \Note\controllers\NoteController();
// READ
......@@ -148,16 +152,24 @@ class NoteControllerTest extends TestCase
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Note out of perimeter', $responseBody->errors);
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testGetByResId()
{
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$noteController = new \Note\controllers\NoteController();
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $noteController->getByResId($request, new \Slim\Http\Response(), ['resId' => self::$resId]);
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $noteController->getByResId($request, new \Slim\Http\Response(), ['resId' => self::$resId]);
$this->assertSame(200, $response->getStatusCode());
......@@ -177,6 +189,71 @@ class NoteControllerTest extends TestCase
$this->assertIsString($value->lastname);
$this->assertNotEmpty($value->lastname);
}
// ERROR
$response = $noteController->getByResId($request, new \Slim\Http\Response(), ['resId' => 1234859]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Document out of perimeter', $responseBody->errors);
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testGetTemplates()
{
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$noteController = new \Note\controllers\NoteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
"resId" => self::$resId
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $noteController->getTemplates($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody->templates);
foreach ($responseBody->templates as $value) {
$this->assertNotEmpty($value->template_label);
$this->assertNotEmpty($value->template_content);
}
// GET
$response = $noteController->getTemplates($request, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody->templates);
foreach ($responseBody->templates as $value) {
$this->assertNotEmpty($value->template_label);
$this->assertNotEmpty($value->template_content);
}
// ERROR
$aArgs = [
"resId" => 19287
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $noteController->getTemplates($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Document out of perimeter', $responseBody->errors);
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testDelete()
......@@ -191,8 +268,8 @@ class NoteControllerTest extends TestCase
$this->assertSame(204, $response->getStatusCode());
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $noteController->getById($request, new \Slim\Http\Response(), ['id' => self::$noteId]);
$this->assertSame(403, $response->getStatusCode());
......
......@@ -378,7 +378,8 @@ class ResControllerTest extends TestCase
'subject' => $key .' Breaking News : 12345 Superman is alive - PHP unit',
'typist' => 19,
'priority' => $value[1],
'diffusionList' => [['id' => 19, 'type' => 'user', 'mode' => 'dest']]
'diffusionList' => [['id' => 19, 'type' => 'user', 'mode' => 'dest']],
'senders' => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
......
<?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 SearchControllerTest extends TestCase
{
private static $id = null;
public function testGet()
{
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$searchController = new \Search\controllers\SearchController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'resourceField' => 'Breaking News',
'contactField' => '',
'limit' => 2,
'offset' => 1,
'order' => 'desc',
'orderBy' => 'creationDate'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $searchController->get($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(3, $responseBody->count);
$this->assertIsArray($responseBody->resources);
$this->assertNotEmpty($responseBody->resources);
$this->assertSame(2, count($responseBody->resources));
foreach ($responseBody->resources as $resource) {
$this->assertIsInt($resource->resId);
$this->assertSame('incoming', $resource->category);
$this->assertEmpty($resource->chrono);
$this->assertEmpty($resource->barcode);
$this->assertNotEmpty($resource->subject);
$this->assertNotEmpty($resource->filename);
$this->assertNotEmpty($resource->creationDate);
$this->assertNotEmpty($resource->priority);
$this->assertNotEmpty($resource->status);
$this->assertNotEmpty($resource->destUser);
$this->assertNotEmpty($resource->priorityColor);
$this->assertNotEmpty($resource->statusLabel);
$this->assertNotEmpty($resource->statusImage);
$this->assertNotEmpty($resource->typeLabel);
$this->assertNotEmpty($resource->destUserLabel);
$this->assertIsBool($resource->hasDocument);
$this->assertSame(true, $resource->hasDocument);
$this->assertIsInt($resource->type);
$this->assertIsArray($resource->senders);
$this->assertIsArray($resource->recipients);
$this->assertIsInt($resource->attachments);
}
$this->assertIsArray($responseBody->allResources);
$this->assertNotEmpty($responseBody->allResources);
$this->assertSame(3, count($responseBody->allResources));
foreach ($responseBody->allResources as $resource) {
$this->assertIsInt($resource);
}
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
// GET WITH SUPERADMIN
$response = $searchController->get($request, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsInt($responseBody->count);
$this->assertIsArray($responseBody->resources);
$this->assertNotEmpty($responseBody->resources);
foreach ($responseBody->resources as $resource) {
$this->assertIsInt($resource->resId);
$this->assertNotEmpty($resource->category);
$this->assertNotEmpty($resource->subject);
$this->assertNotEmpty($resource->creationDate);
$this->assertNotEmpty($resource->status);
$this->assertNotEmpty($resource->typeLabel);
$this->assertIsBool($resource->hasDocument);
$this->assertIsInt($resource->type);
$this->assertIsArray($resource->senders);
$this->assertIsArray($resource->recipients);
$this->assertIsInt($resource->attachments);
}
$this->assertIsArray($responseBody->allResources);
$this->assertNotEmpty($responseBody->allResources);
foreach ($responseBody->allResources as $resource) {
$this->assertIsInt($resource);
}
// GET WITH CONTACT
$aArgs = [
'resourceField' => 'Breaking News',
'contactField' => 'maarch'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $searchController->get($fullRequest, new \Slim\Http\Response());
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsInt($responseBody->count);
$this->assertIsArray($responseBody->resources);
$this->assertNotEmpty($responseBody->resources);
foreach ($responseBody->resources as $resource) {
$this->assertIsInt($resource->resId);
$this->assertNotEmpty($resource->category);
$this->assertNotEmpty($resource->subject);
$this->assertNotEmpty($resource->creationDate);
$this->assertNotEmpty($resource->status);
$this->assertNotEmpty($resource->typeLabel);
$this->assertIsBool($resource->hasDocument);
$this->assertIsInt($resource->type);
$this->assertIsArray($resource->senders);
$this->assertNotEmpty($resource->senders);
$this->assertIsArray($resource->recipients);
$this->assertIsInt($resource->attachments);
}
$this->assertIsArray($responseBody->allResources);
$this->assertNotEmpty($responseBody->allResources);
foreach ($responseBody->allResources as $resource) {
$this->assertIsInt($resource);
}
}
}
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