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

FEAT #13676 TIME 2:30 unit test core

parent 910ba2f1
No related branches found
No related tags found
No related merge requests found
...@@ -2,20 +2,17 @@ ...@@ -2,20 +2,17 @@
<phpunit colors="true" bootstrap="test/unitTests/define.php"> <phpunit colors="true" bootstrap="test/unitTests/define.php">
<testsuites> <testsuites>
<testsuite name="Maarch Test Suite"> <testsuite name="Maarch Test Suite">
<!--directory>test</directory--> <directory>test/unitTests/core/</directory>
<file>test/unitTests/app/home/HomeControllerTest.php</file> <file>test/unitTests/app/home/HomeControllerTest.php</file>
<file>test/unitTests/app/action/ActionControllerTest.php</file> <file>test/unitTests/app/action/ActionControllerTest.php</file>
<file>test/unitTests/app/administration/AdministrationControllerTest.php</file> <file>test/unitTests/app/administration/AdministrationControllerTest.php</file>
<file>test/unitTests/app/attachment/AttachmentControllerTest.php</file> <file>test/unitTests/app/attachment/AttachmentControllerTest.php</file>
<file>test/unitTests/core/AutocompleteControllerTest.php</file>
<file>test/unitTests/core/AuthenticationControllerTest.php</file>
<file>test/unitTests/app/basket/BasketControllerTest.php</file> <file>test/unitTests/app/basket/BasketControllerTest.php</file>
<file>test/unitTests/app/contact/ContactControllerTest.php</file> <file>test/unitTests/app/contact/ContactControllerTest.php</file>
<file>test/unitTests/app/contact/ContactCustomFieldControllerTest.php</file> <file>test/unitTests/app/contact/ContactCustomFieldControllerTest.php</file>
<file>test/unitTests/app/contact/ContactGroupControllerTest.php</file> <file>test/unitTests/app/contact/ContactGroupControllerTest.php</file>
<file>test/unitTests/app/customField/CustomFieldControllerTest.php</file> <file>test/unitTests/app/customField/CustomFieldControllerTest.php</file>
<file>test/unitTests/app/contentManagement/ContentManagementControllerTest.php</file> <file>test/unitTests/app/contentManagement/ContentManagementControllerTest.php</file>
<file>test/unitTests/core/CoreControllerTest.php</file>
<file>test/unitTests/app/docserver/DocserverControllerTest.php</file> <file>test/unitTests/app/docserver/DocserverControllerTest.php</file>
<file>test/unitTests/app/doctype/DoctypeControllerTest.php</file> <file>test/unitTests/app/doctype/DoctypeControllerTest.php</file>
<file>test/unitTests/app/entity/EntityControllerTest.php</file> <file>test/unitTests/app/entity/EntityControllerTest.php</file>
...@@ -26,7 +23,6 @@ ...@@ -26,7 +23,6 @@
<file>test/unitTests/app/notification/NotificationControllerTest.php</file> <file>test/unitTests/app/notification/NotificationControllerTest.php</file>
<file>test/unitTests/app/notification/NotificationScheduleControllerTest.php</file> <file>test/unitTests/app/notification/NotificationScheduleControllerTest.php</file>
<file>test/unitTests/app/parameter/ParameterControllerTest.php</file> <file>test/unitTests/app/parameter/ParameterControllerTest.php</file>
<file>test/unitTests/core/PasswordControllerTest.php</file>
<file>test/unitTests/app/priority/PriorityControllerTest.php</file> <file>test/unitTests/app/priority/PriorityControllerTest.php</file>
<file>test/unitTests/app/resource/ResControllerTest.php</file> <file>test/unitTests/app/resource/ResControllerTest.php</file>
<file>test/unitTests/app/resource/ResourceListControllerTest.php</file> <file>test/unitTests/app/resource/ResourceListControllerTest.php</file>
......
...@@ -23,25 +23,6 @@ require_once 'apps/maarch_entreprise/tools/log4php/Logger.php'; //TODO composer ...@@ -23,25 +23,6 @@ require_once 'apps/maarch_entreprise/tools/log4php/Logger.php'; //TODO composer
class LogsController class LogsController
{ {
/*
timestart : timestamp Debut
timeend : timestamp Fin
level : level log4php
message : message dans les logs
*/
public function executionTimeLog($timestart, $timeend, $level, $message)
{
if (empty($timeend)) {
$timeend = microtime(true);
}
$time = $timeend - $timestart;
//TODO : USE NEW METHOD
// self::$level(
// ['message' => $message.'. Done in ' . number_format($time, 3) . ' secondes.']
// );
}
public static function buildLoggingMethod() public static function buildLoggingMethod()
{ {
$loggingMethods = []; $loggingMethods = [];
......
...@@ -237,6 +237,9 @@ class CoreConfigModel ...@@ -237,6 +237,9 @@ class CoreConfigModel
return $xmlfile; return $xmlfile;
} }
/**
* @codeCoverageIgnore
*/
public static function initAngularStructure() public static function initAngularStructure()
{ {
$lang = CoreConfigModel::getLanguage(); $lang = CoreConfigModel::getLanguage();
......
...@@ -316,17 +316,4 @@ class DatabaseModel ...@@ -316,17 +316,4 @@ class DatabaseModel
return $db->rollbackTransaction(); return $db->rollbackTransaction();
} }
/**
* Database Copy from Array
*
* @return bool
* @throws \Exception
*/
public static function pgsqlCopyFromArray(array $args)
{
$db = new DatabasePDO();
return $db->pgsqlCopyFromArray($args['table'], $args['rows'], $args['delimiter'], $args['nullAs'], $args['fields']);
}
} }
...@@ -217,9 +217,4 @@ class DatabasePDO ...@@ -217,9 +217,4 @@ class DatabasePDO
{ {
return self::$pdo->rollBack(); return self::$pdo->rollBack();
} }
public function pgsqlCopyFromArray(string $table_name, array $rows, string $delimiter = '\t', string $null_as = "\\\\N", string $fields)
{
return self::$pdo->pgsqlCopyFromArray($table_name, $rows, $delimiter, $null_as, $fields);
}
} }
...@@ -64,41 +64,23 @@ class TextFormatModel ...@@ -64,41 +64,23 @@ class TextFormatModel
return $string; return $string;
} }
public static function htmlWasher($html, $mode = 'unicode') public static function htmlWasher($html)
{ {
if ($mode == 'unicode') { $html = str_replace("<br/>", "\\n", $html);
$html = str_replace("<br/>", "\\n", $html); $html = str_replace("<br />", "\\n", $html);
$html = str_replace("<br />", "\\n", $html); $html = str_replace("<br/>", "\\n", $html);
$html = str_replace("<br/>", "\\n", $html); $html = str_replace("&nbsp;", " ", $html);
$html = str_replace("&nbsp;", " ", $html); $html = str_replace("&eacute;", "\u00e9", $html);
$html = str_replace("&eacute;", "\u00e9", $html); $html = str_replace("&egrave;", "\u00e8", $html);
$html = str_replace("&egrave;", "\u00e8", $html); $html = str_replace("&ecirc;", "\00ea", $html);
$html = str_replace("&ecirc;", "\00ea", $html); $html = str_replace("&agrave;", "\u00e0", $html);
$html = str_replace("&agrave;", "\u00e0", $html); $html = str_replace("&acirc;", "\u00e2", $html);
$html = str_replace("&acirc;", "\u00e2", $html); $html = str_replace("&icirc;", "\u00ee", $html);
$html = str_replace("&icirc;", "\u00ee", $html); $html = str_replace("&ocirc;", "\u00f4", $html);
$html = str_replace("&ocirc;", "\u00f4", $html); $html = str_replace("&ucirc;", "\u00fb", $html);
$html = str_replace("&ucirc;", "\u00fb", $html); $html = str_replace("&acute;", "\u0027", $html);
$html = str_replace("&acute;", "\u0027", $html); $html = str_replace("&deg;", "\u00b0", $html);
$html = str_replace("&deg;", "\u00b0", $html); $html = str_replace("&rsquo;", "\u2019", $html);
$html = str_replace("&rsquo;", "\u2019", $html);
} else {
$html = str_replace("<br/>", "\\n", $html);
$html = str_replace("<br />", "\\n", $html);
$html = str_replace("<br/>", "\\n", $html);
$html = str_replace("&nbsp;", " ", $html);
$html = str_replace("&eacute;", "é", $html);
$html = str_replace("&egrave;", "è", $html);
$html = str_replace("&ecirc;", "ê", $html);
$html = str_replace("&agrave;", "à", $html);
$html = str_replace("&acirc;", "â", $html);
$html = str_replace("&icirc;", "î", $html);
$html = str_replace("&ocirc;", "ô", $html);
$html = str_replace("&ucirc;", "û", $html);
$html = str_replace("&acute;", "", $html);
$html = str_replace("&deg;", "°", $html);
$html = str_replace("&rsquo;", "'", $html);
}
return $html; return $html;
} }
......
...@@ -130,20 +130,15 @@ class AttachmentControllerTest extends TestCase ...@@ -130,20 +130,15 @@ class AttachmentControllerTest extends TestCase
$this->assertIsBool($response['mailevaEnabled']); $this->assertIsBool($response['mailevaEnabled']);
foreach ($response['attachments'] as $value) { foreach ($response['attachments'] as $value) {
if ($value == self::$id) { if ($value['resId'] == self::$id) {
$userInfo = \User\models\UserModel::getByLogin(['login' => 'superadmin', 'select' => ['id']]);
$this->assertSame('La plus chétive cabane renferme plus de vertus que les palais des rois.', $value['title']); $this->assertSame('La plus chétive cabane renferme plus de vertus que les palais des rois.', $value['title']);
$this->assertSame('response_project', $value['attachment_type']); $this->assertSame('response_project', $value['type']);
$this->assertSame('txt', $value['format']);
$this->assertSame('A_TRA', $value['status']); $this->assertSame('A_TRA', $value['status']);
$this->assertSame('superadmin', $value['typist']); $this->assertSame($userInfo['id'], $value['typist']);
$this->assertSame(1, $value['relation']); $this->assertSame(1, $value['relation']);
$this->assertSame('MAARCH/2019D/24', $value['identifier']); $this->assertSame('MAARCH/2019D/24', $value['chrono']);
$this->assertNotNull($value['path']); $this->assertNull($value['originId']);
$this->assertNotNull($value['filename']);
$this->assertNotNull($value['docserver_id']);
$this->assertNotNull($value['fingerprint']);
$this->assertNotNull($value['filesize']);
$this->assertNull($value['origin_id']);
$this->assertNotNull($value['modificationDate']); $this->assertNotNull($value['modificationDate']);
$this->assertNotNull($value['modifiedBy']); $this->assertNotNull($value['modifiedBy']);
$this->assertNotNull($value['typeLabel']); $this->assertNotNull($value['typeLabel']);
......
...@@ -40,6 +40,46 @@ class AutocompleteControllerTest extends TestCase ...@@ -40,6 +40,46 @@ class AutocompleteControllerTest extends TestCase
} }
} }
public function testGetMaarchParapheurUsers()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET (EMPTY BECAUSE USER ALREADY LINKED)
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'manfred',
'exludeAlreadyConnected' => 'true'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getMaarchParapheurUsers($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
$this->assertEmpty($responseBody);
$aArgs = [
'search' => 'jane'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getMaarchParapheurUsers($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
foreach ($responseBody as $user) {
$this->assertIsInt($user->id);
$this->assertNotEmpty($user->firstname);
$this->assertNotEmpty($user->lastname);
$this->assertNotEmpty($user->email);
$this->assertIsBool($user->substitute);
$this->assertNotEmpty($user->idToDisplay);
$this->assertIsInt($user->externalId->maarchParapheur);
}
}
public function testGetCorrespondents() public function testGetCorrespondents()
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
...@@ -59,12 +99,8 @@ class AutocompleteControllerTest extends TestCase ...@@ -59,12 +99,8 @@ class AutocompleteControllerTest extends TestCase
foreach ($responseBody as $value) { foreach ($responseBody as $value) {
$this->assertIsInt($value->id); $this->assertIsInt($value->id);
// $this->assertIsString($value->idToDisplay);
// $this->assertIsString($value->otherInfo);
$this->assertNotEmpty($value->type); $this->assertNotEmpty($value->type);
$this->assertNotEmpty($value->id); $this->assertNotEmpty($value->id);
// $this->assertNotEmpty($value->idToDisplay);
// $this->assertNotEmpty($value->otherInfo);
if ($value->type == 'contact') { if ($value->type == 'contact') {
$this->assertNotEmpty($value->fillingRate->rate); $this->assertNotEmpty($value->fillingRate->rate);
$this->assertNotEmpty($value->fillingRate->thresholdLevel); $this->assertNotEmpty($value->fillingRate->thresholdLevel);
...@@ -105,7 +141,7 @@ class AutocompleteControllerTest extends TestCase ...@@ -105,7 +141,7 @@ class AutocompleteControllerTest extends TestCase
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
...@@ -127,13 +163,41 @@ class AutocompleteControllerTest extends TestCase ...@@ -127,13 +163,41 @@ class AutocompleteControllerTest extends TestCase
$this->assertIsString($value->idToDisplay); $this->assertIsString($value->idToDisplay);
$this->assertNotEmpty($value->idToDisplay); $this->assertNotEmpty($value->idToDisplay);
} }
// TEST WITH BBLIER
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$aArgs = [
'search' => 'blier',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getUsersForAdministration($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertSame('user', $value->type);
$this->assertIsInt($value->id);
$this->assertNotEmpty($value->id);
$this->assertIsString($value->idToDisplay);
$this->assertNotEmpty($value->idToDisplay);
}
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
} }
public function testGetUsersForCircuit() public function testGetUsersForCircuit()
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
...@@ -158,11 +222,42 @@ class AutocompleteControllerTest extends TestCase ...@@ -158,11 +222,42 @@ class AutocompleteControllerTest extends TestCase
} }
} }
public function testGetContactsCompany()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maar',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContactsCompany($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
$this->assertNotEmpty($responseBody);
$contact = $responseBody[0];
$this->assertIsInt($contact->id);
$this->assertNotEmpty($contact->company);
$this->assertIsNumeric($contact->addressNumber);
$this->assertNotEmpty($contact->addressStreet);
$this->assertEmpty($contact->addressAdditional1);
$this->assertEmpty($contact->addressAdditional2);
$this->assertNotEmpty($contact->addressPostcode);
$this->assertNotEmpty($contact->addressTown);
$this->assertNotEmpty($contact->addressCountry);
}
public function testGetEntities() public function testGetEntities()
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
...@@ -191,7 +286,7 @@ class AutocompleteControllerTest extends TestCase ...@@ -191,7 +286,7 @@ class AutocompleteControllerTest extends TestCase
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
...@@ -215,7 +310,7 @@ class AutocompleteControllerTest extends TestCase ...@@ -215,7 +310,7 @@ class AutocompleteControllerTest extends TestCase
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
...@@ -264,11 +359,72 @@ class AutocompleteControllerTest extends TestCase ...@@ -264,11 +359,72 @@ class AutocompleteControllerTest extends TestCase
$this->assertSame('Bad Request', $responseBody->errors); $this->assertSame('Bad Request', $responseBody->errors);
} }
public function testGetAvailableContactsForM2M()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'Préfecture',
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getAvailableContactsForM2M($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $contact) {
$this->assertIsInt($contact->id);
$this->assertNotEmpty($contact->m2m);
$this->assertNotEmpty($contact->communicationMeans);
}
}
public function testGetFolders()
{
$GLOBALS['userId'] = 'bblier';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'vie'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getFolders($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertIsArray($responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertIsInt($value->id);
$this->assertNotEmpty($value->idToDisplay);
$this->assertIsBool($value->isPublic);
$this->assertEmpty($value->otherInfo);
}
$GLOBALS['userId'] = 'superadmin';
$userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$GLOBALS['id'] = $userInfo['id'];
}
public function testGetTags() public function testGetTags()
{ {
$autocompleteController = new \SrcCore\controllers\AutoCompleteController(); $autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// CREATE // GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment); $request = \Slim\Http\Request::createFromEnvironment($environment);
......
...@@ -56,4 +56,21 @@ class CoreControllerTest extends TestCase ...@@ -56,4 +56,21 @@ class CoreControllerTest extends TestCase
$this->assertIsArray($responseBody->user->groups); $this->assertIsArray($responseBody->user->groups);
$this->assertIsArray($responseBody->user->entities); $this->assertIsArray($responseBody->user->entities);
} }
public function testGetLanguage()
{
$this->assertFileExists("src/core/lang/lang-en.php");
$this->assertStringNotEqualsFile("src/core/lang/lang-en.php", '');
include("src/core/lang/lang-en.php");
$this->assertFileExists("src/core/lang/lang-nl.php");
$this->assertStringNotEqualsFile("src/core/lang/lang-nl.php", '');
include("src/core/lang/lang-nl.php");
$language = \SrcCore\models\CoreConfigModel::getLanguage();
$this->assertFileExists("src/core/lang/lang-{$language}.php");
$this->assertStringNotEqualsFile("src/core/lang/lang-{$language}.php", '');
include("src/core/lang/lang-{$language}.php");
$this->assertFileNotExists("src/core/lang/lang-zh.php");
}
} }
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