diff --git a/phpunit.xml b/phpunit.xml index 29cc94d59146da1ba444fc39a3722ed5f8009c2f..64c5a928e26bbf982be34c4da9ec16869911079c 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,20 +2,17 @@ <phpunit colors="true" bootstrap="test/unitTests/define.php"> <testsuites> <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/action/ActionControllerTest.php</file> <file>test/unitTests/app/administration/AdministrationControllerTest.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/contact/ContactControllerTest.php</file> <file>test/unitTests/app/contact/ContactCustomFieldControllerTest.php</file> <file>test/unitTests/app/contact/ContactGroupControllerTest.php</file> <file>test/unitTests/app/customField/CustomFieldControllerTest.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/doctype/DoctypeControllerTest.php</file> <file>test/unitTests/app/entity/EntityControllerTest.php</file> @@ -26,7 +23,6 @@ <file>test/unitTests/app/notification/NotificationControllerTest.php</file> <file>test/unitTests/app/notification/NotificationScheduleControllerTest.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/resource/ResControllerTest.php</file> <file>test/unitTests/app/resource/ResourceListControllerTest.php</file> diff --git a/src/core/controllers/LogsController.php b/src/core/controllers/LogsController.php index 373b6151ccbfd5abf21817d28b18f09ad145c77e..93e214331a3729593d9c96b6759007a1ee9d3b30 100755 --- a/src/core/controllers/LogsController.php +++ b/src/core/controllers/LogsController.php @@ -23,25 +23,6 @@ require_once 'apps/maarch_entreprise/tools/log4php/Logger.php'; //TODO composer 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() { $loggingMethods = []; diff --git a/src/core/models/CoreConfigModel.php b/src/core/models/CoreConfigModel.php index c5533f8a42e28f3cf2c22601b67aa5e2adeddb5f..6ae8ba604963a90f59749cb17c7e0a78e7b450fb 100755 --- a/src/core/models/CoreConfigModel.php +++ b/src/core/models/CoreConfigModel.php @@ -237,6 +237,9 @@ class CoreConfigModel return $xmlfile; } + /** + * @codeCoverageIgnore + */ public static function initAngularStructure() { $lang = CoreConfigModel::getLanguage(); diff --git a/src/core/models/DatabaseModel.php b/src/core/models/DatabaseModel.php index f2e495c840a393bc84e6824050d0826276388238..c52acc94ba68095d1a44f4a265b343f9f152f64f 100755 --- a/src/core/models/DatabaseModel.php +++ b/src/core/models/DatabaseModel.php @@ -316,17 +316,4 @@ class DatabaseModel 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']); - } } diff --git a/src/core/models/DatabasePDO.php b/src/core/models/DatabasePDO.php index 4dca5b8f17ad1acfdc9d6ca5966888a6cceb96f2..a8f0c178f695c3a909798f2d96e3d9db2aa0960f 100755 --- a/src/core/models/DatabasePDO.php +++ b/src/core/models/DatabasePDO.php @@ -217,9 +217,4 @@ class DatabasePDO { 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); - } } diff --git a/src/core/models/TextFormatModel.php b/src/core/models/TextFormatModel.php index 3ea6444ccf3cafe294128f25d121ab1d8355ccf7..51ffa9fd498abd7e69d9fea77e249ea26fae421f 100755 --- a/src/core/models/TextFormatModel.php +++ b/src/core/models/TextFormatModel.php @@ -64,41 +64,23 @@ class TextFormatModel 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(" ", " ", $html); - $html = str_replace("é", "\u00e9", $html); - $html = str_replace("è", "\u00e8", $html); - $html = str_replace("ê", "\00ea", $html); - $html = str_replace("à", "\u00e0", $html); - $html = str_replace("â", "\u00e2", $html); - $html = str_replace("î", "\u00ee", $html); - $html = str_replace("ô", "\u00f4", $html); - $html = str_replace("û", "\u00fb", $html); - $html = str_replace("´", "\u0027", $html); - $html = str_replace("°", "\u00b0", $html); - $html = str_replace("’", "\u2019", $html); - } else { - $html = str_replace("<br/>", "\\n", $html); - $html = str_replace("<br />", "\\n", $html); - $html = str_replace("<br/>", "\\n", $html); - $html = str_replace(" ", " ", $html); - $html = str_replace("é", "é", $html); - $html = str_replace("è", "è", $html); - $html = str_replace("ê", "ê", $html); - $html = str_replace("à", "à ", $html); - $html = str_replace("â", "â", $html); - $html = str_replace("î", "î", $html); - $html = str_replace("ô", "ô", $html); - $html = str_replace("û", "û", $html); - $html = str_replace("´", "", $html); - $html = str_replace("°", "°", $html); - $html = str_replace("’", "'", $html); - } + $html = str_replace("<br/>", "\\n", $html); + $html = str_replace("<br />", "\\n", $html); + $html = str_replace("<br/>", "\\n", $html); + $html = str_replace(" ", " ", $html); + $html = str_replace("é", "\u00e9", $html); + $html = str_replace("è", "\u00e8", $html); + $html = str_replace("ê", "\00ea", $html); + $html = str_replace("à", "\u00e0", $html); + $html = str_replace("â", "\u00e2", $html); + $html = str_replace("î", "\u00ee", $html); + $html = str_replace("ô", "\u00f4", $html); + $html = str_replace("û", "\u00fb", $html); + $html = str_replace("´", "\u0027", $html); + $html = str_replace("°", "\u00b0", $html); + $html = str_replace("’", "\u2019", $html); return $html; } diff --git a/test/unitTests/app/attachment/AttachmentControllerTest.php b/test/unitTests/app/attachment/AttachmentControllerTest.php index f521ece51893d316a03bd5c7cd8eef3abb360b54..08d772e9ac37b5f0fffdb731c5e86be69fe24c9b 100755 --- a/test/unitTests/app/attachment/AttachmentControllerTest.php +++ b/test/unitTests/app/attachment/AttachmentControllerTest.php @@ -130,20 +130,15 @@ class AttachmentControllerTest extends TestCase $this->assertIsBool($response['mailevaEnabled']); 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('response_project', $value['attachment_type']); - $this->assertSame('txt', $value['format']); + $this->assertSame('response_project', $value['type']); $this->assertSame('A_TRA', $value['status']); - $this->assertSame('superadmin', $value['typist']); + $this->assertSame($userInfo['id'], $value['typist']); $this->assertSame(1, $value['relation']); - $this->assertSame('MAARCH/2019D/24', $value['identifier']); - $this->assertNotNull($value['path']); - $this->assertNotNull($value['filename']); - $this->assertNotNull($value['docserver_id']); - $this->assertNotNull($value['fingerprint']); - $this->assertNotNull($value['filesize']); - $this->assertNull($value['origin_id']); + $this->assertSame('MAARCH/2019D/24', $value['chrono']); + $this->assertNull($value['originId']); $this->assertNotNull($value['modificationDate']); $this->assertNotNull($value['modifiedBy']); $this->assertNotNull($value['typeLabel']); diff --git a/test/unitTests/core/AutocompleteControllerTest.php b/test/unitTests/core/AutocompleteControllerTest.php index af1a999bd2d3df0c903bca5b502be3b0bf3b0bea..e9621d7c311d30d1ad3cc7c93fcf9e7fb7706444 100755 --- a/test/unitTests/core/AutocompleteControllerTest.php +++ b/test/unitTests/core/AutocompleteControllerTest.php @@ -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() { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); @@ -59,12 +99,8 @@ class AutocompleteControllerTest extends TestCase foreach ($responseBody as $value) { $this->assertIsInt($value->id); - // $this->assertIsString($value->idToDisplay); - // $this->assertIsString($value->otherInfo); $this->assertNotEmpty($value->type); $this->assertNotEmpty($value->id); - // $this->assertNotEmpty($value->idToDisplay); - // $this->assertNotEmpty($value->otherInfo); if ($value->type == 'contact') { $this->assertNotEmpty($value->fillingRate->rate); $this->assertNotEmpty($value->fillingRate->thresholdLevel); @@ -105,7 +141,7 @@ class AutocompleteControllerTest extends TestCase { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -127,13 +163,41 @@ class AutocompleteControllerTest extends TestCase $this->assertIsString($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() { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -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() { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -191,7 +286,7 @@ class AutocompleteControllerTest extends TestCase { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -215,7 +310,7 @@ class AutocompleteControllerTest extends TestCase { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -264,11 +359,72 @@ class AutocompleteControllerTest extends TestCase $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() { $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - // CREATE + // GET $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); diff --git a/test/unitTests/core/CoreControllerTest.php b/test/unitTests/core/CoreControllerTest.php index d3e3fdd5f3c472275366d67ed2bc2aa2287876fc..7d46c0da9a93f0da1c71d47c6ed4a6a7a92cc8e5 100755 --- a/test/unitTests/core/CoreControllerTest.php +++ b/test/unitTests/core/CoreControllerTest.php @@ -56,4 +56,21 @@ class CoreControllerTest extends TestCase $this->assertIsArray($responseBody->user->groups); $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"); + } }