diff --git a/phpunit.xml b/phpunit.xml index edd581bb897e800ad6c179ca0d7b9ed022a98904..9595cafc002e17bf669eb0ceb193d6d171669cdf 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,31 +3,7 @@ <testsuites> <testsuite name="Maarch Test Suite"> <!--directory>test</directory--> - <file>test/unitTests/app/action/ActionControllerTest.php</file> - <file>test/unitTests/core/AutocompleteControllerTest.php</file> - <file>test/unitTests/app/basket/BasketControllerTest.php</file> - <file>test/unitTests/app/contact/ContactControllerTest.php</file> - <file>test/unitTests/app/contact/ContactGroupControllerTest.php</file> - <file>test/unitTests/app/contact/ContactTypeControllerTest.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> - <file>test/unitTests/app/group/GroupControllerTest.php</file> - <file>test/unitTests/app/entity/ListTemplateControllerTest.php</file> - <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/report/ReportControllerTest.php</file> - <file>test/unitTests/app/resource/ResControllerTest.php</file> - <file>test/unitTests/app/status/StatusControllerTest.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> - <!-- The last one should be history --> - <file>test/unitTests/app/history/HistoryControllerTest.php</file> + <file>test/unitTests/app/document/DocumentControllerTest.php</file> </testsuite> </testsuites> <filter> diff --git a/rest/index.php b/rest/index.php index c9b88717452af9ee3e19c54b61fdbb7cb003f516..75d366dc8145a9bfcd55c6bbc95034ad2749eab0 100755 --- a/rest/index.php +++ b/rest/index.php @@ -40,6 +40,7 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, //Documents $app->get('/documents', \Document\controllers\DocumentController::class . ':get'); +$app->get('/documents/{id}', \Document\controllers\DocumentController::class . ':getById'); ////Ressources @@ -95,14 +96,5 @@ $app->get('/documents', \Document\controllers\DocumentController::class . ':get' //$app->post('/users/{id}/redirectedBaskets', \User\controllers\UserController::class . ':setRedirectedBaskets'); //$app->delete('/users/{id}/redirectedBaskets/{basketId}', \User\controllers\UserController::class . ':deleteRedirectedBaskets'); //$app->put('/users/{id}/baskets', \User\controllers\UserController::class . ':updateBasketsDisplay'); -// -////CurrentUser -//$app->get('/currentUser/profile', \User\controllers\UserController::class . ':getProfile'); -//$app->put('/currentUser/profile', \User\controllers\UserController::class . ':updateProfile'); -//$app->put('/currentUser/password', \User\controllers\UserController::class . ':updateCurrentUserPassword'); -//$app->post('/currentUser/emailSignature', \User\controllers\UserController::class . ':createCurrentUserEmailSignature'); -//$app->put('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':updateCurrentUserEmailSignature'); -//$app->delete('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':deleteCurrentUserEmailSignature'); -//$app->put('/currentUser/groups/{groupId}/baskets/{basketId}', \User\controllers\UserController::class . ':updateCurrentUserBasketPreferences'); $app->run(); diff --git a/sql/data_fr.sql b/sql/data_fr.sql index 9227de406d16ddf957e064d7644447e8e14be87c..ba89e4ce839bbdba7c8cb2e4b0bca9d665a4dce9 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -1,56 +1,25 @@ - --- Create USERS -DELETE FROM users WHERE user_id <> 'superadmin'; -DELETE FROM users WHERE user_id = 'rrenaud'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (1, 'rrenaud', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Robert', 'RENAUD', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'ssissoko'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (3, 'ssissoko', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Sylvain', 'SISSOKO', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'jjane'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (6, 'jjane', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Jenny', 'JANE', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'eerina'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (7, 'eerina', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Edith', 'ERINA', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'ppetit'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (10, 'ppetit', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Patricia', 'PETIT', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'sstar'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (14, 'sstar', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Suzanne', 'STAR', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'mmanfred'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (17, 'mmanfred', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Martin', 'MANFRED', 'info@maarch.org', 'Y', 'OK', 'standard'); -DELETE FROM users WHERE user_id = 'ddaull'; -INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (18, 'ddaull', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Denis', 'DAULL', 'info@maarch.org', 'Y', 'OK', 'standard'); - --- Donnees manuelles ------------ ---DOCSERVERS +--USERS ------------ -TRUNCATE TABLE docserver_types; -INSERT INTO docserver_types (docserver_type_id, docserver_type_label, enabled, fingerprint_mode) -VALUES ('DOC', 'Documents numériques', 'Y', 'SHA512'); -INSERT INTO docserver_types (docserver_type_id, docserver_type_label, enabled, fingerprint_mode) -VALUES ('CONVERT', 'Conversions de formats', 'Y', 'SHA256'); +TRUNCATE TABLE users; +INSERT INTO users (login, password, firstname, lastname, mail, enabled, status, loginmode) VALUES ('jjane', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Jenny', 'JANE', 'info@maarch.org', 'Y', 'OK', 'standard'); -TRUNCATE TABLE docservers; -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_MAN', 'DOC', 'Dépôt documentaire de numérisation manuelle', 'N', 50000000000, 1290730, '/opt/maarchparapheur/docservers/manual/', '2011-01-13 14:47:49.197164', 'letterbox_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_ATTACH', 'DOC', 'Dépôt des pièces jointes', 'N', 50000000000, 1, '/opt/maarchparapheur/docservers/manual_attachments/', '2011-01-13 14:47:49.197164', 'attachments_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_MLB', 'CONVERT', 'Dépôt des formats des documents numérisés', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/convert_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_ATTACH', 'CONVERT', 'Dépôt des formats des pièces jointes', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/convert_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); ------------ ---SUPERADMIN USER +--DOCSERVERS ------------ -DELETE FROM users WHERE user_id='superadmin'; -INSERT INTO users (user_id, password, firstname, lastname, phone, mail, enabled, status, loginmode) VALUES ('superadmin', '$2y$10$Vq244c5s2zmldjblmMXEN./Q2qZrqtGVgrbz/l1WfsUJbLco4E.e.', 'Super', 'ADMIN', '0147245159', 'info@maarch.org', 'Y', 'OK', 'standard'); ---MAARCH2GEC USER -DELETE FROM users WHERE user_id = 'cchaplin'; -INSERT INTO users (user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES ('cchaplin', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Charlie', 'CHAPLIN', 'info@maarch.org', 'Y', 'OK', 'restMode'); +TRUNCATE TABLE docservers; +INSERT INTO docservers (type, label, is_readonly, size_limit_number, actual_size_number, path, creation_date) +VALUES ('DOC', 'Documents principaux', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/manual/', CURRENT_TIMESTAMP); ------------ ---STATUS- +--STATUS ------------ TRUNCATE TABLE status; -INSERT INTO status (id, label_status) VALUES ('ANNOT', 'Annotation'); -INSERT INTO status (id, label_status) VALUES ('SIGN', 'Parapheur'); -INSERT INTO status (id, label_status) VALUES ('VAL', 'Validé'); -INSERT INTO status (id, label_status) VALUES ('REF', 'Refusé'); +INSERT INTO status (reference, label) VALUES ('ANNOT', 'Annotation'); +INSERT INTO status (reference, label) VALUES ('SIGN', 'Parapheur'); +INSERT INTO status (reference, label) VALUES ('VAL', 'Validé'); +INSERT INTO status (reference, label) VALUES ('REF', 'Refusé'); + +/* Tests */ +INSERT INTO main_documents (reference, subject, doc_date, status, priority, sender, sender_entity, processing_user, recipient, creation_date) VALUES ('2018/A/1', 'Mon Courrier', CURRENT_TIMESTAMP, 2, 'Urgent', 'Oliver Queen', 'QE', 1, 'Barry Allen', CURRENT_TIMESTAMP); +INSERT INTO adr_main_documents (main_document_id, type, path, filename) VALUES (1, 'DOC', 'tests/', 'test.pdf'); diff --git a/sql/structure.sql b/sql/structure.sql index 7328c3ab2f93fc764fa2d1f22160b817f5bd82ba..1b64747e41fe6b0f63b5c7f75ac2e88f02319616 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -5,55 +5,62 @@ SET standard_conforming_strings = off; SET check_function_bodies = false; SET client_min_messages = warning; SET escape_string_warning = off; - ---DROP PROCEDURAL LANGUAGE IF EXISTS plpgsql CASCADE; ---CREATE PROCEDURAL LANGUAGE plpgsql; - SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -CREATE TABLE docservers + +DROP TABLE IF EXISTS main_documents; +CREATE TABLE main_documents ( id serial NOT NULL, - type character varying(32) NOT NULL, - label character varying(255), - is_readonly character(1) NOT NULL DEFAULT 'N'::bpchar, - size_limit_number bigint NOT NULL DEFAULT (0)::bigint, - actual_size_number bigint NOT NULL DEFAULT (0)::bigint, - path character varying(255) NOT NULL, - creation_date timestamp without time zone NOT NULL, - CONSTRAINT docservers_pkey PRIMARY KEY (id), - CONSTRAINT docservers_type_key UNIQUE (type) + external_id character varying(255), + reference character varying(255), + subject text, + doc_date timestamp without time zone, + status integer NOT NULL, + priority character varying(255), + sender text NOT NULL, + sender_entity text, + processing_user integer NOT NULL, + recipient text, + creation_date timestamp without time zone NOT NULL DEFAULT NOW(), + modification_date timestamp without time zone DEFAULT NOW(), + CONSTRAINT main_documents_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); -CREATE TABLE history +DROP TABLE IF EXISTS attachments; +CREATE TABLE attachments ( id serial NOT NULL, - table_name character varying(32) DEFAULT NULL::character varying, - record_id character varying(255) DEFAULT NULL::character varying, - event_type character varying(32) NOT NULL, - user_id character varying(128) NOT NULL, - event_date timestamp without time zone NOT NULL, - info text, - id_module character varying(50) NOT NULL DEFAULT 'admin'::character varying, - remote_ip character varying(32) DEFAULT NULL, - event_id character varying(50), - CONSTRAINT history_pkey PRIMARY KEY (id) + subject text, + reference character varying(255), + format character varying(50) NOT NULL, + typist character varying(128) NOT NULL, + creation_date timestamp without time zone NOT NULL, + docserver_id character varying(32) NOT NULL, + path character varying(255) DEFAULT NULL::character varying, + filename character varying(255) DEFAULT NULL::character varying, + fingerprint character varying(255) DEFAULT NULL::character varying, + filesize bigint, + main_document_id bigint, + CONSTRAINT attachments_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS status; CREATE TABLE status ( id serial, - status_id character varying(10) NOT NULL, + reference character varying(10) NOT NULL, label character varying(50) NOT NULL, CONSTRAINT status_pkey PRIMARY KEY (id), - CONSTRAINT status_status_id_key UNIQUE (status_id) + CONSTRAINT status_reference_key UNIQUE (reference) ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS users; CREATE TABLE users ( id serial NOT NULL, @@ -70,48 +77,28 @@ CREATE TABLE users loginmode character varying(50) DEFAULT NULL::character varying, cookie_key character varying(255) DEFAULT NULL::character varying, cookie_date timestamp without time zone, - CONSTRAINT users_pkey PRIMARY KEY (user_id), - CONSTRAINT users_id_key UNIQUE (id) -) -WITH (OIDS=FALSE); - -CREATE TABLE main_documents -( - id serial NOT NULL, - external_id character varying(255), - reference character varying(255), - subject text, - doc_date timestamp without time zone, - status integer NOT NULL, - priority character varying(255), - sender text NOT NULL, - sender_entity text, - processing_user integer NOT NULL, - recipient text, - creation_date timestamp without time zone NOT NULL DEFAULT NOW(), - modification_date timestamp without time zone DEFAULT NOW(), - CONSTRAINT main_documents_pkey PRIMARY KEY (id) + CONSTRAINT users_pkey PRIMARY KEY (id), + CONSTRAINT users_login_key UNIQUE (login) ) WITH (OIDS=FALSE); -CREATE TABLE attachments +DROP TABLE IF EXISTS docservers; +CREATE TABLE docservers ( id serial NOT NULL, - subject text, - format character varying(50) NOT NULL, - typist character varying(128) NOT NULL, + type character varying(32) NOT NULL, + label character varying(255), + is_readonly character(1) NOT NULL DEFAULT 'N'::bpchar, + size_limit_number bigint NOT NULL DEFAULT (0)::bigint, + actual_size_number bigint NOT NULL DEFAULT (0)::bigint, + path character varying(255) NOT NULL, creation_date timestamp without time zone NOT NULL, - identifier character varying(255) DEFAULT NULL::character varying, - docserver_id character varying(32) NOT NULL, - path character varying(255) DEFAULT NULL::character varying, - filename character varying(255) DEFAULT NULL::character varying, - fingerprint character varying(255) DEFAULT NULL::character varying, - filesize bigint, - main_document_id bigint, - CONSTRAINT attachments_pkey PRIMARY KEY (id) + CONSTRAINT docservers_pkey PRIMARY KEY (id), + CONSTRAINT docservers_type_key UNIQUE (type) ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS adr_main_documents; CREATE TABLE adr_main_documents ( id serial NOT NULL, @@ -125,6 +112,7 @@ CREATE TABLE adr_main_documents ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS adr_attachments; CREATE TABLE adr_attachments ( id serial NOT NULL, @@ -138,10 +126,11 @@ CREATE TABLE adr_attachments ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS users_signatures; CREATE TABLE users_signatures ( id serial NOT NULL, - user_serial_id integer NOT NULL, + user_id integer NOT NULL, label character varying(255) DEFAULT NULL::character varying, path character varying(255) DEFAULT NULL::character varying, filename character varying(255) DEFAULT NULL::character varying, @@ -149,3 +138,20 @@ CREATE TABLE users_signatures CONSTRAINT user_signatures_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); + +DROP TABLE IF EXISTS history; +CREATE TABLE history +( + id serial NOT NULL, + table_name character varying(32) DEFAULT NULL::character varying, + record_id character varying(255) DEFAULT NULL::character varying, + event_type character varying(32) NOT NULL, + user_id character varying(128) NOT NULL, + event_date timestamp without time zone NOT NULL, + info text, + id_module character varying(50) NOT NULL DEFAULT 'admin'::character varying, + remote_ip character varying(32) DEFAULT NULL, + event_id character varying(50), + CONSTRAINT history_pkey PRIMARY KEY (id) +) +WITH (OIDS=FALSE); diff --git a/src/app/convert/models/AdrModel.php b/src/app/convert/models/AdrModel.php index f46e02732e41fc06b20685e8edf959c8eca7f4c7..4abed101f50bf14e6222d5ae2359b687816b74c9 100644 --- a/src/app/convert/models/AdrModel.php +++ b/src/app/convert/models/AdrModel.php @@ -48,180 +48,17 @@ class AdrModel return $attachment[0]; } - public static function getDocumentsAdr(array $aArgs = []) + public static function getDocumentsAdr(array $aArgs) { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit', 'offset']); + ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - $aReturn = DatabaseModel::select([ + $addresses = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['adr_letterbox'], + 'table' => ['adr_main_documents'], 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'offset' => empty($aArgs['offset']) ? 0 : $aArgs['offset'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] ]); - return $aReturn; - } - - public static function getTypedDocumentAdrByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'type']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::stringType($aArgs, ['type']); - ValidatorModel::arrayType($aArgs, ['select']); - - $adr = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['adr_letterbox'], - 'where' => ['res_id = ?', 'type = ?'], - 'data' => [$aArgs['resId'], $aArgs['type']] - ]); - - if (empty($adr[0])) { - return []; - } - - return $adr[0]; - } - - public static function getTypedAttachAdrByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'type']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::stringType($aArgs, ['type']); - ValidatorModel::arrayType($aArgs, ['select']); - ValidatorModel::boolType($aArgs, ['isVersion']); - - if ($aArgs['isVersion']) { - $table = "adr_attachments_version"; - } else { - $table = "adr_attachments"; - } - - $adr = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => [$table], - 'where' => ['res_id = ?', 'type = ?'], - 'data' => [$aArgs['resId'], $aArgs['type']] - ]); - - if (empty($adr[0])) { - return []; - } - - return $adr[0]; - } - - public static function createDocumentAdr(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'docserverId', 'path', 'filename', 'type']); - ValidatorModel::stringType($aArgs, ['docserverId', 'path', 'filename', 'type', 'fingerprint']); - ValidatorModel::intVal($aArgs, ['resId']); - - DatabaseModel::insert([ - 'table' => 'adr_letterbox', - 'columnsValues' => [ - 'res_id' => $aArgs['resId'], - 'type' => $aArgs['type'], - 'docserver_id' => $aArgs['docserverId'], - 'path' => $aArgs['path'], - 'filename' => $aArgs['filename'], - 'fingerprint' => empty($aArgs['fingerprint']) ? null : $aArgs['fingerprint'], - ] - ]); - - return true; - } - - public static function createAttachAdr(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'docserverId', 'path', 'filename', 'type']); - ValidatorModel::stringType($aArgs, ['docserverId', 'path', 'filename', 'type', 'fingerprint']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::boolType($aArgs, ['isVersion']); - - if ($aArgs['isVersion']) { - $table = "adr_attachments_version"; - } else { - $table = "adr_attachments"; - } - - DatabaseModel::insert([ - 'table' => $table, - 'columnsValues' => [ - 'res_id' => $aArgs['resId'], - 'type' => $aArgs['type'], - 'docserver_id' => $aArgs['docserverId'], - 'path' => $aArgs['path'], - 'filename' => $aArgs['filename'], - 'fingerprint' => empty($aArgs['fingerprint']) ? null : $aArgs['fingerprint'], - ] - ]); - return true; - } - - public static function updateAttachAdr(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'path', 'filename', 'type']); - ValidatorModel::stringType($aArgs, ['path', 'filename', 'type', 'fingerprint']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::boolType($aArgs, ['isVersion']); - - if ($aArgs['isVersion']) { - $table = "adr_attachments_version"; - } else { - $table = "adr_attachments"; - } - - DatabaseModel::update([ - 'table' => $table, - 'set' => [ - 'path' => $aArgs['path'], - 'filename' => $aArgs['filename'], - 'fingerprint' => empty($aArgs['fingerprint']) ? null : $aArgs['fingerprint'], - ], - 'where' => ['res_id = ?', 'type = ?'], - 'data' => [$aArgs['resId'],$aArgs['type']] - ]); - - return true; - } - - public static function deleteDocumentAdr(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'adr_letterbox', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function deleteAttachAdr(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::boolType($aArgs, ['isVersion']); - - if ($aArgs['isVersion']) { - $table = "adr_attachments_version"; - } else { - $table = "adr_attachments"; - } - - DatabaseModel::delete([ - 'table' => $table, - 'where' => ['res_id = ?'], - 'data' => [$aArgs['resId']] - ]); - - return true; + return $addresses; } } diff --git a/src/app/docserver/controllers/DocserverTypeController.php b/src/app/docserver/controllers/DocserverTypeController.php deleted file mode 100644 index b6233e8754fd5461070dccdd455848a9a867444f..0000000000000000000000000000000000000000 --- a/src/app/docserver/controllers/DocserverTypeController.php +++ /dev/null @@ -1,47 +0,0 @@ -<?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. -* -*/ - -/** -* @brief DocerverType Controller -* @author dev@maarch.org -*/ - -namespace Docserver\controllers; - -use Group\models\ServiceModel; -use Docserver\models\DocserverTypeModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class DocserverTypeController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_docservers', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['docserverTypes' => DocserverTypeModel::get(['orderBy' => ['docserver_type_label']])]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_docservers', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $docserverType = DocserverTypeModel::getById(['id' => $aArgs['id']]); - - if(empty($docserverType)){ - return $response->withStatus(400)->withJson(['errors' => 'Docserver Type not found']); - } - - return $response->withJson($docserverType); - } -} diff --git a/src/app/docserver/models/DocserverModel.php b/src/app/docserver/models/DocserverModel.php index 7d77fdbed3e9f4c8d725ff43298f5bcf4b301e8a..9871e4f3d72cf0e8c952fd34a122be7123929d0c 100644 --- a/src/app/docserver/models/DocserverModel.php +++ b/src/app/docserver/models/DocserverModel.php @@ -10,11 +10,31 @@ /** * @brief Docserver Model * @author dev@maarch.org -* @ingroup core */ namespace Docserver\models; -class DocserverModel extends DocserverModelAbstract +use SrcCore\models\DatabaseModel; +use SrcCore\models\ValidatorModel; + +class DocserverModel { - // Do your stuff in this class + public static function getByType(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['type']); + ValidatorModel::stringType($aArgs, ['type']); + ValidatorModel::arrayType($aArgs, ['select']); + + $aDocserver = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['docservers'], + 'where' => ['type = ?'], + 'data' => [$aArgs['type']] + ]); + + if (empty($aDocserver[0])) { + return []; + } + + return $aDocserver[0]; + } } diff --git a/src/app/docserver/models/DocserverModelAbstract.php b/src/app/docserver/models/DocserverModelAbstract.php deleted file mode 100644 index 8c485a62d1bb4fbbf9f7fa46c48d40471c34088f..0000000000000000000000000000000000000000 --- a/src/app/docserver/models/DocserverModelAbstract.php +++ /dev/null @@ -1,157 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Docserver Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Docserver\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -class DocserverModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aDocservers = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['docservers'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aDocservers; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aDocserver = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['docservers'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aDocserver[0])) { - return []; - } - - return $aDocserver[0]; - } - - public static function getByDocserverId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['docserverId']); - ValidatorModel::stringType($aArgs, ['docserverId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aDocserver = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['docservers'], - 'where' => ['docserver_id = ?'], - 'data' => [$aArgs['docserverId']] - ]); - - if (empty($aDocserver[0])) { - return []; - } - - return $aDocserver[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['docserver_id', 'docserver_type_id', 'device_label', 'path_template', 'coll_id', 'size_limit_number', 'is_readonly']); - ValidatorModel::stringType($aArgs, ['docserver_id', 'docserver_type_id', 'device_label', 'path_template', 'coll_id', 'is_readonly']); - ValidatorModel::intVal($aArgs, ['size_limit_number']); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'docservers_id_seq']); - - DatabaseModel::insert([ - 'table' => 'docservers', - 'columnsValues' => [ - 'id' => $nextSequenceId, - 'docserver_id' => $aArgs['docserver_id'], - 'docserver_type_id' => $aArgs['docserver_type_id'], - 'device_label' => $aArgs['device_label'], - 'path_template' => $aArgs['path_template'], - 'coll_id' => $aArgs['coll_id'], - 'size_limit_number' => $aArgs['size_limit_number'], - 'is_readonly' => $aArgs['is_readonly'], - 'creation_date' => 'CURRENT_TIMESTAMP' - ] - ]); - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $id = $aArgs['id']; - unset($aArgs['id']); - - DatabaseModel::update([ - 'table' => 'docservers', - 'set' => $aArgs, - 'where' => ['id = ?'], - 'data' => [$id] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'docservers', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function getCurrentDocserver(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['collId', 'typeId']); - ValidatorModel::stringType($aArgs, ['collId', 'typeId']); - - $aDocserver = DatabaseModel::select([ - 'select' => ['*'], - 'table' => ['docservers'], - 'where' => ['is_readonly = ?', 'coll_id = ?', 'docserver_type_id = ?'], - 'data' => ['N', $aArgs['collId'], $aArgs['typeId']], - 'limit' => 1, - ]); - - if (empty($aDocserver[0])) { - return []; - } - - return $aDocserver[0]; - } -} diff --git a/src/app/docserver/models/DocserverTypeModel.php b/src/app/docserver/models/DocserverTypeModel.php deleted file mode 100644 index 044eb118d4f54af20643d48f3f514f0a8d6882c2..0000000000000000000000000000000000000000 --- a/src/app/docserver/models/DocserverTypeModel.php +++ /dev/null @@ -1,20 +0,0 @@ -<?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. -* -*/ - -/** -* @brief DocserverType Model -* @author dev@maarch.org -* @ingroup core -*/ -namespace Docserver\models; - -class DocserverTypeModel extends DocserverTypeModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/docserver/models/DocserverTypeModelAbstract.php b/src/app/docserver/models/DocserverTypeModelAbstract.php deleted file mode 100644 index 64f961240bebb59983aa4ce6eca0e51eb97d458d..0000000000000000000000000000000000000000 --- a/src/app/docserver/models/DocserverTypeModelAbstract.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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. -* -*/ - -/** -* @brief DocserverType Model -* @author dev@maarch.org -*/ - -namespace Docserver\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -class DocserverTypeModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aDocserverTypes = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['docserver_types'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - - return $aDocserverTypes; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - $aDocserverType = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['docserver_types'], - 'where' => ['docserver_type_id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aDocserverType[0])) { - return []; - } - - return $aDocserverType[0]; - } -} diff --git a/src/app/docserver/models/ResDocserverModel.php b/src/app/docserver/models/ResDocserverModel.php deleted file mode 100644 index 61af17539285fe262722baf321c40e9d0e7f02d7..0000000000000000000000000000000000000000 --- a/src/app/docserver/models/ResDocserverModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Res and docserver association Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Docserver\models; - -class ResDocserverModel extends ResDocserverModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/docserver/models/ResDocserverModelAbstract.php b/src/app/docserver/models/ResDocserverModelAbstract.php deleted file mode 100644 index b8d6de3e1895cac8018d2df7fed6bf1134496f59..0000000000000000000000000000000000000000 --- a/src/app/docserver/models/ResDocserverModelAbstract.php +++ /dev/null @@ -1,93 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Res Docserver association Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Docserver\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -class ResDocserverModelAbstract -{ - - /** - * Retrieve the path of source file to process - * @param string $resTable resource table - * @param string $adrTable adr table - * @param bigint $resId Id of the resource to process - * @param string $adrType type of the address - * $resTable, $adrTable, $resId, $adrType = 'DOC' - * @return string - */ - public static function getSourceResourcePath(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['resTable']); - ValidatorModel::notEmpty($aArgs, ['adrTable']); - ValidatorModel::notEmpty($aArgs, ['resId']); - - if (!isset($aArgs['adrType'])) { - $aArgs['adrType'] = 'DOC'; - } - - if ($aArgs['adrType'] == 'DOC') { - $table = $aArgs['resTable']; - $where = ['res_id=?']; - $data = [$aArgs['resId']]; - } else { - $table = $aArgs['adrTable']; - $where = ['res_id = ?', 'adr_type = ?']; - $data = [$aArgs['resId'], $aArgs['adrType']]; - } - - $aReturn = DatabaseModel::select([ - 'select' => [$table.'.path', $table.'.filename', $table.'.offset_doc', 'docservers.path_template'], - 'table' => [$table, 'docservers'], - 'where' => $where, - 'data' => $data, - 'left_join' => [$table.'.docserver_id = docservers.docserver_id'] - ]); - - if (empty($aReturn)) { - return false; - } - - $resPath = ''; - $resFilename = ''; - if (isset($aReturn[0]['path'])) { - $resPath = $aReturn[0]['path']; - } - if (isset($aReturn[0]['filename'])) { - $resFilename = $aReturn[0]['filename']; - } - if (isset($aReturn[0]['offset_doc']) - && $aReturn[0]['offset_doc'] <> '' - && $aReturn[0]['offset_doc'] <> ' ' - ) { - $sourceFilePath = $aReturn[0]['path'] - . $aReturn[0]['filename'] - . DIRECTORY_SEPARATOR . $aReturn[0]['offset_doc']; - } else { - $sourceFilePath = $resPath . $resFilename; - } - $resPathTemplate = ''; - if (isset($aReturn[0]['path_template'])) { - $resPathTemplate = $aReturn[0]['path_template']; - } - - $sourceFilePath = $resPathTemplate . $sourceFilePath; - $sourceFilePath = str_replace('#', DIRECTORY_SEPARATOR, $sourceFilePath); - - return $sourceFilePath; - } -} diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index f853efeba5841077478724ef6126742b31e40bba..2a8f5fa12067ce2e7aa1e0fbe21fc87890f87076 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -14,9 +14,13 @@ namespace Document\controllers; +use Convert\models\AdrModel; +use Docserver\models\DocserverModel; use Document\models\DocumentModel; use Slim\Http\Request; use Slim\Http\Response; +use SrcCore\models\ValidatorModel; +use Status\models\StatusModel; use User\models\UserModel; class DocumentController @@ -34,8 +38,65 @@ class DocumentController $user = UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]); - $documents = DocumentModel::getByUserId(['select' => ['*'], 'userId' => $user['id']]); + $documents = DocumentModel::getByUserId(['select' => ['id', 'reference', 'subject', 'status'], 'userId' => $user['id']]); + foreach ($documents as $key => $document) { + $status = StatusModel::getById(['select' => ['label'], 'id' => $document['status']]); + $documents[$key]['statusDisplay'] = $status['label']; + } return $response->withJson(['documents' => $documents]); } + + public function getById(Request $request, Response $response, array $args) + { + if (!DocumentController::hasRightById(['id' => $args['id'], 'login' => $GLOBALS['login']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + + $document = DocumentModel::getById(['select' => ['*'], 'id' => $args['id']]); + if (empty($document)) { + return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']); + } + + $status = StatusModel::getById(['select' => ['label'], 'id' => $document['status']]); + $document['statusDisplay'] = $status['label']; + $document['processingUserDisplay'] = UserModel::getLabelledUserById(['id' => $document['processing_user']]); + + + $documentAdr = AdrModel::getDocumentsAdr([ + 'select' => ['path', 'filename'], + 'where' => ['main_document_id = ?', 'type = ?'], + 'data' => [$args['id'], 'DOC'] + ]); + + $docserver = DocserverModel::getByType(['type' => 'DOC', 'select' => ['path']]); + if (empty($docserver['path']) || !file_exists($docserver['path'])) { + return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']); + } + + $pathToDocument = $docserver['path'] . $documentAdr[0]['path'] . $documentAdr[0]['filename']; + if (!file_exists($pathToDocument)) { + return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']); + } + + $document['document'] = base64_encode(file_get_contents($pathToDocument)); + + return $response->withJson(['document' => $document]); + } + + public static function hasRightById(array $args) + { + ValidatorModel::notEmpty($args, ['id', 'login']); + ValidatorModel::intVal($args, ['id']); + ValidatorModel::stringType($args, ['login']); + + $user = UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]); + + $document = DocumentModel::get(['select' => [1], 'where' => ['processing_user = ?', 'id = ?'], 'data' => [$user['id'], $args['id']]]); + if (empty($document)) { + return false; + } + + return true; + } } diff --git a/src/app/document/models/DocumentModel.php b/src/app/document/models/DocumentModel.php index cd257bb0dc0dae146c387dc8f2885a7deff3f6a9..130d7074d0ff0f8de0728b7e3c4b69c265f475a1 100644 --- a/src/app/document/models/DocumentModel.php +++ b/src/app/document/models/DocumentModel.php @@ -18,8 +18,45 @@ use SrcCore\models\ValidatorModel; use SrcCore\models\DatabaseModel; -abstract class DocumentModel +class DocumentModel { + public static function get(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['select']); + ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); + ValidatorModel::intType($aArgs, ['limit', 'offset']); + + $aDocuments = DatabaseModel::select([ + 'select' => $aArgs['select'], + 'table' => ['main_documents'], + 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], + 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], + 'offset' => empty($aArgs['offset']) ? 0 : $aArgs['offset'], + 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] + ]); + + return $aDocuments; + } + + public static function getById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['select', 'id']); + ValidatorModel::arrayType($aArgs, ['select']); + + $document = DatabaseModel::select([ + 'select' => $aArgs['select'], + 'table' => ['main_documents'], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + if (empty($document[0])) { + return []; + } + + return $document[0]; + } + public static function getByUserId(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['select', 'userId']); @@ -38,4 +75,18 @@ abstract class DocumentModel return $aDocuments; } + + public static function delete(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['where', 'data']); + ValidatorModel::arrayType($aArgs, ['where', 'data']); + + DatabaseModel::delete([ + 'table' => 'main_documents', + 'where' => $aArgs['where'], + 'data' => $aArgs['data'] + ]); + + return true; + } } diff --git a/src/app/status/controllers/StatusController.php b/src/app/status/controllers/StatusController.php deleted file mode 100755 index c5408997b634a127fbbe4e2b4f7d7423f2472155..0000000000000000000000000000000000000000 --- a/src/app/status/controllers/StatusController.php +++ /dev/null @@ -1,257 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Status Controller -* @author dev@maarch.org -*/ - -namespace Status\controllers; - -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Status\models\StatusModel; -use Status\models\StatusImagesModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class StatusController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['statuses' => StatusModel::get()]); - } - - public function getNewInformations(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson([ - 'statusImages' => StatusImagesModel::getStatusImages() - ]); - } - - public function getByIdentifier(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!empty($aArgs['identifier']) && Validator::numeric()->validate($aArgs['identifier'])) { - $obj = StatusModel::getByIdentifier(['identifier' => $aArgs['identifier']]); - - if (empty($obj)) { - return $response->withStatus(404)->withJson(['errors' => 'identifier not found']); - } - - return $response->withJson([ - 'status' => $obj, - 'statusImages' => StatusImagesModel::getStatusImages(), - ]); - } else { - return $response->withStatus(500)->withJson(['errors' => 'identifier not valid']); - } - } - - public function getById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $status = StatusModel::getById(['id' => $aArgs['id']]); - if (empty($status)) { - return $response->withStatus(404)->withJson(['errors' => 'id not found']); - } - - return $response->withJson(['status' => $status]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $request = $request->getParams(); - $aArgs = StatusController::manageValue($request); - $errors = $this->control($aArgs, 'create'); - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - StatusModel::create($aArgs); - - $return['status'] = StatusModel::getById(['id' => $aArgs['id']])[0]; - - HistoryController::add([ - 'tableName' => 'status', - 'recordId' => $return['status']['id'], - 'eventType' => 'ADD', - 'eventId' => 'statusup', - 'info' => _STATUS_ADDED . ' : ' . $return['status']['id'] - ]); - - return $response->withJson($return); - } - - public function update(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $request = $request->getParams(); - $request = array_merge($request, $aArgs); - - $aArgs = StatusController::manageValue($request); - $errors = $this->control($aArgs, 'update'); - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - StatusModel::update($aArgs); - - $return['status'] = StatusModel::getByIdentifier(['identifier' => $aArgs['identifier']])[0]; - - HistoryController::add([ - 'tableName' => 'status', - 'recordId' => $return['status']['id'], - 'eventType' => 'UP', - 'eventId' => 'statusup', - 'info' => _MODIFY_STATUS . ' : ' . $return['status']['id'] - ]); - - return $response->withJson($return); - } - - public function delete(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $statusDeleted = StatusModel::getByIdentifier(['identifier' => $aArgs['identifier']]); - - if (Validator::notEmpty()->validate($aArgs['identifier']) && Validator::numeric()->validate($aArgs['identifier']) && !empty($statusDeleted)) { - StatusModel::delete(['identifier' => $aArgs['identifier']]); - - HistoryController::add([ - 'tableName' => 'status', - 'recordId' => $statusDeleted[0]['id'], - 'eventType' => 'DEL', - 'eventId' => 'statusdel', - 'info' => _STATUS_DELETED . ' : ' . $statusDeleted[0]['id'] - ]); - } else { - return $response->withStatus(500)->withJson(['errors' => 'identifier not valid']); - } - - return $response->withJson(['statuses' => StatusModel::get()]); - } - - protected static function manageValue($request) - { - foreach ($request as $key => $value) { - if (in_array($key, ['is_system', 'can_be_searched', 'can_be_modified'])) { - if (empty($value)) { - $request[$key] = 'N'; - } else { - $request[$key] = 'Y'; - } - } - } - - $request['is_system'] = 'N'; - - return $request; - } - - protected function control($request, $mode) - { - $errors = []; - - if (!Validator::notEmpty()->validate($request['id'])) { - array_push($errors, _ID . ' ' . _EMPTY); - } elseif ($mode == 'create') { - $obj = StatusModel::getById(['id' => $request['id']]); - - if (!empty($obj)) { - array_push( - $errors, - _ID . ' ' . $obj[0]['id'] . ' ' . _ALREADY_EXISTS - ); - } - } elseif ($mode == 'update') { - $obj = StatusModel::getByIdentifier(['identifier' => $request['identifier']]); - - if (empty($obj)) { - array_push( - $errors, - $request['identifier'] . ' ' . _NOT_EXISTS - ); - } - } - - if (!Validator::regex('/^[\w.-]*$/')->validate($request['id']) || - !Validator::length(1, 10)->validate($request['id']) || - !Validator::notEmpty()->validate($request['id'])) { - array_push($errors, 'Invalid id value'); - } - - if (!Validator::notEmpty()->validate($request['label_status']) || - !Validator::length(1, 50)->validate($request['label_status'])) { - array_push($errors, 'Invalid label_status value'); - } - - if (Validator::notEmpty()->validate($request['is_system']) && - !Validator::contains('Y')->validate($request['is_system']) && - !Validator::contains('N')->validate($request['is_system']) - ) { - array_push($errors, 'Invalid is_system value'); - } - - if (!Validator::notEmpty()->validate($request['img_filename']) || - !Validator::length(1, 255)->validate($request['img_filename']) - ) { - array_push($errors, 'Invalid img_filename value'); - } - - if (Validator::notEmpty()->validate($request['maarch_module']) && - !Validator::length(null, 255)->validate($request['maarch_module']) - ) { - array_push($errors, 'Invalid maarch_module value'); - } - - if (Validator::notEmpty()->validate($request['can_be_searched']) && - !Validator::contains('Y')->validate($request['can_be_searched']) && - !Validator::contains('N')->validate($request['can_be_searched']) - ) { - array_push($errors, 'Invalid can_be_searched value'); - } - - if (Validator::notEmpty()->validate($request['can_be_modified']) && - !Validator::contains('Y')->validate($request['can_be_modified']) && - !Validator::contains('N')->validate($request['can_be_modified']) - ) { - array_push($errors, 'Invalid can_be_modified value'); - } - - return $errors; - } -} diff --git a/src/app/status/models/StatusImagesModel.php b/src/app/status/models/StatusImagesModel.php deleted file mode 100644 index 1843c9a7d8207d795c958582ec6d335db8e56dc8..0000000000000000000000000000000000000000 --- a/src/app/status/models/StatusImagesModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Status Images Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Status\models; - -class StatusImagesModel extends StatusImagesModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/status/models/StatusImagesModelAbstract.php b/src/app/status/models/StatusImagesModelAbstract.php deleted file mode 100644 index cdd1a2771aa5f9cffb1c10c0d50081a41f25dca0..0000000000000000000000000000000000000000 --- a/src/app/status/models/StatusImagesModelAbstract.php +++ /dev/null @@ -1,34 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Status Images Model -* @author dev@maarch.org -*/ - -namespace Status\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class StatusImagesModelAbstract -{ - public static function getStatusImages(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['status_images'], - 'order_by' => ['id'] - ]); - - return $aReturn; - } -} diff --git a/src/app/status/models/StatusModel.php b/src/app/status/models/StatusModel.php index e6a539de57361351a90705d269fdb82d0cb49caa..9f5f15f95bacc4e6eae62a25788296ebedc8fe1e 100644 --- a/src/app/status/models/StatusModel.php +++ b/src/app/status/models/StatusModel.php @@ -10,12 +10,32 @@ /** * @brief Status Model * @author dev@maarch.org -* @ingroup core */ namespace Status\models; -class StatusModel extends StatusModelAbstract +use SrcCore\models\DatabaseModel; +use SrcCore\models\ValidatorModel; + +class StatusModel { - // Do your stuff in this class + public static function getById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intType($aArgs, ['id']); + ValidatorModel::arrayType($aArgs, ['select']); + + $status = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['status'], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + if (empty($status[0])) { + return []; + } + + return $status[0]; + } } diff --git a/src/app/status/models/StatusModelAbstract.php b/src/app/status/models/StatusModelAbstract.php deleted file mode 100755 index 89cfc8d4c8c27dded9101b5b5666ccd3863275ce..0000000000000000000000000000000000000000 --- a/src/app/status/models/StatusModelAbstract.php +++ /dev/null @@ -1,110 +0,0 @@ -<?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. -* -*/ - -/** -* @brief Status Model -* @author dev@maarch.org -*/ - -namespace Status\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class StatusModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['status'], - 'order_by' => ['label_status'] - ]); - - return $aReturn; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['status'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aReturn; - } - - public static function getByIdentifier(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['identifier']); - ValidatorModel::intVal($aArgs, ['identifier']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['status'], - 'where' => ['identifier = ?'], - 'data' => [$aArgs['identifier']] - ]); - - return $aReturn; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'label_status']); - ValidatorModel::stringType($aArgs, ['id', 'label_status']); - - DatabaseModel::insert([ - 'table' => 'status', - 'columnsValues' => $aArgs - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['label_status', 'identifier']); - ValidatorModel::intVal($aArgs, ['identifier']); - - $where['identifier'] = $aArgs['identifier']; - unset($aArgs['id']); - unset($aArgs['identifier']); - - DatabaseModel::update([ - 'table' => 'status', - 'set' => $aArgs, - 'where' => ['identifier = ?'], - 'data' => [$where['identifier']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['identifier']); - ValidatorModel::intVal($aArgs, ['identifier']); - - DatabaseModel::delete([ - 'table' => 'status', - 'where' => ['identifier = ?'], - 'data' => [$aArgs['identifier']] - ]); - - return true; - } -} diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index bc33d7d6990550299fead34492645ba5c14b62ec..8d04d19a5605895edeff62264c6331a7afbaa621 100644 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -75,34 +75,15 @@ abstract class UserModelAbstract return $aUser[0]; } - public static function getByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aUser = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users'], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - if (empty($aUser)) { - return []; - } - - return $aUser[0]; - } - public static function getLabelledUserById(array $aArgs) { ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['login']); if (!empty($aArgs['id'])) { $rawUser = UserModel::getById(['id' => $aArgs['id'], 'select' => ['firstname', 'lastname']]); - } elseif (!empty($aArgs['userId'])) { - $rawUser = UserModel::getByUserId(['userId' => $aArgs['userId'], 'select' => ['firstname', 'lastname']]); + } elseif (!empty($aArgs['login'])) { + $rawUser = UserModel::getByLogin(['login' => $aArgs['login'], 'select' => ['firstname', 'lastname']]); } $labelledUser = ''; diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index c924d450c2d7c6ee6b4885dd3dcabb0eb5b638e4..809d1bd7f9c0e4190b58b5be43bfcc7abd4acf0c 100644 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -22,7 +22,7 @@ class AuthenticationController { $login = null; if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { - if (AuthenticationModel::authentication(['userId' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']])) { + if (AuthenticationModel::authentication(['login' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']])) { $login = $_SERVER['PHP_AUTH_USER']; } } else { diff --git a/src/core/models/AuthenticationModel.php b/src/core/models/AuthenticationModel.php index 0318103b1afbd6bc182129dc6c2d247ccaa37197..eb5f280d6da59a04f5fe5f7fa393062e93156838 100644 --- a/src/core/models/AuthenticationModel.php +++ b/src/core/models/AuthenticationModel.php @@ -23,14 +23,14 @@ class AuthenticationModel public static function authentication(array $args) { - ValidatorModel::notEmpty($args, ['userId', 'password']); - ValidatorModel::stringType($args, ['userId', 'password']); + ValidatorModel::notEmpty($args, ['login', 'password']); + ValidatorModel::stringType($args, ['login', 'password']); $aReturn = DatabaseModel::select([ 'select' => ['password'], 'table' => ['users'], - 'where' => ['user_id = ?', 'status != ?'], - 'data' => [$args['userId'], 'DEL'] + 'where' => ['login = ?', 'status != ?'], + 'data' => [$args['login'], 'DEL'] ]); if (empty($aReturn[0])) { diff --git a/test/unitTests/app/action/ActionControllerTest.php b/test/unitTests/app/action/ActionControllerTest.php deleted file mode 100644 index ffb06c534275f1ec2a9c3a72f90bf2d3f03597b2..0000000000000000000000000000000000000000 --- a/test/unitTests/app/action/ActionControllerTest.php +++ /dev/null @@ -1,191 +0,0 @@ -<?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. - -* @brief ActionsControllerTest -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -use PHPUnit\Framework\TestCase; - -class ActionsControllerTest extends TestCase -{ - - private static $id = null; - - public function testCreate() - { - $actionController = new \Action\controllers\ActionController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'keyword' => 'indexing', - 'label_action' => 'TEST-LABEL', - 'id_status' => '_NOSTATUS_', - 'action_page' => 'index_mlb', - 'history' => true, - 'origin' => 'apps', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $actionController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->actionId; - - $this->assertInternalType('int', self::$id); - - // FAIL CREATE - $aArgs = [ - 'keyword' => 'indexing', - 'label_action' => '', - 'id_status' => '', - 'action_page' => 'index_mlb', - 'history' => true, - 'origin' => 'apps', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $actionController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Invalid Status', $responseBody->errors[0]); - $this->assertSame('Invalid label action', $responseBody->errors[1]); - $this->assertSame('id_status is empty', $responseBody->errors[2]); - - } - - public function testRead(){ - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', self::$id); - $this->assertSame(self::$id, $responseBody->action->id); - $this->assertSame('indexing', $responseBody->action->keyword); - $this->assertSame('TEST-LABEL', $responseBody->action->label_action); - $this->assertSame('_NOSTATUS_', $responseBody->action->id_status); - $this->assertSame(false, $responseBody->action->is_system); - $this->assertSame('Y', $responseBody->action->enabled); - $this->assertSame('index_mlb', $responseBody->action->action_page); - $this->assertSame(true, $responseBody->action->history); - $this->assertSame('apps', $responseBody->action->origin); - $this->assertSame(false, $responseBody->action->create_id); - - // FAIL READ - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame('Id is not a numeric', $responseBody->errors); - - } - - public function testReadList(){ - // READ LIST - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->actions); - } - - public function testUpdate() - { - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'keyword' => '', - 'label_action' => 'TEST-LABEL_UPDATED', - 'id_status' => 'COU', - 'action_page' => 'process', - 'history' => false, - 'origin' => 'apps', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // UPDATE FAIL - $aArgs = [ - 'keyword' => '', - 'label_action' => 'TEST-LABEL_UPDATED', - 'id_status' => 'COU', - 'action_page' => 'process', - 'history' => false, - 'origin' => 'apps', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame('Id is not a numeric', $responseBody->errors[0]); - - } - - public function testDelete() - { - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->actions); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNull($responseBody->actions[0]); - - // FAIL DELETE - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->delete($request, new \Slim\Http\Response(), ['id' => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors); - - } - - public function testGetInitAction() - { - // InitAction - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $actionController = new \Action\controllers\ActionController(); - $response = $actionController->initAction($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->action); - $this->assertNotNull($responseBody->categoriesList); - $this->assertNotNull($responseBody->statuses); - $this->assertNotNull($responseBody->action_pagesList); - $this->assertNotNull($responseBody->keywordsList); - - } - -} diff --git a/test/unitTests/app/basket/BasketControllerTest.php b/test/unitTests/app/basket/BasketControllerTest.php deleted file mode 100644 index 9ca761bad70a1224adfb9e9f63b76911a431b91c..0000000000000000000000000000000000000000 --- a/test/unitTests/app/basket/BasketControllerTest.php +++ /dev/null @@ -1,403 +0,0 @@ -<?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 BasketControllerTest extends TestCase -{ - private static $id = null; - private static $baskets = null; - - public function testCreate() - { - $basketController = new \Basket\controllers\BasketController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'id' => 'TEST-BASKET123', - 'basket_name' => 'TEST-BASKET123-NAME', - 'basket_desc' => 'TEST BASKET123 DESCRIPTION', - 'clause' => '1=2', - 'isSearchBasket' => true, - 'color' => '#123456' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-BASKET123', $responseBody->basket); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-BASKET123', $responseBody->basket->basket_id); - $this->assertSame('TEST-BASKET123-NAME', $responseBody->basket->basket_name); - $this->assertSame('TEST BASKET123 DESCRIPTION', $responseBody->basket->basket_desc); - $this->assertSame('1=2', $responseBody->basket->basket_clause); - $this->assertSame('N', $responseBody->basket->is_visible); - $this->assertSame('N', $responseBody->basket->flag_notif); - $this->assertSame('#123456', $responseBody->basket->color); - } - - public function testUpdate() - { - $basketController = new \Basket\controllers\BasketController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'basket_name' => 'TEST-BASKET123-UPDATED', - 'basket_desc' => 'TEST BASKET123 DESCRIPTION UPDATED', - 'clause' => '1=3', - 'isSearchBasket' => false, - 'flagNotif' => true, - 'color' => '#111222' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-BASKET123', $responseBody->basket->basket_id); - $this->assertSame('TEST-BASKET123-UPDATED', $responseBody->basket->basket_name); - $this->assertSame('TEST BASKET123 DESCRIPTION UPDATED', $responseBody->basket->basket_desc); - $this->assertSame('1=3', $responseBody->basket->basket_clause); - $this->assertSame('Y', $responseBody->basket->is_visible); - $this->assertSame('Y', $responseBody->basket->flag_notif); - $this->assertSame('#111222', $responseBody->basket->color); - } - - public function testCreateGroup() - { - $basketController = new \Basket\controllers\BasketController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'group_id' => 'AGENT', - 'result_page' => 'redirect_to_action', - 'groupActions' => [ - [ - 'id' => '112', - 'where_clause' => '1=2', - 'used_in_basketlist' => false, - 'used_in_action_page' => true, - 'default_action_list' => true, - 'checked' => true, - 'statuses' => [ - 'NEW', - 'END' - ], - 'redirects' => [ - [ - 'entity_id' => '', - 'keyword' => 'MY_ENTITIES', - 'redirect_mode' => 'ENTITY' - ] - ] - ] - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->createGroup($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getGroups($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('AGENT', $responseBody->groups[0]->group_id); - $this->assertSame('TEST-BASKET123', $responseBody->groups[0]->basket_id); - $this->assertSame('redirect_to_action', $responseBody->groups[0]->result_page); - $this->assertInternalType('array', $responseBody->groups[0]->groupActions); - $this->assertNotNull($responseBody->groups[0]->groupActions); - foreach ($responseBody->groups[0]->groupActions as $groupAction) { - if ($groupAction->id == 112) { - $this->assertSame(112, $groupAction->id); - $this->assertSame('1=2', $groupAction->where_clause); - $this->assertSame('N', $groupAction->used_in_basketlist); - $this->assertSame('Y', $groupAction->used_in_action_page); - $this->assertSame('Y', $groupAction->default_action_list); - $this->assertInternalType('array', $groupAction->statuses); - $this->assertNotNull($groupAction->statuses); - $this->assertSame('NEW', $groupAction->statuses[0]); - $this->assertSame('END', $groupAction->statuses[1]); - $this->assertInternalType('array', $groupAction->redirects); - $this->assertNotNull($groupAction->redirects); - $this->assertSame('', $groupAction->redirects[0]->entity_id); - $this->assertSame('MY_ENTITIES', $groupAction->redirects[0]->keyword); - $this->assertSame('ENTITY', $groupAction->redirects[0]->redirect_mode); - } - } - - $this->assertInternalType('array', $responseBody->allGroups); - $this->assertNotNull($responseBody->allGroups); - $this->assertInternalType('array', $responseBody->pages); - $this->assertNotNull($responseBody->pages); - - $users = \Group\models\GroupModel::getUsersByGroupId(['select' => ['id'], 'groupId' => 'AGENT']); - $group = \Group\models\GroupModel::getByGroupId(['select' => ['id'], 'groupId' => 'AGENT']); - foreach ($users as $user) { - $preference = \User\models\UserBasketPreferenceModel::get([ - 'select' => ['display'], - 'where' => ['user_serial_id = ?', 'group_serial_id = ?', 'basket_id = ?'], - 'data' => [$user['id'], $group['id'], 'TEST-BASKET123'] - ]); - $this->assertNotNull($preference[0]); - $this->assertSame(true, $preference[0]['display']); - } - } - - public function testUpdateGroup() - { - $basketController = new \Basket\controllers\BasketController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'result_page' => 'list_with_attachments', - 'groupActions' => [ - [ - 'id' => '1', - 'where_clause' => '1=1', - 'used_in_basketlist' => true, - 'used_in_action_page' => true, - 'default_action_list' => true, - 'checked' => true, - 'statuses' => [ - 'END', - ], - 'redirects' => [ - [ - 'entity_id' => '', - 'keyword' => 'ALL_ENTITIES', - 'redirect_mode' => 'ENTITY' - ] - ] - ], - [ - 'id' => '4', - 'where_clause' => '1=4', - 'used_in_basketlist' => false, - 'used_in_action_page' => true, - 'default_action_list' => false, - 'checked' => true, - 'statuses' => [ - 'NEW', - 'COU' - ], - 'redirects' => [ - [ - 'entity_id' => 'PSO', - 'keyword' => '', - 'redirect_mode' => 'ENTITY' - ], - [ - 'entity_id' => 'PSF', - 'keyword' => '', - 'redirect_mode' => 'USERS' - ] - ] - ] - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->updateGroup($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123', 'groupId' => 'AGENT']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getGroups($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('AGENT', $responseBody->groups[0]->group_id); - $this->assertSame('TEST-BASKET123', $responseBody->groups[0]->basket_id); - $this->assertSame('list_with_attachments', $responseBody->groups[0]->result_page); - $this->assertInternalType('array', $responseBody->groups[0]->groupActions); - $this->assertNotNull($responseBody->groups[0]->groupActions); - - foreach ($responseBody->groups[0]->groupActions as $groupAction) { - if ($groupAction->id == 1) { - $this->assertSame(1, $groupAction->id); - $this->assertSame('1=1', $groupAction->where_clause); - $this->assertSame('Y', $groupAction->used_in_basketlist); - $this->assertSame('Y', $groupAction->used_in_action_page); - $this->assertSame('Y', $groupAction->default_action_list); - $this->assertInternalType('array', $groupAction->statuses); - $this->assertNotNull($groupAction->statuses); - $this->assertSame('END', $groupAction->statuses[0]); - $this->assertInternalType('array', $groupAction->redirects); - $this->assertNotNull($groupAction->redirects); - $this->assertSame('', $groupAction->redirects[0]->entity_id); - $this->assertSame('ALL_ENTITIES', $groupAction->redirects[0]->keyword); - $this->assertSame('ENTITY', $groupAction->redirects[0]->redirect_mode); - } elseif ($groupAction->id == 4) { - $this->assertSame(4, $groupAction->id); - $this->assertSame('1=4', $groupAction->where_clause); - $this->assertSame('N', $groupAction->used_in_basketlist); - $this->assertSame('Y', $groupAction->used_in_action_page); - $this->assertSame('N', $groupAction->default_action_list); - $this->assertInternalType('array', $groupAction->statuses); - $this->assertNotNull($groupAction->statuses); - $this->assertSame('NEW', $groupAction->statuses[0]); - $this->assertSame('COU', $groupAction->statuses[1]); - $this->assertInternalType('array', $groupAction->redirects); - $this->assertNotNull($groupAction->redirects); - $this->assertSame('PSO', $groupAction->redirects[0]->entity_id); - $this->assertSame('', $groupAction->redirects[0]->keyword); - $this->assertSame('ENTITY', $groupAction->redirects[0]->redirect_mode); - $this->assertSame('PSF', $groupAction->redirects[1]->entity_id); - $this->assertSame('', $groupAction->redirects[1]->keyword); - $this->assertSame('USERS', $groupAction->redirects[1]->redirect_mode); - } - } - } - - public function testDeleteGroup() - { - $basketController = new \Basket\controllers\BasketController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->deleteGroup($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123', 'groupId' => 'AGENT']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getGroups($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertEmpty($responseBody->groups); - } - - public function testGet() - { - $basketController = new \Basket\controllers\BasketController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->baskets); - $this->assertNotNull($responseBody->baskets); - } - - public function testDelete() - { - $basketController = new \Basket\controllers\BasketController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->delete($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->baskets); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Basket not found', $responseBody->errors); - } - - public function testGetSorted() - { - $basketController = new \Basket\controllers\BasketController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $basketController->getSorted($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->baskets); - - self::$id = $responseBody->baskets[0]->basket_id; - self::$baskets = $responseBody->baskets; - } - - public function testUpdateSort() - { - $basketController = new \Basket\controllers\BasketController(); - - // PUT - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - // DOWN - $firstBasket = self::$baskets[0]; - self::$baskets[0] = self::$baskets[1]; - self::$baskets[1] = $firstBasket; - - $aArgs = self::$baskets; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->updateSort($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->baskets); - $this->assertSame(self::$id, $responseBody->baskets[1]->basket_id); - - // UP - self::$baskets = $responseBody->baskets; - - $firstBasket = self::$baskets[0]; - self::$baskets[0] = self::$baskets[1]; - self::$baskets[1] = $firstBasket; - - $aArgs = self::$baskets; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $basketController->updateSort($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->baskets); - $this->assertSame(self::$id, $responseBody->baskets[0]->basket_id); - } -} diff --git a/test/unitTests/app/contact/ContactControllerTest.php b/test/unitTests/app/contact/ContactControllerTest.php deleted file mode 100644 index dcd54fc3bad5a3fb686f04f9cbcedf0e98f8e848..0000000000000000000000000000000000000000 --- a/test/unitTests/app/contact/ContactControllerTest.php +++ /dev/null @@ -1,375 +0,0 @@ -<?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 ContactControllerTest extends TestCase -{ - private static $id = null; - private static $addressId = null; - - public function testCreate() - { - $contactController = new \Contact\controllers\ContactController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'firstname' => 'Hal', - 'lastname' => 'Jordan', - 'contactType' => '106', - 'contactPurposeId' => '3', - 'isCorporatePerson' => 'N', - 'email' => 'hal.jordan@glc.com', - 'society' => 'Green Lantern Corps', - 'societyShort' => 'GLC', - 'title' => 'title1', - 'function' => 'member', - 'addressNum' => '1', - 'addressStreet' => 'somewhere', - 'addressCountry' => 'OA', - 'phone' => '911', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->contactId); - $this->assertInternalType('int', $responseBody->addressId); - - self::$id = $responseBody->contactId; - self::$addressId = $responseBody->addressId; - - - // READ - $contact = \Contact\models\ContactModel::getById(['id' => self::$id]); - - $this->assertInternalType('array', $contact); - $this->assertSame(self::$id, $contact['contact_id']); - $this->assertSame(106, $contact['contact_type']); - $this->assertSame('Green Lantern Corps', $contact['society']); - $this->assertSame('GLC', $contact['society_short']); - $this->assertSame('Hal', $contact['firstname']); - $this->assertSame('Jordan', $contact['lastname']); - $this->assertSame('title1', $contact['title']); - $this->assertSame('member', $contact['function']); - $this->assertSame('superadmin', $contact['user_id']); - $this->assertSame('SUPERADMIN', $contact['entity_id']); - $this->assertSame('Y', $contact['enabled']); - - $contact = \Contact\models\ContactModel::getByAddressId(['addressId' => self::$addressId]); - - $this->assertInternalType('array', $contact); - $this->assertSame(self::$addressId, $contact['id']); - $this->assertSame(self::$id, $contact['contact_id']); - $this->assertSame(3, $contact['contact_purpose_id']); - $this->assertSame(null, $contact['firstname']); - $this->assertSame(null, $contact['lastname']); - $this->assertSame('hal.jordan@glc.com', $contact['email']); - $this->assertSame('1', $contact['address_num']); - $this->assertSame(null, $contact['address_town']); - $this->assertSame('somewhere', $contact['address_street']); - $this->assertSame('OA', $contact['address_country']); - $this->assertSame('911', $contact['phone']); - $this->assertSame('superadmin', $contact['user_id']); - $this->assertSame('SUPERADMIN', $contact['entity_id']); - $this->assertSame('Y', $contact['enabled']); - } - - public function testCreateAddress() - { - $contactController = new \Contact\controllers\ContactController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - "contactPurposeId" => 2, - "email" => "office@group.com", - "phone" => "+33120212223", - "addressNum" => "14", - "addressStreet" => "Avenue du Pérou", - "addressZip" => "75016", - "addressTown" => "Paris", - "addressCountry" => "France" - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->createAddress($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->addressId); - - $contact = \Contact\models\ContactModel::getByAddressId(['addressId' => $responseBody->addressId]); - - $this->assertInternalType('array', $contact); - $this->assertSame($responseBody->addressId, $contact['id']); - $this->assertSame(self::$id, $contact['contact_id']); - $this->assertSame(2, $contact['contact_purpose_id']); - $this->assertSame(null, $contact['firstname']); - $this->assertSame(null, $contact['lastname']); - $this->assertSame('office@group.com', $contact['email']); - $this->assertSame('14', $contact['address_num']); - $this->assertSame('Avenue du Pérou', $contact['address_street']); - $this->assertSame('75016', $contact['address_postal_code']); - $this->assertSame('Paris', $contact['address_town']); - $this->assertSame('France', $contact['address_country']); - $this->assertSame('+33120212223', $contact['phone']); - $this->assertSame('superadmin', $contact['user_id']); - $this->assertSame('SUPERADMIN', $contact['entity_id']); - $this->assertSame('Y', $contact['enabled']); - - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'contact_addresses', - 'where' => ['id = ?'], - 'data' => [$responseBody->addressId] - ]); - - // READ - $contact = \Contact\models\ContactModel::getByAddressId(['addressId' => $responseBody->addressId]); - $this->assertInternalType('array', $contact); - $this->assertEmpty($contact); - - $aArgs = [ - "contactPurposeId" => 2 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->createAddress($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } - - public function testUpdate() - { - $contactController = new \Contact\controllers\ContactController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'firstname' => 'Guy', - 'lastname' => 'Gardner', - 'title' => 'title2', - 'function' => '2nd member', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $contact = \Contact\models\ContactModel::getById(['id' => self::$id]); - - $this->assertInternalType('array', $contact); - $this->assertSame(self::$id, $contact['contact_id']); - $this->assertSame(106, $contact['contact_type']); - $this->assertSame('Green Lantern Corps', $contact['society']); - $this->assertSame('GLC', $contact['society_short']); - $this->assertSame('Guy', $contact['firstname']); - $this->assertSame('Gardner', $contact['lastname']); - $this->assertSame('title2', $contact['title']); - $this->assertSame('2nd member', $contact['function']); - $this->assertSame('superadmin', $contact['user_id']); - $this->assertSame('SUPERADMIN', $contact['entity_id']); - $this->assertSame('Y', $contact['enabled']); - - $aArgs = [ - 'firstname' => 'Guy', - 'lastname' => 'Gardner', - 'title' => 'title2', - 'function' => '2nd member', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->update($fullRequest, new \Slim\Http\Response(), ['id' => -1]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Contact does not exist', $responseBody->errors); - } - - public function testUpdateAddress() - { - $contactController = new \Contact\controllers\ContactController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - "contact_purpose_id" => 2, - "email" => "updatedemail@mail.com", - "phone" => "+66", - "address_num" => "23", - "address_street" => "Rue des GL", - "address_postal_code" => "75000", - "address_town" => "Paris", - "address_country" => "France" - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->updateAddress($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'addressId' => self::$addressId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $contact = \Contact\models\ContactModel::getByAddressId(['addressId' => self::$addressId]); - - $this->assertInternalType('array', $contact); - $this->assertSame(self::$addressId, $contact['id']); - $this->assertSame(self::$id, $contact['contact_id']); - $this->assertSame(2, $contact['contact_purpose_id']); - $this->assertSame(null, $contact['firstname']); - $this->assertSame(null, $contact['lastname']); - $this->assertSame('updatedemail@mail.com', $contact['email']); - $this->assertSame('23', $contact['address_num']); - $this->assertSame('Rue des GL', $contact['address_street']); - $this->assertSame('75000', $contact['address_postal_code']); - $this->assertSame('Paris', $contact['address_town']); - $this->assertSame('France', $contact['address_country']); - $this->assertSame('+66', $contact['phone']); - $this->assertSame('superadmin', $contact['user_id']); - $this->assertSame('SUPERADMIN', $contact['entity_id']); - $this->assertSame('Y', $contact['enabled']); - - - $aArgs = [ - "contact_purpose_id" => 2, - "email" => "updatedemail@mail.com", - "phone" => "+66", - "address_num" => "23", - "address_street" => "Rue des GL", - "address_postal_code" => "75000", - "address_town" => "Paris", - "address_country" => "France" - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->updateAddress($fullRequest, new \Slim\Http\Response(), ['id' => -1, 'addressId' => self::$addressId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Contact or address do not exist', $responseBody->errors); - } - - public function testGetContactCommunicationByContactId() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $contactController = new \Contact\controllers\ContactController(); - $response = $contactController->getCommunicationByContactId($request, new \Slim\Http\Response(), ['contactId' => (string)self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - } - - public function testDelete() - { - // DELETE - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'contacts_v2', - 'where' => ['contact_id = ?'], - 'data' => [self::$id] - ]); - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'contact_addresses', - 'where' => ['id = ?'], - 'data' => [self::$addressId] - ]); - - // READ - $contact = \Contact\models\ContactModel::getById(['id' => self::$id]); - $this->assertInternalType('array', $contact); - $this->assertEmpty($contact); - - $contact = \Contact\models\ContactModel::getByAddressId(['addressId' => self::$addressId]); - $this->assertInternalType('array', $contact); - $this->assertEmpty($contact); - } - - public function testControlLengthNameAfnor() - { - $name = \Contact\controllers\ContactController::controlLengthNameAfnor(['title' => 'title1', 'fullName' => 'Prénom NOM', 'strMaxLength' => 38]); - - $this->assertSame('Monsieur Prénom NOM', $name); - - $name = \Contact\controllers\ContactController::controlLengthNameAfnor(['title' => 'title3', 'fullName' => 'Prénom NOM TROP LOOOOOOOOOOOOONG', 'strMaxLength' => 38]); - - $this->assertSame('Mlle Prénom NOM TROP LOOOOOOOOOOOOONG', $name); - } - - public function testAvailableReferential() - { - $contactController = new \Contact\controllers\ContactController(); - $availableReferential = $contactController->availableReferential(); - $this->assertInternalType('array', $availableReferential); - $this->assertNotEmpty($availableReferential); - } - - public function testGetFilling() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $contactController = new \Contact\controllers\ContactController(); - $response = $contactController->getFilling($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', (array)$responseBody->contactsFilling); - } - - public function testUpdateFilling() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - "enable" => true, - "rating_columns" => ["society", "function"], - "first_threshold" => 22, - "second_threshold" => 85 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $contactController = new \Contact\controllers\ContactController(); - $response = $contactController->updateFilling($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $response = $contactController->getFilling($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(true, $responseBody->contactsFilling->enable); - $this->assertSame(22, $responseBody->contactsFilling->first_threshold); - $this->assertSame(85, $responseBody->contactsFilling->second_threshold); - $this->assertSame('society', $responseBody->contactsFilling->rating_columns[0]); - $this->assertSame('function', $responseBody->contactsFilling->rating_columns[1]); - - $aArgs = [ - "enable" => true, - "first_threshold" => 22, - "second_threshold" => 85 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactController->updateFilling($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } -} diff --git a/test/unitTests/app/contact/ContactGroupControllerTest.php b/test/unitTests/app/contact/ContactGroupControllerTest.php deleted file mode 100644 index 717e4d60359385431e0ffc39a69d55f145fc4349..0000000000000000000000000000000000000000 --- a/test/unitTests/app/contact/ContactGroupControllerTest.php +++ /dev/null @@ -1,192 +0,0 @@ -<?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 ContactGroupControllerTest extends TestCase -{ - private static $id = null; - - - public function testCreate() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'label' => 'Groupe petition', - 'description' => 'Groupe de petition', - 'public' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactGroupController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->contactsGroup; - - $this->assertInternalType('int', self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $user = \User\models\UserModel::getByUserId(['select' => ['id'], 'userId' => 'superadmin']); - $this->assertSame(self::$id, $responseBody->contactsGroup->id); - $this->assertSame('Groupe petition', $responseBody->contactsGroup->label); - $this->assertSame('Groupe de petition', $responseBody->contactsGroup->description); - $this->assertSame(true, $responseBody->contactsGroup->public); - $this->assertSame($user['id'], $responseBody->contactsGroup->owner); - $this->assertSame('superadmin', $responseBody->contactsGroup->entity_owner); - $this->assertInternalType('string', $responseBody->contactsGroup->labelledOwner); - $this->assertInternalType('array', $responseBody->contactsGroup->contacts); - } - - public function testGet() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->contactsGroups); - $this->assertNotNull($responseBody->contactsGroups); - } - - public function testUpdate() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'label' => 'Groupe petition updated', - 'description' => 'Groupe de petition updated', - 'public' => false - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactGroupController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->contactsGroup->id); - $this->assertSame('Groupe petition updated', $responseBody->contactsGroup->label); - $this->assertSame('Groupe de petition updated', $responseBody->contactsGroup->description); - $this->assertSame(false, $responseBody->contactsGroup->public); - $this->assertSame('superadmin', $responseBody->contactsGroup->entity_owner); - $this->assertInternalType('string', $responseBody->contactsGroup->labelledOwner); - $this->assertInternalType('array', $responseBody->contactsGroup->contacts); - } - - public function testAddContacts() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - $contacts = \Contact\models\ContactModel::getOnView([ - 'select' => ['ca_id'], - 'limit' => 1 - ]); - - if (!empty($contacts[0])) { - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'contacts' => [$contacts[0]['ca_id']] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $contactGroupController->addContacts($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->contactsGroup->id); - $this->assertNotEmpty($responseBody->contactsGroup); - $this->assertNotEmpty($responseBody->contactsGroup->contacts); - $this->assertSame($contacts[0]['ca_id'], $responseBody->contactsGroup->contacts[0]->addressId); - $this->assertSame(0, $responseBody->contactsGroup->contacts[0]->position); - $this->assertInternalType('string', $responseBody->contactsGroup->contacts[0]->contact); - $this->assertInternalType('string', $responseBody->contactsGroup->contacts[0]->address); - } - } - - public function testDeleteContacts() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - $contacts = \Contact\models\ContactModel::getOnView([ - 'select' => ['ca_id'], - 'limit' => 1 - ]); - - if (!empty($contacts[0])) { - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $contactGroupController->deleteContact($request, new \Slim\Http\Response(), ['id' => self::$id, 'addressId' => $contacts[0]['ca_id']]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - } - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $user = \User\models\UserModel::getByUserId(['select' => ['id'], 'userId' => 'superadmin']); - $this->assertSame(self::$id, $responseBody->contactsGroup->id); - $this->assertSame($user['id'], $responseBody->contactsGroup->owner); - $this->assertSame('superadmin', $responseBody->contactsGroup->entity_owner); - $this->assertInternalType('string', $responseBody->contactsGroup->labelledOwner); - $this->assertInternalType('array', $responseBody->contactsGroup->contacts); - $this->assertEmpty($responseBody->contactsGroup->contacts); - } - - public function testDelete() - { - $contactGroupController = new \Contact\controllers\ContactGroupController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactGroupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Contacts group not found', $responseBody->errors); - } -} diff --git a/test/unitTests/app/contact/ContactTypeControllerTest.php b/test/unitTests/app/contact/ContactTypeControllerTest.php deleted file mode 100644 index ecc6ae981af707d716894347f38a4ef2410064a3..0000000000000000000000000000000000000000 --- a/test/unitTests/app/contact/ContactTypeControllerTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?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 ContactTypeControllerTest extends TestCase -{ - public function testGet() - { - $contactTypeController = new \Contact\controllers\ContactTypeController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactTypeController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->contactsTypes); - $this->assertNotEmpty($responseBody->contactsTypes); - } -} diff --git a/test/unitTests/app/docserver/DocserverControllerTest.php b/test/unitTests/app/docserver/DocserverControllerTest.php deleted file mode 100644 index 9617fcc00dd582ea6f1378c2ed01817103d7a9e0..0000000000000000000000000000000000000000 --- a/test/unitTests/app/docserver/DocserverControllerTest.php +++ /dev/null @@ -1,216 +0,0 @@ -<?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 DocserverControllerTest extends TestCase -{ - private static $id = null; - private static $pathTemplate = '/tmp/unitTestMaarchCourrier/'; - - public function testGet() - { - $docserverController = new \Docserver\controllers\DocserverController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $docserverController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotEmpty($responseBody->docservers); - $this->assertNotEmpty($responseBody->types); - } - - public function testCreate() - { - $docserverController = new \Docserver\controllers\DocserverController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - if (!is_dir(self::$pathTemplate)) { - mkdir(self::$pathTemplate); - } - - $aArgs = [ - 'docserver_id' => 'NEW_DOCSERVER', - 'docserver_type_id' => 'DOC', - 'device_label' => 'new docserver', - 'size_limit_number' => 50000000000, - 'path_template' => self::$pathTemplate, - 'coll_id' => 'letterbox_coll' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $docserverController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->docserver; - $this->assertInternalType('int', self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $docserverController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('NEW_DOCSERVER', $responseBody->docserver_id); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'docserver_id' => 'WRONG_PATH', - 'docserver_type_id' => 'DOC', - 'device_label' => 'new docserver', - 'size_limit_number' => 50000000000, - 'path_template' => '/wrong/path/', - 'coll_id' => 'letterbox_coll' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(_PATH_OF_DOCSERVER_UNAPPROACHABLE, $responseBody->errors); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'docserver_id' => 'BAD_REQUEST', - 'docserver_type_id' => 'DOC', - 'device_label' => 'new docserver', - 'size_limit_number' => 50000000000, - 'path_template' => null, - 'coll_id' => 'letterbox_coll' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'docserver_id' => 'NEW_DOCSERVER', - 'docserver_type_id' => 'DOC', - 'device_label' => 'new docserver', - 'size_limit_number' => 50000000000, - 'path_template' => '/var/docserversDEV/dev1804/archive_transfer/', - 'coll_id' => 'letterbox_coll' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(_ID. ' ' . _ALREADY_EXISTS, $responseBody->errors); - } - - public function testUpdate() - { - $docserverController = new \Docserver\controllers\DocserverController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'docserver_type_id' => 'DOC', - 'device_label' => 'updated docserver', - 'size_limit_number' => 50000000000, - 'path_template' => self::$pathTemplate, - 'is_readonly' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotEmpty($responseBody->docserver); - $this->assertSame('updated docserver', $responseBody->docserver->device_label); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $docserverController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('updated docserver', $responseBody->device_label); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'docserver_type_id' => 'DOC', - 'device_label' => 'updated docserver', - 'size_limit_number' => 50000000000, - 'path_template' => '/wrong/path/', - 'is_readonly' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(_PATH_OF_DOCSERVER_UNAPPROACHABLE, $responseBody->errors); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'docserver_type_id' => 'DOC', - 'device_label' => 'updated docserver', - 'size_limit_number' => 50000000000, - 'path_template' => self::$pathTemplate, - 'is_readonly' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $docserverController->update($fullRequest, new \Slim\Http\Response(), ['id' => 12345]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Docserver not found', $responseBody->errors); - } - - public function testDelete() - { - $docserverController = new \Docserver\controllers\DocserverController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $docserverController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertsame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $docserverController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Docserver not found', $responseBody->errors); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $docserverController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Docserver does not exist', $responseBody->errors); - - rmdir(self::$pathTemplate); - } -} diff --git a/test/unitTests/app/doctype/DoctypeControllerTest.php b/test/unitTests/app/doctype/DoctypeControllerTest.php deleted file mode 100644 index fb9f7b21a551dc035a0b69535b99da5a71237358..0000000000000000000000000000000000000000 --- a/test/unitTests/app/doctype/DoctypeControllerTest.php +++ /dev/null @@ -1,760 +0,0 @@ -<?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. - -* @brief DoctypeControllerTest -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -use PHPUnit\Framework\TestCase; -use SrcCore\models\DatabaseModel; - -class DoctypeControllerTest extends TestCase -{ - private static $firstLevelId = null; - private static $secondLevelId = null; - private static $doctypeId = null; - - public function testReadList() - { - // READ LIST - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - $response = $firstLevelController->getTree($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->structure); - $this->assertNotNull($responseBody->structure[0]->id); - $this->assertNotNull($responseBody->structure[0]->text); - $this->assertNotNull($responseBody->structure[0]->parent); - - $this->assertInternalType('int', $responseBody->structure[0]->doctypes_first_level_id); - $this->assertNotNull($responseBody->structure[0]->doctypes_first_level_id); - $this->assertNotNull($responseBody->structure[0]->doctypes_first_level_label); - $this->assertNotNull($responseBody->structure[0]->enabled); - } - - public function testinitDoctypes() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - $response = $firstLevelController->initDoctypes($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->folderTypes); - $this->assertNotNull($responseBody->folderTypes[0]->foldertype_id); - $this->assertNotNull($responseBody->folderTypes[0]->foldertype_label); - - $this->assertNotNull($responseBody->firstLevel); - $this->assertNotNull($responseBody->firstLevel[0]->doctypes_first_level_id); - $this->assertNotNull($responseBody->firstLevel[0]->doctypes_first_level_label); - - $this->assertNotNull($responseBody->secondLevel); - $this->assertNotNull($responseBody->processModes); - $this->assertNotNull($responseBody->processModes->processing_modes); - $this->assertNotNull($responseBody->processModes->process_mode_priority); - $this->assertNotNull($responseBody->models); - $this->assertNotNull($responseBody->models[0]->template_id); - $this->assertNotNull($responseBody->models[0]->template_label); - $this->assertNotNull($responseBody->models[0]->template_comment); - } - - public function testCreateFirstLevel() - { - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'doctypes_first_level_label' => 'testTUfirstlevel', - 'foldertype_id' => [1], - 'css_style' => '#99999', - 'enabled' => 'Y', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $firstLevelController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$firstLevelId = $responseBody->firstLevelId; - - $this->assertInternalType('int', self::$firstLevelId); - - // CREATE FAIL - $aArgs = [ - 'doctypes_first_level_label' => '', - 'foldertype_id' => [], - 'css_style' => '#7777', - 'enabled' => 'gaz', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $firstLevelController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Invalid doctypes_first_level_label', $responseBody->errors[0]); - $this->assertSame('Invalid foldertype_id', $responseBody->errors[1]); - } - - public function testCreateSecondLevel() - { - $secondLevelController = new \Doctype\controllers\SecondLevelController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'doctypes_second_level_label' => 'testTUsecondlevel', - 'doctypes_first_level_id' => self::$firstLevelId, - 'css_style' => '#99999', - 'enabled' => 'Y', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$secondLevelId = $responseBody->secondLevelId; - - $this->assertInternalType('int', self::$secondLevelId); - - // CREATE FAIL - $aArgs = [ - 'doctypes_second_level_label' => '', - 'doctypes_first_level_id' => '', - 'css_style' => '#7777', - 'enabled' => 'gaz', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Invalid doctypes_second_level_label', $responseBody->errors[0]); - $this->assertSame('Invalid doctypes_first_level_id', $responseBody->errors[1]); - } - - public function testCreateDoctype() - { - $doctypeController = new \Doctype\controllers\DoctypeController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'testUDoctype', - 'doctypes_second_level_id' => self::$secondLevelId, - 'retention_final_disposition' => 'destruction', - 'retention_rule' => 'compta_3_03', - 'duration_current_use' => '10', - 'process_delay' => '18', - 'delay1' => '10', - 'delay2' => '5', - 'process_mode' => 'NORMAL', - 'template_id' => 0, - 'is_generated' => 'N', - 'indexes' => [ - 0 => [ - "column" => "custom_t1", - "label" => "PO#", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ], - 1 => [ - "column" => "custom_t2", - "label" => "Imput", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false, - "use" => true, - "mandatory" => false - ], - 2 => [ - "column" => "custom_f1", - "label" => "Mnt", - "type" => "float", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ], - 3 => [ - "column" => "custom_t3", - "label" => "Id/Matricule", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ] - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$doctypeId = $responseBody->doctypeId; - - $this->assertInternalType('int', self::$doctypeId); - $this->assertNotNull($responseBody->doctypeTree); - - // CREATE FAIL - $aArgs = [ - 'description' => '', - 'doctypes_second_level_id' => '', - 'retention_final_disposition' => '', - 'retention_rule' => 'compta_3_03', - 'duration_current_use' => '3', - 'process_delay' => '', - 'delay1' => '', - 'delay2' => '', - 'process_mode' => '', - 'template_id' => 0, - 'is_generated' => 'N', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Invalid description', $responseBody->errors[0]); - $this->assertSame('Invalid doctypes_second_level_id value', $responseBody->errors[1]); - $this->assertSame('Invalid process_delay value', $responseBody->errors[2]); - $this->assertSame('Invalid delay1 value', $responseBody->errors[3]); - $this->assertSame('Invalid delay2 value', $responseBody->errors[4]); - } - - public function testUpdateFirstLevel() - { - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'doctypes_first_level_label' => 'testTUfirstlevelUPDATE', - 'foldertype_id' => [1], - 'css_style' => '#7777', - 'enabled' => 'Y', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $firstLevelController->update($fullRequest, new \Slim\Http\Response(), ["id" => self::$firstLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$firstLevelId, $responseBody->firstLevelId->doctypes_first_level_id); - $this->assertSame('testTUfirstlevelUPDATE', $responseBody->firstLevelId->doctypes_first_level_label); - $this->assertSame('#7777', $responseBody->firstLevelId->css_style); - $this->assertSame('Y', $responseBody->firstLevelId->enabled); - - // UPDATE FAIL - $aArgs = [ - 'doctypes_first_level_label' => '', - 'foldertype_id' => [], - 'css_style' => '#7777', - 'enabled' => 'gaz', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $firstLevelController->update($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors[0]); - $this->assertSame('Id gaz does not exists', $responseBody->errors[1]); - $this->assertSame('Invalid doctypes_first_level_label', $responseBody->errors[2]); - $this->assertSame('Invalid foldertype_id', $responseBody->errors[3]); - } - - public function testUpdateSecondLevel() - { - $secondLevelController = new \Doctype\controllers\SecondLevelController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'doctypes_second_level_label' => 'testTUsecondlevelUPDATE', - 'doctypes_first_level_id' => self::$firstLevelId, - 'css_style' => '#7777', - 'enabled' => 'Y', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->update($fullRequest, new \Slim\Http\Response(), ["id" => self::$secondLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$secondLevelId, $responseBody->secondLevelId->doctypes_second_level_id); - $this->assertSame('testTUsecondlevelUPDATE', $responseBody->secondLevelId->doctypes_second_level_label); - $this->assertSame(self::$firstLevelId, $responseBody->secondLevelId->doctypes_first_level_id); - $this->assertSame('#7777', $responseBody->secondLevelId->css_style); - $this->assertSame('Y', $responseBody->secondLevelId->enabled); - - // UPDATE FAIL - $aArgs = [ - 'doctypes_second_level_label' => '', - 'doctypes_first_level_id' => '', - 'css_style' => '#7777', - 'enabled' => 'gaz', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->update($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors[0]); - $this->assertSame('Id gaz does not exists', $responseBody->errors[1]); - $this->assertSame('Invalid doctypes_second_level_label', $responseBody->errors[2]); - $this->assertSame('Invalid doctypes_first_level_id', $responseBody->errors[3]); - } - - public function testUpdateDoctype() - { - $doctypeController = new \Doctype\controllers\DoctypeController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'testUDoctypeUPDATE', - 'doctypes_second_level_id' => self::$secondLevelId, - 'retention_final_disposition' => 'destruction', - 'retention_rule' => 'compta_3_03', - 'duration_current_use' => '12', - 'process_delay' => '17', - 'delay1' => '11', - 'delay2' => '6', - 'process_mode' => 'SVR', - 'template_id' => 0, - 'is_generated' => 'N', - 'indexes' => [ - 0 => [ - "column" => "custom_t1", - "label" => "PO#", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false, - "use" => true, - "mandatory" => true - ], - 1 => [ - "column" => "custom_t2", - "label" => "Imput", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false, - "use" => false, - "mandatory" => false - ], - 2 => [ - "column" => "custom_f1", - "label" => "Mnt", - "type" => "float", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ], - 3 => [ - "column" => "custom_t3", - "label" => "Id/Matricule", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ] - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->update($fullRequest, new \Slim\Http\Response(), ["id" => self::$doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$doctypeId, $responseBody->doctype->type_id); - $this->assertNotNull($responseBody->doctypeTree); - - // UPDATE FAIL - $aArgs = [ - 'description' => '', - 'doctypes_second_level_id' => '', - 'retention_final_disposition' => '', - 'retention_rule' => 'compta_3_03', - 'duration_current_use' => '3', - 'process_delay' => '', - 'delay1' => '', - 'delay2' => '', - 'process_mode' => '', - 'template_id' => 0, - 'is_generated' => 'N', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->update($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('type_id is not a numeric', $responseBody->errors[0]); - $this->assertSame('Id gaz does not exists', $responseBody->errors[1]); - $this->assertSame('Invalid description', $responseBody->errors[2]); - $this->assertSame('Invalid doctypes_second_level_id value', $responseBody->errors[3]); - $this->assertSame('Invalid process_delay value', $responseBody->errors[4]); - $this->assertSame('Invalid delay1 value', $responseBody->errors[5]); - $this->assertSame('Invalid delay2 value', $responseBody->errors[6]); - } - - public function testRead() - { - // READ FIRST LEVEL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - $response = $firstLevelController->getById($request, new \Slim\Http\Response(), ["id" => self::$firstLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$firstLevelId, $responseBody->firstLevel->doctypes_first_level_id); - $this->assertSame('testTUfirstlevelUPDATE', $responseBody->firstLevel->doctypes_first_level_label); - $this->assertSame('#7777', $responseBody->firstLevel->css_style); - $this->assertSame(true, $responseBody->firstLevel->enabled); - $this->assertNotNull($responseBody->firstLevel->foldertype_id); - $this->assertNotNull($responseBody->folderTypes); - - // READ FIRST LEVEL FAIL - $response = $firstLevelController->getById($request, new \Slim\Http\Response(), ["id" => 'GAZ']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('wrong format for id', $responseBody->errors); - - // READ SECOND LEVEL - $secondLevelController = new \Doctype\controllers\SecondLevelController(); - $response = $secondLevelController->getById($request, new \Slim\Http\Response(), ["id" => self::$secondLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$secondLevelId, $responseBody->secondLevel->doctypes_second_level_id); - $this->assertSame('testTUsecondlevelUPDATE', $responseBody->secondLevel->doctypes_second_level_label); - $this->assertSame(self::$firstLevelId, $responseBody->secondLevel->doctypes_first_level_id); - $this->assertSame(true, $responseBody->secondLevel->enabled); - - // READ SECOND LEVEL FAIL - $response = $secondLevelController->getById($request, new \Slim\Http\Response(), ["id" => 'GAZ']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('wrong format for id', $responseBody->errors); - - // READ DOCTYPE - $doctypeController = new \Doctype\controllers\DoctypeController(); - $response = $doctypeController->getById($request, new \Slim\Http\Response(), ["id" => self::$doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$doctypeId, $responseBody->doctype->type_id); - $this->assertSame('testUDoctypeUPDATE', $responseBody->doctype->description); - $this->assertSame(self::$firstLevelId, $responseBody->doctype->doctypes_first_level_id); - $this->assertSame(self::$secondLevelId, $responseBody->doctype->doctypes_second_level_id); - $this->assertSame('destruction', $responseBody->doctype->retention_final_disposition); - $this->assertSame('compta_3_03', $responseBody->doctype->retention_rule); - $this->assertSame(12, $responseBody->doctype->duration_current_use); - $this->assertSame(17, $responseBody->doctype->process_delay); - $this->assertSame(11, $responseBody->doctype->delay1); - $this->assertSame(6, $responseBody->doctype->delay2); - $this->assertSame('SVR', $responseBody->doctype->process_mode); - $this->assertNotNull($responseBody->secondLevel); - $this->assertNotNull($responseBody->processModes); - $this->assertSame(null, $responseBody->doctype->template_id); - $this->assertSame('N', $responseBody->doctype->is_generated); - $this->assertNotNull($responseBody->models); - $this->assertNotNull($responseBody->doctype->indexes); - $this->assertSame('custom_t1', $responseBody->doctype->indexes[0]->column); - $this->assertSame(true, $responseBody->doctype->indexes[0]->mandatory); - $this->assertSame(true, $responseBody->doctype->indexes[0]->use); - - // READ DOCTYPE FAIL - $response = $doctypeController->getById($request, new \Slim\Http\Response(), ["id" => 'GAZ']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('wrong format for id', $responseBody->errors); - } - - public function testDeleteRedirectDoctype() - { - $doctypeController = new \Doctype\controllers\DoctypeController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'testUDoctype', - 'doctypes_first_level_id' => self::$firstLevelId, - 'doctypes_second_level_id' => self::$secondLevelId, - 'retention_final_disposition' => 'destruction', - 'retention_rule' => 'compta_3_03', - 'duration_current_use' => '10', - 'process_delay' => '18', - 'delay1' => '10', - 'delay2' => '5', - 'process_mode' => 'NORMAL', - 'template_id' => 0, - 'is_generated' => 'N', - 'indexes' => [ - 0 => [ - "column" => "custom_t1", - "label" => "PO#", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false, - "use" => false, - "mandatory" => false - ], - 1 => [ - "column" => "custom_t2", - "label" => "Imput", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false, - "use" => true, - "mandatory" => true - ], - 2 => [ - "column" => "custom_f1", - "label" => "Mnt", - "type" => "float", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ], - 3 => [ - "column" => "custom_t3", - "label" => "Id/Matricule", - "type" => "string", - "img" => "arrow-right", - "type_field" => "input", - "default_value" => false - ] - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $doctypeId = $responseBody->doctypeId; - - $resController = new \Resource\controllers\ResController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $fileContent = file_get_contents('modules/convert/Test/Samples/test.txt'); - $encodedFile = base64_encode($fileContent); - - $data = [ - [ - 'column' => 'subject', - 'value' => 'subject value test U', - 'type' => 'string', - ], - [ - 'column' => 'type_id', - 'value' => $doctypeId, - 'type' => 'integer', - ], - [ - 'column' => 'typist', - 'value' => 'LLane', - 'type' => 'string', - ] - ]; - - $aArgs = [ - 'collId' => 'letterbox_coll', - 'table' => 'res_letterbox', - 'status' => 'NEW', - 'encodedFile' => $encodedFile, - 'fileFormat' => 'txt', - 'data' => $data - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $resController->create($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string)$response->getBody()); - - $resId = $responseBody->resId; - - // CAN NOT DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->delete($fullRequest, new \Slim\Http\Response(), ["id" => $doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(1, $responseBody->deleted); - $this->assertNull($responseBody->doctypeTree); - $this->assertNotNull($responseBody->doctypes); - - $aArgs = [ - "new_type_id" => self::$doctypeId - ]; - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $requestPut = \Slim\Http\Request::createFromEnvironment($environment); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $requestPut); - - $response = $doctypeController->deleteRedirect($fullRequest, new \Slim\Http\Response(), ["id" => $doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->doctypeTree); - - $res = \Resource\models\ResModel::getById(['resId' => $resId]); - $this->assertSame(self::$doctypeId, $res['type_id']); - - DatabaseModel::delete([ - 'table' => 'res_letterbox', - 'where' => ['type_id = ?'], - 'data' => [self::$doctypeId] - ]); - - // DELETE REDIRECT FAIL - $aArgs = [ - "new_type_id" => 'gaz' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $doctypeController->deleteRedirect($fullRequest, new \Slim\Http\Response(), ["id" => $doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('wrong format for new_type_id', $responseBody->errors); - } - - public function testDeleteDoctype() - { - $doctypeController = new \Doctype\controllers\DoctypeController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->delete($fullRequest, new \Slim\Http\Response(), ["id" => self::$doctypeId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(0, $responseBody->deleted); - $this->assertNotNull($responseBody->doctypeTree); - $this->assertNull($responseBody->doctypes); - - // DELETE FAIL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $doctypeController->delete($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors); - } - - public function testDeleteSecondLevel() - { - $secondLevelController = new \Doctype\controllers\SecondLevelController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->delete($fullRequest, new \Slim\Http\Response(), ["id" => self::$secondLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$secondLevelId, $responseBody->secondLevelDeleted->doctypes_second_level_id); - $this->assertSame(self::$firstLevelId, $responseBody->secondLevelDeleted->doctypes_first_level_id); - $this->assertSame('testTUsecondlevelUPDATE', $responseBody->secondLevelDeleted->doctypes_second_level_label); - $this->assertSame('#7777', $responseBody->secondLevelDeleted->css_style); - $this->assertSame('N', $responseBody->secondLevelDeleted->enabled); - - // DELETE FAIL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $secondLevelController->delete($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors); - } - - public function testDeleteFirstLevel() - { - $firstLevelController = new \Doctype\controllers\FirstLevelController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $firstLevelController->delete($fullRequest, new \Slim\Http\Response(), ["id" => self::$firstLevelId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$firstLevelId, $responseBody->firstLevelDeleted->doctypes_first_level_id); - $this->assertSame('testTUfirstlevelUPDATE', $responseBody->firstLevelDeleted->doctypes_first_level_label); - $this->assertSame('#7777', $responseBody->firstLevelDeleted->css_style); - $this->assertSame('N', $responseBody->firstLevelDeleted->enabled); - - // DELETE FAIL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $firstLevelController->delete($fullRequest, new \Slim\Http\Response(), ["id" => 'gaz']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors); - } - - public function testDeleteSQL() - { - DatabaseModel::delete([ - 'table' => 'doctypes_first_level', - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [self::$firstLevelId] - ]); - DatabaseModel::delete([ - 'table' => 'doctypes_second_level', - 'where' => ['doctypes_second_level_id = ?'], - 'data' => [self::$secondLevelId] - ]); - - // Bypass risky test - $this->assertSame(1, 1); - } -} diff --git a/test/unitTests/app/document/DocumentControllerTest.php b/test/unitTests/app/document/DocumentControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3db105eb7e0b59e0c49ee5ed306deae012adacb6 --- /dev/null +++ b/test/unitTests/app/document/DocumentControllerTest.php @@ -0,0 +1,96 @@ +<?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 DocumentControllerTest extends TestCase +{ + private static $id = null; + + public function testCreate() + { + $nextSequenceId = \SrcCore\models\DatabaseModel::getNextSequenceValue(['sequenceId' => 'main_documents_id_seq']); + + \SrcCore\models\DatabaseModel::insert([ + 'table' => 'main_documents', + 'columnsValues' => [ + 'id' => $nextSequenceId, + 'reference' => '2018/A/1', + 'subject' => 'Mon Courrier', + 'doc_date' => 'CURRENT_TIMESTAMP', + 'status' => 2, + 'priority' => 'Urgent', + 'sender' => 'Oliver Queen', + 'sender_entity' => 'QE', + 'processing_user' => 1, + 'recipient' => 'Barry Allen', + 'creation_date' => 'CURRENT_TIMESTAMP' + ] + ]); + + self::$id = $nextSequenceId; + $this->assertInternalType('int', self::$id); + } + + public function testGet() + { + $documentController = new \Document\controllers\DocumentController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $documentController->get($request, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertInternalType('array', $responseBody->documents); + } + + public function testGetById() + { + $documentController = new \Document\controllers\DocumentController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $documentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('2018/A/1', $responseBody->document->reference); + $this->assertSame('Mon Courrier', $responseBody->document->subject); + $this->assertSame(2, $responseBody->document->status); + $this->assertSame('Urgent', $responseBody->document->priority); + $this->assertSame('Oliver Queen', $responseBody->document->sender); + $this->assertSame('QE', $responseBody->document->sender_entity); + $this->assertSame(1, $responseBody->document->processing_user); + $this->assertSame('Barry Allen', $responseBody->document->recipient); + + $response = $documentController->getById($request, new \Slim\Http\Response(), ['id' => -1]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('Document out of perimeter', $responseBody->errors); + } + + public function testDelete() + { + \Document\models\DocumentModel::delete([ + 'where' => ['id = ?'], + 'data' => [self::$id] + ]); + + $documentController = new \Document\controllers\DocumentController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $documentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('Document out of perimeter', $responseBody->errors); + } +} diff --git a/test/unitTests/app/entity/EntityControllerTest.php b/test/unitTests/app/entity/EntityControllerTest.php deleted file mode 100644 index a6910e090abc6ff19078b6b31ec887738004859e..0000000000000000000000000000000000000000 --- a/test/unitTests/app/entity/EntityControllerTest.php +++ /dev/null @@ -1,217 +0,0 @@ -<?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 EntityControllerTest extends TestCase -{ - private static $id = null; - - public function testCreate() - { - $entityController = new \Entity\controllers\EntityController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'entity_id' => 'TEST-ENTITY123', - 'entity_label' => 'TEST-ENTITY123-LABEL', - 'short_label' => 'TEST-ENTITY123-SHORTLABEL', - 'entity_type' => 'Service', - 'email' => 'paris@isMagic.fr', - 'adrs_1' => '1 rue du parc des princes', - 'zipcode' => '75016', - 'city' => 'PARIS', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $entityController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-ENTITY123', $responseBody->entity->entity_id); - $this->assertSame('TEST-ENTITY123-LABEL', $responseBody->entity->entity_label); - $this->assertSame('TEST-ENTITY123-SHORTLABEL', $responseBody->entity->short_label); - $this->assertSame('Service', $responseBody->entity->entity_type); - $this->assertSame('Y', $responseBody->entity->enabled); - $this->assertSame('paris@isMagic.fr', $responseBody->entity->email); - $this->assertSame('1 rue du parc des princes', $responseBody->entity->adrs_1); - $this->assertSame(null, $responseBody->entity->adrs_2); - $this->assertSame(null, $responseBody->entity->adrs_3); - $this->assertSame('75016', $responseBody->entity->zipcode); - $this->assertSame('PARIS', $responseBody->entity->city); - $this->assertSame(null, $responseBody->entity->parent_entity_id); - } - - public function testUpdate() - { - $entityController = new \Entity\controllers\EntityController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'entity_label' => 'TEST-ENTITY123-LABEL', - 'short_label' => 'TEST-ENTITY123-SHORTLABEL-UP', - 'entity_type' => 'Direction', - 'email' => 'paris@isMagic2.fr', - 'adrs_2' => '2 rue des princes' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $entityController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-ENTITY123', $responseBody->entity->entity_id); - $this->assertSame('TEST-ENTITY123-LABEL', $responseBody->entity->entity_label); - $this->assertSame('TEST-ENTITY123-SHORTLABEL-UP', $responseBody->entity->short_label); - $this->assertSame('Direction', $responseBody->entity->entity_type); - $this->assertSame('Y', $responseBody->entity->enabled); - $this->assertSame('paris@isMagic2.fr', $responseBody->entity->email); - $this->assertSame('1 rue du parc des princes', $responseBody->entity->adrs_1); - $this->assertSame('2 rue des princes', $responseBody->entity->adrs_2); - $this->assertSame(null, $responseBody->entity->adrs_3); - $this->assertSame('75016', $responseBody->entity->zipcode); - $this->assertSame('PARIS', $responseBody->entity->city); - $this->assertSame(null, $responseBody->entity->parent_entity_id); - } - - public function testUpdateStatus() - { - $entityController = new \Entity\controllers\EntityController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'method' => 'disable' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $entityController->updateStatus($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-ENTITY123', $responseBody->entity->entity_id); - $this->assertSame('N', $responseBody->entity->enabled); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'method' => 'enable' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $entityController->updateStatus($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-ENTITY123', $responseBody->entity->entity_id); - $this->assertSame('Y', $responseBody->entity->enabled); - } - - public function testGet() - { - $entityController = new \Entity\controllers\EntityController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - $this->assertNotNull($responseBody->entities); - } - - public function testGetDetailledById() - { - $entityController = new \Entity\controllers\EntityController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getDetailledById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-ENTITY123', $responseBody->entity->entity_id); - $this->assertSame('TEST-ENTITY123-LABEL', $responseBody->entity->entity_label); - $this->assertSame('TEST-ENTITY123-SHORTLABEL-UP', $responseBody->entity->short_label); - $this->assertSame('Direction', $responseBody->entity->entity_type); - $this->assertSame('Y', $responseBody->entity->enabled); - $this->assertSame('paris@isMagic2.fr', $responseBody->entity->email); - $this->assertSame('1 rue du parc des princes', $responseBody->entity->adrs_1); - $this->assertSame('2 rue des princes', $responseBody->entity->adrs_2); - $this->assertSame(null, $responseBody->entity->adrs_3); - $this->assertSame('75016', $responseBody->entity->zipcode); - $this->assertSame('PARIS', $responseBody->entity->city); - $this->assertSame(null, $responseBody->entity->parent_entity_id); - $this->assertInternalType('array', (array) $responseBody->entity->listTemplate); - $this->assertInternalType('array', $responseBody->entity->visaTemplate); - $this->assertSame(false, $responseBody->entity->hasChildren); - $this->assertSame(0, $responseBody->entity->documents); - $this->assertInternalType('array', $responseBody->entity->users); - $this->assertSame(0, $responseBody->entity->templates); - $this->assertSame(0, $responseBody->entity->instances); - $this->assertSame(0, $responseBody->entity->redirects); - } - - public function testDelete() - { - $entityController = new \Entity\controllers\EntityController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->delete($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $entityController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-ENTITY123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Entity not found', $responseBody->errors); - } -} diff --git a/test/unitTests/app/entity/ListTemplateControllerTest.php b/test/unitTests/app/entity/ListTemplateControllerTest.php deleted file mode 100644 index e505cca14d2e680d52d604aee7c1a51106b7a22c..0000000000000000000000000000000000000000 --- a/test/unitTests/app/entity/ListTemplateControllerTest.php +++ /dev/null @@ -1,204 +0,0 @@ -<?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 ListTemplateControllerTest extends TestCase -{ - private static $id = null; - - public function testCreate() - { - $listTemplateController = new \Entity\controllers\ListTemplateController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'object_type' => 'VISA_CIRCUIT', - 'title' => 'TEST-LISTTEMPLATE123-TITLE', - 'description' => 'TEST LISTTEMPLATE123 DESCRIPTION', - 'items' => [ - [ - 'sequence' => 0, - 'item_id' => 'bbain', - 'item_type' => 'user_id', - 'item_mode' => 'visa' - ], - [ - 'sequence' => 1, - 'item_id' => 'ssissoko', - 'item_type' => 'user_id', - 'item_mode' => 'visa' - ], - [ - 'sequence' => 0, - 'item_id' => 'bboule', - 'item_type' => 'user_id', - 'item_mode' => 'sign' - ] - ], - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $listTemplateController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - foreach ($responseBody->listTemplates as $listTemplate) { - if ($listTemplate->title == 'TEST-LISTTEMPLATE123-TITLE') { - self::$id = $listTemplate->id; - $this->assertSame('VISA_CIRCUIT', $listTemplate->object_type); - $this->assertSame('VISA_CIRCUIT_', substr($listTemplate->object_id, 0, 13)); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION', $listTemplate->description); - } - } - - $this->assertNotEmpty(self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('VISA_CIRCUIT', $responseBody->listTemplate->diffusionList[0]->object_type); - $this->assertSame('TEST-LISTTEMPLATE123-TITLE', $responseBody->listTemplate->diffusionList[0]->title); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION', $responseBody->listTemplate->diffusionList[0]->description); - $this->assertSame(0, $responseBody->listTemplate->diffusionList[0]->sequence); - $this->assertSame('bbain', $responseBody->listTemplate->diffusionList[0]->item_id); - $this->assertSame('user_id', $responseBody->listTemplate->diffusionList[0]->item_type); - $this->assertSame('visa', $responseBody->listTemplate->diffusionList[0]->item_mode); - $this->assertSame('Y', $responseBody->listTemplate->diffusionList[0]->visible); - - $this->assertSame('VISA_CIRCUIT', $responseBody->listTemplate->diffusionList[1]->object_type); - $this->assertSame('TEST-LISTTEMPLATE123-TITLE', $responseBody->listTemplate->diffusionList[1]->title); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION', $responseBody->listTemplate->diffusionList[1]->description); - $this->assertSame(1, $responseBody->listTemplate->diffusionList[1]->sequence); - $this->assertSame('ssissoko', $responseBody->listTemplate->diffusionList[1]->item_id); - $this->assertSame('user_id', $responseBody->listTemplate->diffusionList[1]->item_type); - $this->assertSame('visa', $responseBody->listTemplate->diffusionList[1]->item_mode); - $this->assertSame('Y', $responseBody->listTemplate->diffusionList[1]->visible); - - $this->assertSame('VISA_CIRCUIT', $responseBody->listTemplate->diffusionList[2]->object_type); - $this->assertSame('TEST-LISTTEMPLATE123-TITLE', $responseBody->listTemplate->diffusionList[2]->title); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION', $responseBody->listTemplate->diffusionList[2]->description); - $this->assertSame(0, $responseBody->listTemplate->diffusionList[2]->sequence); - $this->assertSame('bboule', $responseBody->listTemplate->diffusionList[2]->item_id); - $this->assertSame('user_id', $responseBody->listTemplate->diffusionList[2]->item_type); - $this->assertSame('sign', $responseBody->listTemplate->diffusionList[2]->item_mode); - $this->assertSame('Y', $responseBody->listTemplate->diffusionList[2]->visible); - } - - public function testUpdate() - { - $listTemplateController = new \Entity\controllers\ListTemplateController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'title' => 'TEST-LISTTEMPLATE123-TITLE-UPDATED', - 'description' => 'TEST LISTTEMPLATE123 DESCRIPTION UPDATED', - 'items' => [ - [ - 'sequence' => 0, - 'item_id' => 'kkaar', - 'item_type' => 'user_id', - 'item_mode' => 'visa' - ], - [ - 'sequence' => 0, - 'item_id' => 'ppetit', - 'item_type' => 'user_id', - 'item_mode' => 'sign' - ] - ], - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $listTemplateController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = null; - foreach ($responseBody->listTemplates as $listTemplate) { - if ($listTemplate->title == 'TEST-LISTTEMPLATE123-TITLE-UPDATED') { - self::$id = $listTemplate->id; - $this->assertSame('VISA_CIRCUIT', $listTemplate->object_type); - $this->assertSame('VISA_CIRCUIT_', substr($listTemplate->object_id, 0, 13)); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION UPDATED', $listTemplate->description); - } - } - $this->assertNotEmpty(self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('VISA_CIRCUIT', $responseBody->listTemplate->diffusionList[0]->object_type); - $this->assertSame('TEST-LISTTEMPLATE123-TITLE-UPDATED', $responseBody->listTemplate->diffusionList[0]->title); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION UPDATED', $responseBody->listTemplate->diffusionList[0]->description); - $this->assertSame(0, $responseBody->listTemplate->diffusionList[0]->sequence); - $this->assertSame('kkaar', $responseBody->listTemplate->diffusionList[0]->item_id); - $this->assertSame('user_id', $responseBody->listTemplate->diffusionList[0]->item_type); - $this->assertSame('visa', $responseBody->listTemplate->diffusionList[0]->item_mode); - $this->assertSame('Y', $responseBody->listTemplate->diffusionList[0]->visible); - - $this->assertSame('VISA_CIRCUIT', $responseBody->listTemplate->diffusionList[1]->object_type); - $this->assertSame('TEST-LISTTEMPLATE123-TITLE-UPDATED', $responseBody->listTemplate->diffusionList[1]->title); - $this->assertSame('TEST LISTTEMPLATE123 DESCRIPTION UPDATED', $responseBody->listTemplate->diffusionList[1]->description); - $this->assertSame(0, $responseBody->listTemplate->diffusionList[1]->sequence); - $this->assertSame('ppetit', $responseBody->listTemplate->diffusionList[1]->item_id); - $this->assertSame('user_id', $responseBody->listTemplate->diffusionList[1]->item_type); - $this->assertSame('sign', $responseBody->listTemplate->diffusionList[1]->item_mode); - $this->assertSame('Y', $responseBody->listTemplate->diffusionList[1]->visible); - - $this->assertSame(null, $responseBody->listTemplate->diffusionList[2]); - } - - public function testDelete() - { - $listTemplateController = new \Entity\controllers\ListTemplateController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $listTemplateController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('List template not found', $responseBody->errors); - } -} diff --git a/test/unitTests/app/group/GroupControllerTest.php b/test/unitTests/app/group/GroupControllerTest.php deleted file mode 100644 index a80eb0f910e13f90e2c8a4a9b74da58526eea198..0000000000000000000000000000000000000000 --- a/test/unitTests/app/group/GroupControllerTest.php +++ /dev/null @@ -1,125 +0,0 @@ -<?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 GroupControllerTest extends TestCase -{ - private static $id = null; - - - public function testCreate() - { - $groupController = new \Group\controllers\GroupController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'group_id' => 'TEST-JusticeLeague', - 'group_desc' => 'Beyond the darkness', - 'security' => [ - 'where_clause' => '1=2', - 'maarch_comment' => 'commentateur du dimanche' - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $groupController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->group . ''; - - $this->assertInternalType('int', $responseBody->group); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $groupController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-JusticeLeague', $responseBody->group->group_id); - $this->assertSame('Beyond the darkness', $responseBody->group->group_desc); - $this->assertSame('Y', $responseBody->group->enabled); - $this->assertSame('1=2', $responseBody->group->security->where_clause); - $this->assertSame('commentateur du dimanche', $responseBody->group->security->maarch_comment); - $this->assertInternalType('array', $responseBody->group->users); - $this->assertInternalType('array', $responseBody->group->baskets); - $this->assertEmpty($responseBody->group->users); - $this->assertEmpty($responseBody->group->baskets); - $this->assertSame(true, $responseBody->group->canAdminUsers); - $this->assertSame(true, $responseBody->group->canAdminBaskets); - } - - public function testUpdate() - { - $groupController = new \Group\controllers\GroupController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'description' => 'Beyond the darkness #2', - 'security' => [ - 'where_clause' => '1=3', - 'maarch_comment' => 'commentateur du dimanche #2' - ] - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $groupController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $groupController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-JusticeLeague', $responseBody->group->group_id); - $this->assertSame('Beyond the darkness #2', $responseBody->group->group_desc); - $this->assertSame('Y', $responseBody->group->enabled); - $this->assertSame('1=3', $responseBody->group->security->where_clause); - $this->assertSame('commentateur du dimanche #2', $responseBody->group->security->maarch_comment); - $this->assertInternalType('array', $responseBody->group->users); - $this->assertInternalType('array', $responseBody->group->baskets); - $this->assertEmpty($responseBody->group->users); - $this->assertEmpty($responseBody->group->baskets); - $this->assertSame(true, $responseBody->group->canAdminUsers); - $this->assertSame(true, $responseBody->group->canAdminBaskets); - } - - public function testDelete() - { - $groupController = new \Group\controllers\GroupController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $groupController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->groups); - $this->assertNotEmpty($responseBody->groups); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $groupController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Group not found', $responseBody->errors); - } - -} diff --git a/test/unitTests/app/history/HistoryControllerTest.php b/test/unitTests/app/history/HistoryControllerTest.php deleted file mode 100644 index 81d60ad1d54789051fe9b95063c3e9057a057b6b..0000000000000000000000000000000000000000 --- a/test/unitTests/app/history/HistoryControllerTest.php +++ /dev/null @@ -1,71 +0,0 @@ -<?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 HistoryControllerTest extends TestCase -{ - public function testGetHistoryByUserId() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $history = new \History\controllers\HistoryController(); - - $currentUser = \User\models\UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - $response = $history->getByUserId($request, new \Slim\Http\Response(), ['userSerialId' => $currentUser['id']]); - - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotEmpty($responseBody->histories); - } - - public function testGetHistory() - { - $history = new \History\controllers\HistoryController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'startDate' => '1521100000', - 'endDate' => time() - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $history->get($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->histories); - $this->assertInternalType('bool', $responseBody->limitExceeded); - $this->assertNotEmpty($responseBody->histories); - } - - public function testGetBatchHistory() - { - $batchHistory = new \History\controllers\BatchHistoryController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'startDate' => '1521100000', - 'endDate' => time() - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $batchHistory->get($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->batchHistories); - $this->assertInternalType('bool', $responseBody->limitExceeded); - $this->assertNotNull($responseBody->batchHistories); - } -} diff --git a/test/unitTests/app/notification/NotificationControllerTest.php b/test/unitTests/app/notification/NotificationControllerTest.php deleted file mode 100644 index 0f86a0ef9aa10d2732be90a1a65f0bc210486dea..0000000000000000000000000000000000000000 --- a/test/unitTests/app/notification/NotificationControllerTest.php +++ /dev/null @@ -1,295 +0,0 @@ -<?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. - -* -* @brief NotificationsControllerTest -* -* @author dev <dev@maarch.org> -* @ingroup core -*/ -use PHPUnit\Framework\TestCase; - -class NotificationControllerTest extends TestCase -{ - private static $id = null; - - public function testCreate() - { - $NotificationController = new \Notification\controllers\NotificationController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'notification_id' => 'testcreatetu', - 'description' => 'description de la notification', - 'is_enabled' => 'Y', - 'event_id' => 'users%', - 'notification_mode' => 'EMAIL', - 'template_id' => 4, - 'diffusion_type' => 'group', - 'diffusion_properties' => ['ADMINISTRATEUR', 'ARCHIVISTE', 'DIRECTEUR'], - 'attachfor_type' => 'entity', - 'attachfor_properties' => ['COU', 'PJS'], - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertInternalType('int', $responseBody->notification_sid); - self::$id = $responseBody->notification_sid; - - $this->assertSame('testcreatetu', $responseBody->notification_id); - $this->assertSame('description de la notification', $responseBody->description); - $this->assertSame('Y', $responseBody->is_enabled); - $this->assertSame('users%', $responseBody->event_id); - $this->assertSame('EMAIL', $responseBody->notification_mode); - $this->assertSame(4, $responseBody->template_id); - $this->assertSame('group', $responseBody->diffusion_type); - $this->assertSame('ADMINISTRATEUR,ARCHIVISTE,DIRECTEUR', $responseBody->diffusion_properties); - $this->assertSame('entity', $responseBody->attachfor_type); - $this->assertSame('COU,PJS', $responseBody->attachfor_properties); - } - - public function testCreateFail1() - { - //Fail Create 1 - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'notification_id' => '', - 'description' => 'description de la notification', - 'is_enabled' => 'Y', - 'event_id' => '', - 'notification_mode' => 'EMAIL', - 'template_id' => '', - 'diffusion_type' => 'user', - 'diffusion_properties' => 'superadmin', - 'attachfor_type' => 'zz', - 'attachfor_properties' => 'cc', - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('notification_id is empty', $responseBody->errors[0]); - $this->assertSame('wrong format for template_id', $responseBody->errors[1]); - } - - public function testCreateFail2() - { - //Fail Create 2 - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'notification_id' => 'testcreatetu', - 'description' => 'description de la notification', - 'is_enabled' => 'Y', - 'event_id' => 'users%', - 'notification_mode' => 'EMAIL', - 'template_id' => 4, - 'diffusion_type' => 'user', - 'diffusion_properties' => 'superadmin', - 'attachfor_type' => 'zz', - 'attachfor_properties' => 'cc', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - $this->assertSame('Notification déjà existante', $responseBody->errors); - } - - public function testRead() - { - //READ - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(self::$id, $responseBody->notification->notification_sid); - $this->assertSame('testcreatetu', $responseBody->notification->notification_id); - $this->assertSame('description de la notification', $responseBody->notification->description); - $this->assertSame('Y', $responseBody->notification->is_enabled); - $this->assertSame('users%', $responseBody->notification->event_id); - $this->assertSame('EMAIL', $responseBody->notification->notification_mode); - $this->assertSame(4, $responseBody->notification->template_id); - $this->assertSame('group', $responseBody->notification->diffusion_type); - } - - public function testReadFail() - { - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => 'test']); - $responseBody = json_decode((string) $response->getBody()); - $this->assertSame('Id is not a numeric', $responseBody->errors); - } - - public function testReadFail2() - { - //I CANT READ BECAUSE NO EXIST - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => '9999999999']); - $responseBody = json_decode((string) $response->getBody()); - $this->assertSame('Notification not found', $responseBody->errors); - } - - public function testReadAll() - { - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $NotificationController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertNotNull($responseBody->notifications); - } - - public function testUpdate() - { - // UPDATE - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'notification_id' => 'testcreatetu', - 'description' => 'nouvelle description', - 'is_enabled' => 'N', - 'event_id' => 'users%', - 'notification_mode' => 'EMAIL', - 'template_id' => 3, - 'diffusion_type' => 'group', - 'diffusion_properties' => ['ADMINISTRATEUR', 'ARCHIVISTE', 'DIRECTEUR'], - 'attachfor_type' => 'entity', - 'attachfor_properties' => ['COU', 'PJS'], - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(self::$id, $responseBody->notification->notification_sid); - $this->assertSame('testcreatetu', $responseBody->notification->notification_id); - $this->assertSame('nouvelle description', $responseBody->notification->description); - $this->assertSame('N', $responseBody->notification->is_enabled); - $this->assertSame('users%', $responseBody->notification->event_id); - $this->assertSame('EMAIL', $responseBody->notification->notification_mode); - $this->assertSame(3, $responseBody->notification->template_id); - $this->assertSame('group', $responseBody->notification->diffusion_type); - $this->assertSame('ADMINISTRATEUR,ARCHIVISTE,DIRECTEUR', $responseBody->notification->diffusion_properties); - $this->assertSame('entity', $responseBody->notification->attachfor_type); - $this->assertSame('COU,PJS', $responseBody->notification->attachfor_properties); - } - - public function testUpdateFail() - { - // UPDATE - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'notification_id' => 'testcreatetu', - 'description' => '', - 'is_enabled' => 'N', - 'event_id' => 'users%', - 'notification_mode' => 'EMAIL', - 'template_id' => '', - 'diffusion_type' => 'group', - 'diffusion_properties' => ['ADMINISTRATEUR', 'ARCHIVISTE', 'DIRECTEUR'], - 'attachfor_type' => 'entity', - 'attachfor_properties' => ['COU', 'PJS'], - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('wrong format for description', $responseBody->errors[0]); - $this->assertSame('wrong format for template_id', $responseBody->errors[1]); - } - - public function testUpdateFail2() - { - // UPDATE - $NotificationController = new \Notification\controllers\NotificationController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'notification_id' => 'testcreatetu', - 'description' => 'description', - 'is_enabled' => 'N', - 'event_id' => 'users%', - 'notification_mode' => 'EMAIL', - 'template_id' => 4, - 'diffusion_type' => 'group', - 'diffusion_properties' => ['ADMINISTRATEUR', 'ARCHIVISTE', 'DIRECTEUR'], - 'attachfor_type' => 'entity', - 'attachfor_properties' => ['COU', 'PJS'], - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'fail']); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('notification_sid is not a numeric', $responseBody->errors[0]); - $this->assertSame('notification does not exists', $responseBody->errors[1]); - } - - public function testDelete() - { - $NotificationController = new \Notification\controllers\NotificationController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $NotificationController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertNotNull($responseBody->notifications[0]); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $NotificationController->getBySid($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertNull($responseBody->notifications[0]); - - // FAIL DELETE - $response = $NotificationController->delete($request, new \Slim\Http\Response(), ['id' => 'gaz']); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('Id is not a numeric', $responseBody->errors); - } - - public function testGetInitNotification() - { - // InitAction - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $NotificationController = new \Notification\controllers\NotificationController(); - $response = $NotificationController->initNotification($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertNotNull($responseBody->notification->data->event); - $this->assertNotNull($responseBody->notification->data->template); - $this->assertNotNull($responseBody->notification->data->diffusionType); - $this->assertNotNull($responseBody->notification->data->groups); - $this->assertNotNull($responseBody->notification->data->users); - $this->assertNotNull($responseBody->notification->data->entities); - $this->assertNotNull($responseBody->notification->data->status); - } -} diff --git a/test/unitTests/app/notification/NotificationScheduleControllerTest.php b/test/unitTests/app/notification/NotificationScheduleControllerTest.php deleted file mode 100644 index 0f5d4e283ca91d7cbdf03eeb6a033f8752b8fb50..0000000000000000000000000000000000000000 --- a/test/unitTests/app/notification/NotificationScheduleControllerTest.php +++ /dev/null @@ -1,216 +0,0 @@ -<?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. - -* -* @brief NotificationsScheduleControllerTest -* -* @author dev <dev@maarch.org> -* @ingroup core -*/ -use PHPUnit\Framework\TestCase; - -class NotificationScheduleControllerTest extends TestCase -{ - private static $id = null; - - public function testCreateScript() - { - $NotificationScheduleController = new \Notification\controllers\NotificationScheduleController(); - - // CREATE FAIL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'notification_sid' => 'gaz', - 'notification_id' => '', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $NotificationScheduleController->createScriptNotification($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('notification_sid is not a numeric', $responseBody->errors[0]); - $this->assertSame('one of arguments is empty', $responseBody->errors[1]); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'notification_sid' => 1, - 'notification_id' => 'USERS', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $NotificationScheduleController->createScriptNotification($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(true, $responseBody); - } - - public function testSaveCrontab() - { - $NotificationScheduleController = new \Notification\controllers\NotificationScheduleController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $NotificationScheduleController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - // CREATE FAIL - $aArgs = $responseBody->crontab; - - $corePath = dirname(__FILE__, 5).'/'; - $newCrontab = [ - 'm' => 12, - 'h' => 23, - 'dom' => '', - 'mon' => '*', - 'dow' => '*', - 'cmd' => $corePath.'modules/notifications/batch/scripts/notification_testtu.sh', - 'state' => 'normal', - ]; - - array_push($aArgs, $newCrontab); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationScheduleController->create($fullRequest, new \Slim\Http\Response()); - $responseBodyFail = json_decode((string) $response->getBody()); - - $this->assertSame('wrong format for dom', $responseBodyFail->errors[0]); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = $responseBody->crontab; - - $corePath = dirname(__FILE__, 5).'/'; - $newCrontab = [ - 'm' => 12, - 'h' => 23, - 'dom' => '*', - 'mon' => '*', - 'dow' => '*', - 'cmd' => $corePath.'modules/notifications/batch/scripts/notification_testtu.sh', - 'state' => 'normal', - ]; - - array_push($aArgs, $newCrontab); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $NotificationScheduleController->create($fullRequest, new \Slim\Http\Response()); - $responseBodyCreate = json_decode((string) $response->getBody()); - - $this->assertSame(true, $responseBodyCreate); - } - - public function testReadAll() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $NotificationScheduleController = new \Notification\controllers\NotificationScheduleController(); - $response = $NotificationScheduleController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertInternalType('array', $responseBody->crontab); - $this->assertInternalType('array', $responseBody->authorizedNotification); - $this->assertNotNull($responseBody->authorizedNotification); - $this->assertNotNull($responseBody->crontab); - } - - public function testUpdateCrontab() - { - $NotificationScheduleController = new \Notification\controllers\NotificationScheduleController(); - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $NotificationScheduleController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = $responseBody->crontab; - - $corePath = dirname(__FILE__, 5).'/'; - - $aArgs[count($aArgs) - 1] = [ - 'm' => 35, - 'h' => 22, - 'dom' => '*', - 'mon' => '*', - 'dow' => '*', - 'cmd' => $corePath.'modules/notifications/batch/scripts/notification_testtu.sh', - 'state' => 'normal', - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $NotificationScheduleController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(true, $responseBody); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $NotificationScheduleController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('35', $responseBody->crontab[count($responseBody->crontab) - 1]->m); - $this->assertSame('22', $responseBody->crontab[count($responseBody->crontab) - 1]->h); - } - - public function testDelete() - { - // DELETE FAIL - $NotificationScheduleController = new \Notification\controllers\NotificationScheduleController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $NotificationScheduleController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $aArgs = $responseBody->crontab; - - foreach ($aArgs as $id => $value) { - if ($value->cmd == dirname(__FILE__, 5).'/'.'modules/notifications/batch/scripts/notification_testtu.sh') { - $aArgs[$id]->state = 'hidden'; - } - } - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $NotificationScheduleController->create($fullRequest, new \Slim\Http\Response()); - $responseBodyFail = json_decode((string) $response->getBody()); - - $this->assertSame('Problem with crontab', $responseBodyFail->errors); - - // DELETE - $aArgs = $responseBody->crontab; - - foreach ($aArgs as $id => $value) { - if ($value->cmd == dirname(__FILE__, 5).'/'.'modules/notifications/batch/scripts/notification_testtu.sh') { - $aArgs[$id]->state = 'deleted'; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $NotificationScheduleController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(true, $responseBody); - - unlink('modules/notifications/batch/scripts/notification_USERS.sh'); - } -} diff --git a/test/unitTests/app/parameter/ParameterControllerTest.php b/test/unitTests/app/parameter/ParameterControllerTest.php deleted file mode 100644 index 2ef0e239490b7a65c2c889ab67e02a04d88dd699..0000000000000000000000000000000000000000 --- a/test/unitTests/app/parameter/ParameterControllerTest.php +++ /dev/null @@ -1,109 +0,0 @@ -<?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 ParameterControllerTest extends TestCase -{ - public function testCreate() - { - $parameterController = new \Parameter\controllers\ParameterController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'id' => 'TEST-PARAMETER123', - 'description' => 'TEST PARAMETER123 DESCRIPTION', - 'param_value_string' => '20.12' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $parameterController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $parameterController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-PARAMETER123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-PARAMETER123', $responseBody->parameter->id); - $this->assertSame('TEST PARAMETER123 DESCRIPTION', $responseBody->parameter->description); - $this->assertSame('20.12', $responseBody->parameter->param_value_string); - } - - public function testUpdate() - { - $parameterController = new \Parameter\controllers\ParameterController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'TEST PARAMETER123 DESCRIPTION UPDATED', - 'param_value_string' => '20.12.22' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $parameterController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'TEST-PARAMETER123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $parameterController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-PARAMETER123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('TEST-PARAMETER123', $responseBody->parameter->id); - $this->assertSame('TEST PARAMETER123 DESCRIPTION UPDATED', $responseBody->parameter->description); - $this->assertSame('20.12.22', $responseBody->parameter->param_value_string); - } - - public function testGet() - { - $parameterController = new \Parameter\controllers\ParameterController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $parameterController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->parameters); - $this->assertNotNull($responseBody->parameters); - } - - public function testDelete() - { - $parameterController = new \Parameter\controllers\ParameterController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $parameterController->delete($request, new \Slim\Http\Response(), ['id' => 'TEST-PARAMETER123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->parameters); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $parameterController->getById($request, new \Slim\Http\Response(), ['id' => 'TEST-PARAMETER123']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Parameter not found', $responseBody->errors); - } -} diff --git a/test/unitTests/app/priority/PriorityControllerTest.php b/test/unitTests/app/priority/PriorityControllerTest.php deleted file mode 100644 index 57f3e3677bd9b3a6893e08c5be7f61e4103f384d..0000000000000000000000000000000000000000 --- a/test/unitTests/app/priority/PriorityControllerTest.php +++ /dev/null @@ -1,123 +0,0 @@ -<?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 PriorityControllerTest extends TestCase -{ - private static $id = null; - - - public function testCreate() - { - $priorityController = new \Priority\controllers\PriorityController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'label' => 'TEST-OVER-URGENT', - 'color' => '#ffffff', - 'working_days' => true, - 'delays' => '2', - 'default_priority' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $priorityController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->priority; - - $this->assertInternalType('string', self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->priority->id); - $this->assertSame('TEST-OVER-URGENT', $responseBody->priority->label); - $this->assertSame('#ffffff', $responseBody->priority->color); - $this->assertSame(true, $responseBody->priority->working_days); - $this->assertSame(2, $responseBody->priority->delays); - } - - public function testGet() - { - $priorityController = new \Priority\controllers\PriorityController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $priorityController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->priorities); - $this->assertNotNull($responseBody->priorities); - } - - public function testUpdate() - { - $priorityController = new \Priority\controllers\PriorityController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'label' => 'TEST-OVER-URGENT-UPDATED', - 'color' => '#f2f2f2', - 'working_days' => false, - 'delays' => '4', - 'default_priority' => true - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $priorityController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->priority->id); - $this->assertSame('TEST-OVER-URGENT-UPDATED', $responseBody->priority->label); - $this->assertSame('#f2f2f2', $responseBody->priority->color); - $this->assertSame(false, $responseBody->priority->working_days); - $this->assertSame(4, $responseBody->priority->delays); - } - - public function testDelete() - { - $priorityController = new \Priority\controllers\PriorityController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $priorityController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->priorities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Priority not found', $responseBody->errors); - } -} diff --git a/test/unitTests/app/report/ReportControllerTest.php b/test/unitTests/app/report/ReportControllerTest.php deleted file mode 100644 index fda6d573c5e7711c5c9930982b70f801821d13e9..0000000000000000000000000000000000000000 --- a/test/unitTests/app/report/ReportControllerTest.php +++ /dev/null @@ -1,100 +0,0 @@ -<?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 ReportControllerTest extends TestCase -{ - private static $id = null; - - public function testGetGroups() - { - $reportController = new \Report\controllers\ReportController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $reportController->getGroups($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->groups); - - self::$id = $responseBody->groups[0]->group_id; - } - - public function testUpdateForGroupId() - { - $reportController = new \Report\controllers\ReportController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $reportController->getByGroupId($request, new \Slim\Http\Response(), ['groupId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->reports); - - foreach ($responseBody->reports as $key => $report) { - $responseBody->reports[$key]->checked = true; - } - - // PUT - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $fullRequest = \httpRequestCustom::addContentInBody($responseBody->reports, $request); - - $response = $reportController->updateForGroupId($fullRequest, new \Slim\Http\Response(), ['groupId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $reportController->getByGroupId($request, new \Slim\Http\Response(), ['groupId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->reports); - - foreach ($responseBody->reports as $key => $report) { - $this->assertSame(true, $report->checked); - if ($key % 2) { - $responseBody->reports[$key]->checked = false; - } - } - - // PUT - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $fullRequest = \httpRequestCustom::addContentInBody($responseBody->reports, $request); - - $response = $reportController->updateForGroupId($fullRequest, new \Slim\Http\Response(), ['groupId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $reportController->getByGroupId($request, new \Slim\Http\Response(), ['groupId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->reports); - - foreach ($responseBody->reports as $key => $report) { - if ($key % 2) { - $this->assertSame(false, $report->checked); - } else { - $this->assertSame(true, $report->checked); - } - } - } -} diff --git a/test/unitTests/app/resource/ResControllerTest.php b/test/unitTests/app/resource/ResControllerTest.php deleted file mode 100644 index 9565c451ebc85fbf356f7f0bfa40ebce5a598f98..0000000000000000000000000000000000000000 --- a/test/unitTests/app/resource/ResControllerTest.php +++ /dev/null @@ -1,411 +0,0 @@ -<?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 ResControllerTest extends TestCase -{ - private static $id = null; - - public function testCreate() - { - $resController = new \Resource\controllers\ResController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $fileContent = file_get_contents('modules/convert/Test/Samples/test.txt'); - $encodedFile = base64_encode($fileContent); - - $data = [ - [ - 'column' => 'subject', - 'value' => 'Breaking News : Superman is alive', - 'type' => 'string', - ], - [ - 'column' => 'type_id', - 'value' => 102, - 'type' => 'integer', - ], - [ - 'column' => 'typist', - 'value' => 'LLane', - 'type' => 'string', - ] - ]; - - $aArgs = [ - 'collId' => 'letterbox_coll', - 'table' => 'res_letterbox', - 'status' => 'NEW', - 'encodedFile' => $encodedFile, - 'fileFormat' => 'txt', - 'data' => $data - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - self::$id = $responseBody->resId; - $this->assertInternalType('int', self::$id); - - // READ - $res = \Resource\models\ResModel::getById(['resId' => self::$id]); - - $this->assertInternalType('array', $res); - - $this->assertSame('Breaking News : Superman is alive', $res['subject']); - $this->assertSame(null, $res['title']); - $this->assertSame(null, $res['description']); - $this->assertSame(102, $res['type_id']); - $this->assertSame('txt', $res['format']); - $this->assertSame('NEW', $res['status']); - $this->assertSame('LLane', $res['typist']); - $this->assertSame(null, $res['destination']); - } - - public function testCreateExt() - { - $resController = new \Resource\controllers\ResController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $data = [ - [ - 'column' => 'category_id', - 'value' => 'incoming', - 'type' => 'string', - ] - ]; - - $aArgs = [ - 'resId' => self::$id, - 'data' => $data - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->createExt($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(true, $responseBody->status); - - $ext = \Resource\models\ResModel::getExtById(['resId' => self::$id, 'select' => ['category_id']]); - - $this->assertSame('incoming', $ext['category_id']); - - $data = [ - [ - 'column' => 'category_id', - 'value' => 'incoming', - 'type' => 'string', - ] - ]; - - $aArgs = [ - 'resId' => self::$id, - 'data' => $data - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->createExt($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Document already exists in mlb_coll_ext', $responseBody->errors); - - - $aArgs = [ - 'resId' => self::$id, - 'data' => null - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->createExt($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } - - public function testGetFileContent() - { - $resController = new \Resource\controllers\ResController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $resController->getFileContent($request, new \Slim\Http\Response(), ['resId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(null, $responseBody); - - $response = $resController->getFileContent($request, new \Slim\Http\Response(), ['resId' => -2]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Document does not exist', $responseBody->errors); - } - - public function testGetThumbnailContent() - { - $resController = new \Resource\controllers\ResController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $resController->getThumbnailContent($request, new \Slim\Http\Response(), ['resId' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(null, $responseBody); - - $response = $resController->getThumbnailContent($request, new \Slim\Http\Response(), ['resId' => -2]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(null, $responseBody); - } - - public function testUpdateStatus() - { - $resController = new \Resource\controllers\ResController(); - - // UPDATE STATUS - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'resId' => [self::$id], - 'status' => 'EVIS' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateStatus($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame('success', $responseBody->success); - - // READ - $res = \Resource\models\ResModel::getById(['resId' => self::$id]); - $this->assertInternalType('array', $res); - $this->assertSame('EVIS', $res['status']); - - // UPDATE WITHOUT STATUS - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'resId' => [self::$id] - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateStatus($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $res = \Resource\models\ResModel::getById(['resId' => self::$id]); - $this->assertInternalType('array', $res); - $this->assertSame('COU', $res['status']); - } - - public function testUpdateExternalInfos() - { - $resController = new \Resource\controllers\ResController(); - - // UPDATE STATUS - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - //ALL OK - $aArgs = [ - 'externalInfos' => [ - [ - 'res_id' => self::$id, - 'external_id' => "BB981212IIYZ", - 'external_link' => "https://publik.nancy.fr/res/BB981212BB65" - ] - ], - 'status' => "GRCSENT" - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // EXTERNAL INFOS EMPTY AND RES ID IS NOT INTEGER - $aArgs = [ - 'externalInfos' => [ - [ - 'res_id' => "res_id", - 'external_id' => "", - 'external_link' => "" - ] - ], - 'status' => "GRCSENT" - - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('Bad Request: invalid res_id', $responseBody->errors); - - // DOCUMENT DOES NOT EXIST - $aArgs = [ - 'externalInfos' => [ - [ - 'res_id' => 123456789, - 'external_id' => "BB981212IIYZ", - 'external_link' => "https://publik.nancy.fr/res/BB981212BB65" - ] - ], - 'status' => 'GRCSENT' - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame(_DOCUMENT_NOT_FOUND, $responseBody->errors); - - //MISSING STATUS - $aArgs = [ - 'externalInfos' => [ - [ - 'res_id' => self::$id, - 'external_id' => "BB981212IIYZ", - 'external_link' => "https://publik.nancy.fr/res/BB981212BB65" - ] - ], - 'status' => null - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - - //MISSING EXTERNAL INFOS - $aArgs = [ - 'externalInfos' => null, - 'status' => "GRCSENT" - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->updateExternalInfos($fullRequest, new \Slim\Http\Response()); - - $responseBody = json_decode((string) $response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } - - public function testGetList() - { - $resController = new \Resource\controllers\ResController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'select' => 'res_id', - 'clause' => '1=1', - 'withFile' => true, - 'orderBy' => ['res_id'], - 'limit' => 1 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->getList($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $arr_res = $responseBody->resources; - $this->assertNotNull($arr_res[0]->fileBase64Content); - $this->assertInternalType('int', $arr_res[0]->res_id); - - $aArgs = [ - 'select' => 'res_id', - 'clause' => '1=1', - 'withFile' => false, - 'orderBy' => ['res_id'], - 'limit' => 1 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->getList($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $arr_res = $responseBody->resources; - $this->assertSame(null, $arr_res[0]->fileBase64Content); - $this->assertInternalType('int', $arr_res[0]->res_id); - - $aArgs = [ - 'select' => '', - 'clause' => '1=1', - 'withFile' => false, - 'orderBy' => ['res_id'], - 'limit' => 1 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->getList($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame("Bad Request: select is not valid", $responseBody->errors); - - $aArgs = [ - 'select' => 'res_id', - 'clause' => '', - 'withFile' => false, - 'orderBy' => ['res_id'], - 'limit' => 1 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $resController->getList($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame("Bad Request: clause is not valid", $responseBody->errors); - } - - public function testDelete() - { - // DELETE - \Resource\models\ResModel::delete(['resId' => self::$id]); - - // READ - $res = \Resource\models\ResModel::getById(['resId' => self::$id]); - $this->assertInternalType('array', $res); - $this->assertSame('DEL', $res['status']); - - // REAL DELETE - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'res_letterbox', - 'where' => ['res_id = ?'], - 'data' => [self::$id] - ]); - - // READ - $res = \Resource\models\ResModel::getById(['resId' => self::$id]); - $this->assertInternalType('array', $res); - $this->assertEmpty($res); - } -} diff --git a/test/unitTests/app/status/StatusControllerTest.php b/test/unitTests/app/status/StatusControllerTest.php deleted file mode 100644 index 0762340d6b6fd01fd53589e720f9b66421ca8749..0000000000000000000000000000000000000000 --- a/test/unitTests/app/status/StatusControllerTest.php +++ /dev/null @@ -1,197 +0,0 @@ -<?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 StatusControllerTest extends TestCase -{ - public function testCreate() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $status = new \Status\controllers\StatusController(); - - $aArgs = [ - 'id' => 'TEST', - 'label_status' => 'TEST', - 'img_filename' => 'fm-letter-end', - 'can_be_searched' => 'true', - 'can_be_modified' => '', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $status->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType("int", $responseBody->status->identifier); - - unset($responseBody->status->identifier); - - $compare = [ - 'id' => 'TEST', - 'label_status' => 'TEST', - 'is_system' => 'N', - 'img_filename' => 'fm-letter-end', - 'maarch_module' => 'apps', - 'can_be_searched' => 'Y', - 'can_be_modified' => 'N', - ]; - - $aCompare = json_decode(json_encode($compare), false); - $this->assertEquals($aCompare, $responseBody->status, "\$canonicalize = true", 0.0, 10, true); - - ########## CREATE FAIL ########## - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'id' => 'TEST', - 'label_status' => 'TEST', - 'img_filename' => 'fm-letter-end', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $status->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(_ID . ' TEST ' . _ALREADY_EXISTS, $responseBody->errors[0]); - - ########## CREATE FAIL 2 ########## - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'id' => 'papa', - 'label_status' => '', - 'img_filename' => 'fm-letter-end', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $status->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Invalid label_status value', $responseBody->errors[0]); - } - - public function testGetListUpdateDelete() - { - ########## GET LIST ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $status = new \Status\controllers\StatusController(); - - $response = $status->get($request, new \Slim\Http\Response()); - - $responseBody = json_decode((string)$response->getBody()); - $this->assertNotNull($responseBody->statuses); - - foreach ($responseBody->statuses as $value) { - $this->assertInternalType("int", $value->identifier); - } - - //$this->assertNotNull($responseBody->lang); - - $elem = $responseBody->statuses; - end($elem); - $key = key($elem); - $lastIdentifier = $elem[$key]->identifier; - - ########## GETBYIDENTIFIER ########## - $response = $status->getByIdentifier($request, new \Slim\Http\Response(), ['identifier' => $lastIdentifier]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->status); - $this->assertNotNull($responseBody->statusImages); - - $compare = [ - 'identifier' => $lastIdentifier, - 'id' => 'TEST', - 'label_status' => 'TEST', - 'is_system' => 'N', - 'img_filename' => 'fm-letter-end', - 'maarch_module' => 'apps', - 'can_be_searched' => 'Y', - 'can_be_modified' => 'N', - ]; - - $aCompare = json_decode(json_encode($compare), false); - $this->assertEquals($aCompare, $responseBody->status[0], "\$canonicalize = true", 0.0, 10, true); - - ########## GETBYIDENTIFIER FAIL ########## - $response = $status->getByIdentifier($request, new \Slim\Http\Response(), ['identifier' => -1]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('identifier not found', $responseBody->errors); - - - ########## UPDATE ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'id' => 'TEST', - 'label_status' => 'TEST AFTER UP', - 'img_filename' => 'fm-letter-end', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $status->update($fullRequest, new \Slim\Http\Response(), ['identifier' => $lastIdentifier]); - - $responseBody = json_decode((string)$response->getBody()); - - $compare = [ - 'identifier' => $lastIdentifier, - 'id' => 'TEST', - 'label_status' => 'TEST AFTER UP', - 'is_system' => 'N', - 'img_filename' => 'fm-letter-end', - 'maarch_module' => 'apps', - 'can_be_searched' => 'Y', - 'can_be_modified' => 'N', - ]; - - $aCompare = json_decode(json_encode($compare), false); - - $this->assertEquals($aCompare, $responseBody->status, "\$canonicalize = true", 0.0, 10, true); - - ########## UPDATE FAIL ########## - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'id' => 'PZOEIRUTY', - 'label_status' => 'TEST AFTER UP', - 'img_filename' => 'fm-letter-end', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $status->update($fullRequest, new \Slim\Http\Response(), ['identifier' => -1]); - - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame('-1 ' . _NOT_EXISTS, $responseBody->errors[0]); - - - ########## DELETE ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $status->delete($request, new \Slim\Http\Response(), ['identifier'=> $lastIdentifier]); - - //$this->assertSame((string)$response->getBody(), '[true]'); - $this->assertRegexp('/statuses/', (string)$response->getBody()); - } - - public function testGetNewInformations() - { - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $status = new \Status\controllers\StatusController(); - - $response = $status->getNewInformations($request, new \Slim\Http\Response()); - - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->statusImages); - //$this->assertNotNull($responseBody->lang); - } -} diff --git a/test/unitTests/app/template/TemplateControllerTest.php b/test/unitTests/app/template/TemplateControllerTest.php deleted file mode 100644 index 4cbeb291d7a045291ffe229ad632c3d81b504c34..0000000000000000000000000000000000000000 --- a/test/unitTests/app/template/TemplateControllerTest.php +++ /dev/null @@ -1,314 +0,0 @@ -<?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 TemplateControllerTest extends TestCase -{ - private static $id = null; - private static $idDuplicated = null; - - public function testCreate() - { - $templates = new \Template\controllers\TemplateController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'template_label' => 'TEST TEMPLATE', - 'template_comment' => 'DESCRIPTION OF THIS TEMPLATE', - 'template_target' => 'sendmail', - 'template_attachment_type' => 'all', - 'template_type' => 'HTML', - 'template_content' => 'Content of this template', - 'template_datasource' => 'letterbox_attachment', - 'entities' => ['DGS', 'COU'] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $templates->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->template; - $this->assertInternalType("int", self::$id); - - // CREATE FAIL - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'template_label' => '', - 'template_comment' => '', - 'template_target' => 'sendmail', - 'template_attachment_type' => 'all', - 'template_type' => 'HTML', - 'template_content' => 'Content of this template', - 'template_datasource' => 'letterbox_attachment' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $templates->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } - - public function testRead() - { - $templates = new \Template\controllers\TemplateController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->template->template_id); - $this->assertSame('TEST TEMPLATE', $responseBody->template->template_label); - $this->assertSame('DESCRIPTION OF THIS TEMPLATE', $responseBody->template->template_comment); - $this->assertSame('sendmail', $responseBody->template->template_target); - $this->assertSame('all', $responseBody->template->template_attachment_type); - $this->assertSame('HTML', $responseBody->template->template_type); - $this->assertSame('Content of this template', $responseBody->template->template_content); - $this->assertSame('letterbox_attachment', $responseBody->template->template_datasource); - $this->assertNotNull($responseBody->templatesModels); - $this->assertNotNull($responseBody->templatesModels[0]->fileName); - $this->assertNotNull($responseBody->templatesModels[0]->fileExt); - $this->assertNotNull($responseBody->templatesModels[0]->filePath); - $this->assertNotNull($responseBody->attachmentTypes); - $this->assertNotNull($responseBody->attachmentTypes[0]->label); - $this->assertNotNull($responseBody->attachmentTypes[0]->id); - $this->assertNotNull($responseBody->datasources); - $this->assertNotNull($responseBody->datasources[0]->id); - $this->assertNotNull($responseBody->datasources[0]->label); - $this->assertNotNull($responseBody->datasources[0]->script); - $this->assertNotNull($responseBody->datasources[0]->target); - $this->assertNotNull($responseBody->entities); - $this->assertNotNull($responseBody->entities[0]->entity_id); - $this->assertNotNull($responseBody->entities[0]->entity_label); - - // READ FAIL - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->getDetailledById($request, new \Slim\Http\Response(), ['id' => '11119999']); - $responseBody = json_decode((string)$response->getBody()); - $this->assertSame('Template does not exist', $responseBody->errors); - } - - public function testUpdate() - { - $templates = new \Template\controllers\TemplateController(); - - ########## UPDATE ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'template_label' => 'TEST TEMPLATE UPDATE', - 'template_comment' => 'DESCRIPTION OF THIS TEMPLATE UPDATE', - 'template_target' => 'sendmail', - 'template_attachment_type' => 'all', - 'template_type' => 'HTML', - 'template_content' => 'Content of this template', - 'template_datasource' => 'letterbox_attachment', - 'entities' => [] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $templates->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame("success", $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->template->template_id); - $this->assertSame('TEST TEMPLATE UPDATE', $responseBody->template->template_label); - $this->assertSame('DESCRIPTION OF THIS TEMPLATE UPDATE', $responseBody->template->template_comment); - $this->assertSame('sendmail', $responseBody->template->template_target); - $this->assertSame('all', $responseBody->template->template_attachment_type); - $this->assertSame('HTML', $responseBody->template->template_type); - $this->assertSame('Content of this template', $responseBody->template->template_content); - $this->assertSame('letterbox_attachment', $responseBody->template->template_datasource); - - ########## UPDATE FAIL MISSING PARAMETERS ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'template_label' => '', - 'template_comment' => '', - 'template_target' => 'sendmail', - 'template_attachment_type' => 'all', - 'template_type' => 'HTML', - 'template_content' => 'Content of this template', - 'template_datasource' => 'letterbox_attachment', - 'entities' => [] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $templates->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame("Bad Request", $responseBody->errors); - - ########## UPDATE FAIL WRONG ID ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'template_label' => '', - 'template_comment' => '', - 'template_target' => 'sendmail', - 'template_attachment_type' => 'all', - 'template_type' => 'HTML', - 'template_content' => 'Content of this template', - 'template_datasource' => 'letterbox_attachment', - 'entities' => [] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $templates->update($fullRequest, new \Slim\Http\Response(), ['id' => '1235789']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Template does not exist', $responseBody->errors); - } - - public function testDuplicate() - { - $templates = new \Template\controllers\TemplateController(); - - ########## DUPLICATE ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $templates->duplicate($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - self::$idDuplicated = $responseBody->id; - $this->assertInternalType("int", self::$idDuplicated); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$idDuplicated]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('int', $responseBody->template->template_id); - $this->assertSame('Copie de TEST TEMPLATE UPDATE', $responseBody->template->template_label); - $this->assertSame('DESCRIPTION OF THIS TEMPLATE UPDATE', $responseBody->template->template_comment); - $this->assertSame('sendmail', $responseBody->template->template_target); - $this->assertSame('all', $responseBody->template->template_attachment_type); - $this->assertSame('HTML', $responseBody->template->template_type); - $this->assertSame('Content of this template', $responseBody->template->template_content); - $this->assertSame('letterbox_attachment', $responseBody->template->template_datasource); - - ########## DUPLICATE FAIL ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $templates->duplicate($request, new \Slim\Http\Response(), ['id' => 139875323456]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Template not found', $responseBody->errors); - } - - public function testGetList() - { - $templates = new \Template\controllers\TemplateController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $idFound = false; - $idDuplicatedFound = false; - foreach ($responseBody->templates as $template) { - $this->assertInternalType('int', $template->template_id); - $this->assertNotNull($template->template_label); - $this->assertNotNull($template->template_comment); - $this->assertNotNull($template->template_type); - - if ($template->template_id == self::$id) { - $idFound = true; - } - if ($template->template_id == self::$idDuplicated) { - $idDuplicatedFound = true; - } - } - - $this->assertSame(true, $idFound); - $this->assertSame(true, $idDuplicatedFound); - } - - public function testDelete() - { - $templates = new \Template\controllers\TemplateController(); - - ########## DELETE ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $templates->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame("success", $responseBody->success); - - ########## DELETE DUPLICATED ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $templates->delete($request, new \Slim\Http\Response(), ['id' => self::$idDuplicated]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame("success", $responseBody->success); - - ########## DELETE FAIL ########## - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $templates->delete($request, new \Slim\Http\Response(), ['id' => '8928191923']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Template does not exist', $responseBody->errors); - } - - public function testInitTemplate() - { - $templates = new \Template\controllers\TemplateController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $templates->initTemplates($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->templatesModels); - $this->assertNotNull($responseBody->templatesModels[0]->fileName); - $this->assertNotNull($responseBody->templatesModels[0]->fileExt); - $this->assertNotNull($responseBody->templatesModels[0]->filePath); - $this->assertNotNull($responseBody->attachmentTypes); - $this->assertNotNull($responseBody->attachmentTypes[0]->label); - $this->assertNotNull($responseBody->attachmentTypes[0]->id); - $this->assertNotNull($responseBody->datasources); - $this->assertNotNull($responseBody->datasources[0]->id); - $this->assertNotNull($responseBody->datasources[0]->label); - $this->assertNotNull($responseBody->datasources[0]->script); - $this->assertNotNull($responseBody->datasources[0]->target); - $this->assertNotNull($responseBody->entities); - $this->assertNotNull($responseBody->entities[0]->entity_id); - $this->assertNotNull($responseBody->entities[0]->entity_label); - } -} diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php deleted file mode 100644 index c806711da3a8ae864aaa40af0998a2522918f2e2..0000000000000000000000000000000000000000 --- a/test/unitTests/app/user/UserControllerTest.php +++ /dev/null @@ -1,758 +0,0 @@ -<?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 UserControllerTest extends TestCase -{ - private static $id = null; - - - public function testGet() - { - $userController = new \User\controllers\UserController(); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $userController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - - $this->assertInternalType('array', $responseBody->users); - $this->assertNotEmpty($responseBody->users); - } - - public function testCreate() - { - $userController = new \User\controllers\UserController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'userId' => 'TEST-CKENT', - 'firstname' => 'TEST-CLARK', - 'lastname' => 'TEST-KENT' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - self::$id = $responseBody->user->id; - - $this->assertInternalType('int', self::$id); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('TEST-CKENT', $responseBody->user_id); - $this->assertSame('TEST-CLARK', $responseBody->firstname); - $this->assertSame('TEST-KENT', $responseBody->lastname); - $this->assertSame('OK', $responseBody->status); - $this->assertSame('Y', $responseBody->enabled); - $this->assertSame(null, $responseBody->phone); - $this->assertSame(null, $responseBody->mail); - $this->assertSame(null, $responseBody->initials); - $this->assertSame(null, $responseBody->thumbprint); - } - - public function testUpdate() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'user_id' => 'TEST-CKENT', - 'firstname' => 'TEST-CLARK2', - 'lastname' => 'TEST-KENT2', - 'mail' => 'ck@dailyP.com', - 'phone' => '0122334455', - 'initials' => 'CK', - 'enabled' => 'N', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('TEST-CKENT', $responseBody->user_id); - $this->assertSame('TEST-CLARK2', $responseBody->firstname); - $this->assertSame('TEST-KENT2', $responseBody->lastname); - $this->assertSame('OK', $responseBody->status); - $this->assertSame('N', $responseBody->enabled); - $this->assertSame('0122334455', $responseBody->phone); - $this->assertSame('ck@dailyP.com', $responseBody->mail); - $this->assertSame('CK', $responseBody->initials); - $this->assertSame(null, $responseBody->thumbprint); - } - - public function testAddGroup() - { - $userController = new \User\controllers\UserController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'groupId' => 'AGENT', - 'role' => 'Douche' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->addGroup($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->groups); - $this->assertInternalType('array', $responseBody->baskets); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->groups); - $this->assertSame('AGENT', $responseBody->groups[0]->group_id); - $this->assertSame('Douche', $responseBody->groups[0]->role); - } - - public function testUpdateGroup() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'role' => 'role updated' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateGroup($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'groupId' => 'AGENT']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->groups); - $this->assertSame('AGENT', $responseBody->groups[0]->group_id); - $this->assertSame('role updated', $responseBody->groups[0]->role); - } - - public function testDeleteGroup() - { - $userController = new \User\controllers\UserController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->deleteGroup($request, new \Slim\Http\Response(), ['id' => self::$id, 'groupId' => 'AGENT']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->groups); - $this->assertEmpty($responseBody->groups); - $this->assertInternalType('array', $responseBody->baskets); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->groups); - $this->assertEmpty($responseBody->groups); - } - - public function testAddEntity() - { - $userController = new \User\controllers\UserController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'entityId' => 'DGS', - 'role' => 'Warrior' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->addEntity($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - $this->assertInternalType('array', $responseBody->allEntities); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'entityId' => 'FIN', - 'role' => 'Hunter' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->addEntity($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - $this->assertInternalType('array', $responseBody->allEntities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->entities); - $this->assertSame('DGS', $responseBody->entities[0]->entity_id); - $this->assertSame('Warrior', $responseBody->entities[0]->user_role); - $this->assertSame('Y', $responseBody->entities[0]->primary_entity); - $this->assertSame('FIN', $responseBody->entities[1]->entity_id); - $this->assertSame('Hunter', $responseBody->entities[1]->user_role); - $this->assertSame('N', $responseBody->entities[1]->primary_entity); - } - - public function testUpdateEntity() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'user_role' => 'Rogue' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateEntity($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'entityId' => 'DGS']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->entities); - $this->assertSame('DGS', $responseBody->entities[0]->entity_id); - $this->assertSame('Rogue', $responseBody->entities[0]->user_role); - $this->assertSame('Y', $responseBody->entities[0]->primary_entity); - } - - public function testUpdatePrimaryEntity() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $userController->updatePrimaryEntity($request, new \Slim\Http\Response(), ['id' => self::$id, 'entityId' => 'FIN']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->entities); - $this->assertSame('FIN', $responseBody->entities[0]->entity_id); - $this->assertSame('Hunter', $responseBody->entities[0]->user_role); - $this->assertSame('Y', $responseBody->entities[0]->primary_entity); - $this->assertSame('DGS', $responseBody->entities[1]->entity_id); - $this->assertSame('Rogue', $responseBody->entities[1]->user_role); - $this->assertSame('N', $responseBody->entities[1]->primary_entity); - } - - public function testDeleteEntity() - { - $userController = new \User\controllers\UserController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->deleteEntity($request, new \Slim\Http\Response(), ['id' => self::$id, 'entityId' => 'FIN']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - $this->assertInternalType('array', $responseBody->allEntities); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->deleteEntity($request, new \Slim\Http\Response(), ['id' => self::$id, 'entityId' => 'DGS']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->entities); - $this->assertEmpty($responseBody->entities); - $this->assertInternalType('array', $responseBody->allEntities); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertInternalType('array', $responseBody->entities); - $this->assertEmpty($responseBody->entities); - } - - public function testUpdateStatus() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'status' => 'ABS' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateStatus($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('ABS', $responseBody->user->status); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('ABS', $responseBody->status); - } - - public function testRead() - { - $userController = new \User\controllers\UserController(); - $parameterController = new \Parameter\controllers\ParameterController(); - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'User quota', - 'param_value_int' => 0 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $parameterController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'user_quota']); - - // READ in case of deactivated user_quota - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->get($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->users); - $this->assertNull($responseBody->quota->userQuota); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'description' => 'User quota', - 'param_value_int' => 20 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $parameterController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'user_quota']); - - // READ in case of enabled user_quotat - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->get($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->users); - $this->assertNotNull($responseBody->quota); - $this->assertSame(20, $responseBody->quota->userQuota); - $this->assertNotNull($responseBody->quota->actives); - $this->assertInternalType('int', $responseBody->quota->inactives); - - } - - public function testUserQuota() - { - $userController = new \User\controllers\UserController(); - $parameterController = new \Parameter\controllers\ParameterController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'userId' => 'TEST-CKENTquota', - 'firstname' => 'TEST-CLARKquota', - 'lastname' => 'TEST-KENTquota' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->create($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - $userId = $responseBody->user->id; - - $this->assertInternalType('int', $userId); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'user_id' => 'TEST-CKENTquota', - 'firstname' => 'TEST-CLARKquota2', - 'lastname' => 'TEST-KENTquota2', - 'mail' => 'ck@dailyP.com', - 'phone' => '0122334455', - 'initials' => 'CK', - 'enabled' => 'N', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' =>$userId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // UPDATE disabled user for user_quota (avoid notification sending) - $aArgs = [ - 'user_id' => 'TEST-CKENTquota', - 'firstname' => 'TEST-CLARKquota2', - 'lastname' => 'TEST-KENTquota2', - 'mail' => 'ck@dailyP.com', - 'phone' => '0122334455', - 'initials' => 'CK', - 'enabled' => 'Y', - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' =>$userId]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // DELETE - // REAL DELETE - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'users', - 'where' => ['id = ?'], - 'data' => [$userId] - ]); - - // UPDATE - $aArgs = [ - 'description' => 'User quota', - 'param_value_int' => 0 - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $parameterController->update($fullRequest, new \Slim\Http\Response(), ['id' => 'user_quota']); - } - - public function testDelete() - { - $userController = new \User\controllers\UserController(); - - // DELETE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getDetailledById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('TEST-CKENT', $responseBody->user_id); - $this->assertSame('TEST-CLARK2', $responseBody->firstname); - $this->assertSame('TEST-KENT2', $responseBody->lastname); - $this->assertSame('DEL', $responseBody->status); - $this->assertSame('N', $responseBody->enabled); - $this->assertSame('0122334455', $responseBody->phone); - $this->assertSame('ck@dailyP.com', $responseBody->mail); - $this->assertSame('CK', $responseBody->initials); - $this->assertSame(null, $responseBody->thumbprint); - - // REAL DELETE - \SrcCore\models\DatabaseModel::delete([ - 'table' => 'users', - 'where' => ['id = ?'], - 'data' => [self::$id] - ]); - } - - public function testPasswordManagement() - { - $userController = new \User\controllers\UserController(); - - // UPDATE PASSWORD - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'currentPassword' => 'superadmin', - 'newPassword' => 'hcraam', - 'reNewPassword' => 'hcraam' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateCurrentUserPassword($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $checkPassword = \SrcCore\models\AuthenticationModel::authentication(['userId' => $GLOBALS['userId'], 'password' => 'hcraam']); - - $this->assertSame(true, $checkPassword); - - // RESET PASSWORD - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = []; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $user = \User\models\UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - $response = $userController->resetPassword($fullRequest, new \Slim\Http\Response(), ['id' => $user['id']]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $checkPassword = \SrcCore\models\AuthenticationModel::authentication(['userId' => $GLOBALS['userId'], 'password' => 'maarch']); - - $this->assertSame(true, $checkPassword); - - // UPDATE PASSWORD - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'currentPassword' => 'maarch', - 'newPassword' => 'superadmin', - 'reNewPassword' => 'superadmin' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateCurrentUserPassword($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $checkPassword = \SrcCore\models\AuthenticationModel::authentication(['userId' => $GLOBALS['userId'], 'password' => 'superadmin']); - - $this->assertSame(true, $checkPassword); - - \SrcCore\models\DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'change_password' => 'N' - ], - 'where' => ['user_id = ?'], - 'data' => [$GLOBALS['userId']] - ]); - } - - public function testUpdateProfile() - { - $userController = new \User\controllers\UserController(); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'firstname' => 'Wonder', - 'lastname' => 'User', - 'mail' => 'dev@maarch.org', - 'initials' => 'SU' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateProfile($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getProfile($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('superadmin', $responseBody->user_id); - $this->assertSame('Wonder', $responseBody->firstname); - $this->assertSame('User', $responseBody->lastname); - $this->assertSame('dev@maarch.org', $responseBody->mail); - $this->assertSame('SU', $responseBody->initials); - - // UPDATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - 'firstname' => 'Super', - 'lastname' => 'Admin', - 'mail' => 'dev@maarch.org', - 'initials' => 'SU' - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - - $response = $userController->updateProfile($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - // READ - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getProfile($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('superadmin', $responseBody->user_id); - $this->assertSame('Super', $responseBody->firstname); - $this->assertSame('Admin', $responseBody->lastname); - $this->assertSame('dev@maarch.org', $responseBody->mail); - $this->assertSame('SU', $responseBody->initials); - } - - public function testSetRedirectedBasket() - { - $userController = new \User\controllers\UserController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $aArgs = [ - [ - 'newUser' => 'bblier', - 'basketId' => 'MyBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ], - [ - 'newUser' => 'bblier', - 'basketId' => 'EenvBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ] - ]; - - $user_id = \User\models\UserModel::getByUserId(['userId' => 'bbain', 'select' => ['id']]); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $userController->setRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id']]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->baskets); - - $aArgs = [ - [ - 'newUser' => null, - 'basketId' => 'MyBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ], - [ - 'newUser' => 'bblier', - 'basketId' => 'EenvBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $userController->setRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id']]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - - $aArgs = [ - [ - 'newUser' => 'notExist', - 'basketId' => 'MyBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ], - [ - 'newUser' => 'existNot', - 'basketId' => 'EenvBasket', - 'basketOwner' => 'bbain', - 'virtual' => 'Y' - ] - ]; - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $userController->setRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id']]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('User not found', $responseBody->errors); - } - - public function testDeleteRedirectedBaskets() - { - $userController = new \User\controllers\UserController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'basketOwner' => 'bbain', - ]; - - $user_id = \User\models\UserModel::getByUserId(['userId' => 'bbain', 'select' => ['id']]); - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $userController->deleteRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id'], 'basketId' => 'MyBasket']); - $response = $userController->deleteRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id'], 'basketId' => 'EenvBasket']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotNull($responseBody->baskets); - - $aArgs = [ - 'basketOwner' => null, - ]; - - $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $userController->deleteRedirectedBaskets($fullRequest, new \Slim\Http\Response(), ['id' => $user_id['id'], 'basketId' => 'MyBasket']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } -} diff --git a/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php b/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php deleted file mode 100644 index c691e07c74df34cc11d87f68b58d172482265f77..0000000000000000000000000000000000000000 --- a/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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 VersionUpdateControllerTest extends TestCase -{ - public function testGet() - { - $versionUpdateController = new \VersionUpdate\controllers\VersionUpdateController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $versionUpdateController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->currentMinorVersions); - $this->assertNotNull($responseBody->currentMinorVersions); - $this->assertInternalType('array', $responseBody->availableMajorVersions); - $this->assertInternalType('string', $responseBody->currentVersion); - $this->assertNotNull($responseBody->currentVersion); - } -} diff --git a/test/unitTests/core/AutocompleteControllerTest.php b/test/unitTests/core/AutocompleteControllerTest.php deleted file mode 100644 index dd2b011ece6fe87099c53eb44a863d5ea4dde1c2..0000000000000000000000000000000000000000 --- a/test/unitTests/core/AutocompleteControllerTest.php +++ /dev/null @@ -1,221 +0,0 @@ -<?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. - -* @brief ActionsControllerTest -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -use PHPUnit\Framework\TestCase; - -class AutocompleteControllerTest extends TestCase -{ - public function testGetContacts() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'search' => 'maarch', - 'type' => 'all' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getContacts($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertInternalType('int', $responseBody[0]->position); - $this->assertInternalType('int', $responseBody[0]->addressId); - $this->assertInternalType('string', $responseBody[0]->contact); - $this->assertInternalType('string', $responseBody[0]->address); - } - - public function testGetUsers() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'search' => 'bain' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getUsers($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertSame('user', $responseBody[0]->type); - $this->assertInternalType('string', $responseBody[0]->id); - $this->assertNotEmpty($responseBody[0]->id); - $this->assertInternalType('string', $responseBody[0]->idToDisplay); - $this->assertNotEmpty($responseBody[0]->idToDisplay); - $this->assertInternalType('string', $responseBody[0]->otherInfo); - } - - public function testGetUsersForAdministration() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'search' => 'bern', - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getUsersForAdministration($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertSame('user', $responseBody[0]->type); - $this->assertInternalType('int', $responseBody[0]->id); - $this->assertNotEmpty($responseBody[0]->id); - $this->assertInternalType('string', $responseBody[0]->idToDisplay); - $this->assertNotEmpty($responseBody[0]->idToDisplay); - } - - public function testGetUsersForVisa() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'search' => 'dau', - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getUsersForVisa($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertSame('user', $responseBody[0]->type); - $this->assertInternalType('string', $responseBody[0]->id); - $this->assertNotEmpty($responseBody[0]->id); - $this->assertInternalType('string', $responseBody[0]->idToDisplay); - $this->assertNotEmpty($responseBody[0]->idToDisplay); - $this->assertInternalType('string', $responseBody[0]->otherInfo); - } - - public function testGetEntities() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'search' => 'mai', - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getEntities($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertSame('entity', $responseBody[0]->type); - $this->assertInternalType('string', $responseBody[0]->id); - $this->assertNotEmpty($responseBody[0]->id); - $this->assertInternalType('string', $responseBody[0]->idToDisplay); - $this->assertNotEmpty($responseBody[0]->idToDisplay); - $this->assertInternalType('string', $responseBody[0]->otherInfo); - } - - public function testGetStatuses() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $autocompleteController->getStatuses($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertSame('status', $responseBody[0]->type); - $this->assertInternalType('string', $responseBody[0]->id); - $this->assertNotEmpty($responseBody[0]->id); - $this->assertInternalType('string', $responseBody[0]->idToDisplay); - $this->assertNotEmpty($responseBody[0]->idToDisplay); - $this->assertInternalType('string', $responseBody[0]->otherInfo); - } - - public function testGetBanAddresses() - { - $autocompleteController = new \SrcCore\controllers\AutoCompleteController(); - - // CREATE - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'department' => '75', - 'address' => 'italie' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getBanAddresses($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody); - $this->assertNotEmpty($responseBody); - - $this->assertInternalType('string', $responseBody[0]->banId); - $this->assertNotEmpty($responseBody[0]->banId); - $this->assertInternalType('string', $responseBody[0]->number); - $this->assertNotEmpty($responseBody[0]->number); - $this->assertInternalType('string', $responseBody[0]->afnorName); - $this->assertNotEmpty($responseBody[0]->afnorName); - $this->assertInternalType('string', $responseBody[0]->postalCode); - $this->assertNotEmpty($responseBody[0]->postalCode); - $this->assertInternalType('string', $responseBody[0]->city); - $this->assertNotEmpty($responseBody[0]->city); - $this->assertInternalType('string', $responseBody[0]->address); - $this->assertNotEmpty($responseBody[0]->address); - - // Errors - $aArgs = [ - 'department' => '100', - 'address' => 'italie' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $autocompleteController->getBanAddresses($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Department indexes do not exist', $responseBody->errors); - - $response = $autocompleteController->getBanAddresses($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('Bad Request', $responseBody->errors); - } -} diff --git a/test/unitTests/core/CoreControllerTest.php b/test/unitTests/core/CoreControllerTest.php deleted file mode 100644 index 8e879e4eef4a50e294ad06f2a66f23fec909c620..0000000000000000000000000000000000000000 --- a/test/unitTests/core/CoreControllerTest.php +++ /dev/null @@ -1,63 +0,0 @@ -<?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. - -* @brief ActionsControllerTest -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -use PHPUnit\Framework\TestCase; - -class CoreControllerTest extends TestCase -{ - public function testInitialize() - { - $coreController = new \SrcCore\controllers\CoreController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $coreController->getAdministration($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertNotEmpty($responseBody->administrations->organisation); - $this->assertNotEmpty($responseBody->administrations->classement); - $this->assertNotEmpty($responseBody->administrations->production); - $this->assertNotEmpty($responseBody->administrations->supervision); - } - - public function testrenderJnlp() - { - // ERROR FILE NAME - $coreController = new \ContentManagement\controllers\JnlpController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'fileName' => 'superadmin_maarch_12345.jnlp' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $coreController->renderJnlp($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('File name forbidden', $responseBody->errors); - - // ERROR EXTENSION - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $aArgs = [ - 'fileName' => 'superadmin_maarchCM_12345.js' - ]; - $fullRequest = $request->withQueryParams($aArgs); - - $response = $coreController->renderJnlp($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('File extension forbidden', $responseBody->errors); - } -} diff --git a/test/unitTests/core/PasswordControllerTest.php b/test/unitTests/core/PasswordControllerTest.php deleted file mode 100644 index 49765f237620fa3f3c74e90894d223417902d09d..0000000000000000000000000000000000000000 --- a/test/unitTests/core/PasswordControllerTest.php +++ /dev/null @@ -1,157 +0,0 @@ -<?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 PasswordControllerTest extends TestCase -{ - public function testGetRules() - { - $passwordController = new \SrcCore\controllers\PasswordController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $passwordController->getRules($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->rules); - $this->assertNotEmpty($responseBody->rules); - } - - public function testUpdateRules() - { - $passwordController = new \SrcCore\controllers\PasswordController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $passwordController->getRules($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - // reset - $rules = (array)$responseBody->rules; - foreach ($rules as $key => $rule) { - $rules[$key] = (array)$rule; - $rule = (array)$rule; - if ($rule['label'] == 'complexitySpecial' || $rule['label'] == 'complexityNumber' || $rule['label'] == 'complexityUpper') { - $rules[$key]['enabled'] = false; - } - if ($rule['label'] == 'minLength') { - $rules[$key]['value'] = 6; - $rules[$key]['enabled'] = true; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'maarch']); - $this->assertSame($isPasswordValid, true); - - // minLength - foreach ($rules as $key => $rule) { - if ($rule['label'] == 'minLength') { - $rules[$key]['value'] = 7; - $rules[$key]['enabled'] = true; - } - } - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'maarch']); - $this->assertSame($isPasswordValid, false); - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'maaarch']); - $this->assertSame($isPasswordValid, true); - - // complexityUpper - foreach ($rules as $key => $rule) { - if ($rule['label'] == 'complexityUpper') { - $rules[$key]['enabled'] = true; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'maaarch']); - $this->assertSame($isPasswordValid, false); - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'Maaarch']); - $this->assertSame($isPasswordValid, true); - - // complexityNumber - foreach ($rules as $key => $rule) { - if ($rule['label'] == 'complexityNumber') { - $rules[$key]['enabled'] = true; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'Maaarch']); - $this->assertSame($isPasswordValid, false); - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'Maaarch1']); - $this->assertSame($isPasswordValid, true); - - // complexitySpecial - foreach ($rules as $key => $rule) { - if ($rule['label'] == 'complexitySpecial') { - $rules[$key]['enabled'] = true; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'Maaarch1']); - $this->assertSame($isPasswordValid, false); - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'Maaarch1!']); - $this->assertSame($isPasswordValid, true); - - // reset - foreach ($rules as $key => $rule) { - if ($rule['label'] == 'complexitySpecial' || $rule['label'] == 'complexityNumber' || $rule['label'] == 'complexityUpper') { - $rules[$key]['enabled'] = false; - } - if ($rule['label'] == 'minLength') { - $rules[$key]['value'] = 6; - $rules[$key]['enabled'] = true; - } - } - - $fullRequest = \httpRequestCustom::addContentInBody(['rules' => $rules], $request); - $response = $passwordController->updateRules($fullRequest, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame($responseBody->success, 'success'); - - $isPasswordValid = $passwordController->isPasswordValid(['password' => 'maarch']); - $this->assertSame($isPasswordValid, true); - } -} diff --git a/test/unitTests/define.php b/test/unitTests/define.php index e273d06367ec4e037f84bc8877f75548136f76db..46ef9b1024ba21038cf00e4b52f25301cfc77095 100644 --- a/test/unitTests/define.php +++ b/test/unitTests/define.php @@ -9,7 +9,8 @@ require_once 'vendor/autoload.php'; -$userId = 'superadmin'; +$login = 'jjane'; +$_SERVER['CONFIG_DIR'] = "/var/www/html/MaarchParapheur/config/"; $language = \SrcCore\models\CoreConfigModel::getLanguage(); require_once("src/core/lang/lang-{$language}.php");