From a32cc2c02cb2705e6a72ffaa5f8fb1c9e76b3f9a Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Tue, 25 Jun 2019 10:15:08 +0100 Subject: [PATCH] FIX #10733 TIME 1:15 fix document TU --- lang/en.json | 1 + lang/fr.json | 3 +- phpunit.xml | 2 +- .../controllers/DocumentController.php | 1 - .../app/document/DocumentControllerTest.php | 67 ++++++++----------- 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/lang/en.json b/lang/en.json index 9197305394..c7baddf68f 100755 --- a/lang/en.json +++ b/lang/en.json @@ -196,6 +196,7 @@ "privilegeUpdated" : "Privilege added", "removedFromGroup" : "User removed from group", "manage_groups" : "Groups", + "manage_groupsDesc": "Add / Update / Delete groups in application.", "manage_connections" : "Connections", "manage_connectionsDesc" : "Manage all available connections modes in application.", "defaultConnection" : "Default", diff --git a/lang/fr.json b/lang/fr.json index ec1bcd77b7..010ed83d83 100755 --- a/lang/fr.json +++ b/lang/fr.json @@ -195,8 +195,9 @@ "groupdeleted" : "Groupe supprimé", "groupUpdated" : "Groupe mis à jour", "privilegeUpdated" : "Privilège Ajouté", - "removedFromGroup" : "User removed from group", + "removedFromGroup" : "Utilisateur retiré du groupe", "manage_groups" : "Groupes", + "manage_groupsDesc": "Ajouter / Modifier / Supprimer les groupes de l'application.", "manage_connections" : "Connexions", "manage_connectionsDesc" : "Administrer les différents modes de connexion disponibles de l'application.", "defaultConnection" : "Standard", diff --git a/phpunit.xml b/phpunit.xml index 7f296e45b0..6a5511deba 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,7 +5,7 @@ <!-- <file>test/unitTests/core/AuthenticationControllerTest.php</file> --> <file>test/unitTests/core/PasswordControllerTest.php</file> <file>test/unitTests/app/user/UserControllerTest.php</file> - <!-- <file>test/unitTests/app/document/DocumentControllerTest.php</file> --> + <file>test/unitTests/app/document/DocumentControllerTest.php</file> <file>test/unitTests/app/group/GroupControllerTest.php</file> </testsuite> </testsuites> diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index f402eb167d..400de979e7 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -29,7 +29,6 @@ use Slim\Http\Request; use Slim\Http\Response; use SrcCore\models\DatabaseModel; use SrcCore\models\ValidatorModel; -use User\controllers\UserController; use User\models\UserModel; use History\controllers\HistoryController; use Workflow\models\WorkflowModel; diff --git a/test/unitTests/app/document/DocumentControllerTest.php b/test/unitTests/app/document/DocumentControllerTest.php index 3437e16ec1..e30711a7ed 100755 --- a/test/unitTests/app/document/DocumentControllerTest.php +++ b/test/unitTests/app/document/DocumentControllerTest.php @@ -25,12 +25,17 @@ class DocumentControllerTest extends TestCase 'title' => 'Mon Courrier', 'reference' => '2018/CR/7', 'description' => 'Mon premier courrier parapheur', - 'mode' => 'SIGN', - 'processingUser' => 'jjane@maarch.com', + 'encodedDocument' => base64_encode(file_get_contents('test/unitTests/samples/testPdf.zip')), 'sender' => 'Oliver Queen', 'deadline' => '2018-12-25', + 'workflow' => [[ + "processingUser" => "ccornillac@maarch.com", + "mode" => "visa" + ], [ + "processingUser" => "jjane@maarch.com", + "mode" => "visa" + ]], 'metadata' => ['Entité' => 'QE', 'Destinataire' => 'Barry Allen', 'priorité' => 'Urgent'], - 'encodedDocument' => base64_encode(file_get_contents('test/unitTests/samples/testPdf.zip')), 'attachments' => [[ 'encodedDocument' => base64_encode(file_get_contents('test/unitTests/samples/testPdf.zip')), 'title' => 'Ma pj de mon courrier', @@ -58,7 +63,8 @@ class DocumentControllerTest extends TestCase $this->assertInternalType('array', $responseBody->documents); $this->assertNotEmpty($responseBody->documents); - + $this->assertInternalType('int', $responseBody->count); + $this->assertNotEmpty($responseBody->count); $fullRequest = $request->withQueryParams(['mode' => 'SIGN']); $response = $documentController->get($fullRequest, new \Slim\Http\Response()); @@ -70,6 +76,9 @@ class DocumentControllerTest extends TestCase public function testGetById() { + // Wait thumbnail generation + sleep(10); + $documentController = new \Document\controllers\DocumentController(); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); @@ -80,11 +89,14 @@ class DocumentControllerTest extends TestCase $this->assertSame('2018/CR/7', $responseBody->document->reference); $this->assertSame('Mon Courrier', $responseBody->document->title); - $this->assertSame('SIGN', $responseBody->document->mode); - $this->assertSame(1, $responseBody->document->status); $this->assertSame('Oliver Queen', $responseBody->document->sender); - $this->assertSame('jjane@maarch.com', $responseBody->document->processingUser); - $this->assertInternalType('string', $responseBody->document->encodedDocument); + $this->assertInternalType('array', $responseBody->document->metadata); + $this->assertNotEmpty($responseBody->document->metadata); + $this->assertInternalType('array', $responseBody->document->workflow); + $this->assertInternalType('int', $responseBody->document->workflow[0]->userId); + $this->assertSame(2, $responseBody->document->workflow[0]->userId); + $this->assertSame('visa', $responseBody->document->workflow[0]->mode); + $this->assertNotEmpty($responseBody->document->workflow); $this->assertInternalType('array', $responseBody->document->attachments); $this->assertNotEmpty($responseBody->document->attachments); $this->assertNotEmpty($responseBody->document->attachments[0]->id); @@ -108,7 +120,7 @@ class DocumentControllerTest extends TestCase $responseBody = json_decode((string)$response->getBody()); $this->assertSame('2018/ZZ/10', $responseBody->attachment->reference); - $this->assertSame('Ma pj de mon courrier', $responseBody->attachment->subject); + $this->assertSame('Ma pj de mon courrier', $responseBody->attachment->title); $this->assertInternalType('string', $responseBody->attachment->encodedDocument); $response = $attachmentController->getById($request, new \Slim\Http\Response(), ['id' => -1]); @@ -117,20 +129,6 @@ class DocumentControllerTest extends TestCase $this->assertSame('Attachment does not exist', $responseBody->errors); } - public function testGetStatusById() - { - $documentController = new \Document\controllers\DocumentController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $documentController->getStatusById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('NEW', $responseBody->status->reference); - $this->assertSame('SIGN', $responseBody->status->mode); - } - public function testSetAction() { $documentController = new \Document\controllers\DocumentController(); @@ -160,35 +158,28 @@ class DocumentControllerTest extends TestCase ]; $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - $response = $documentController->setAction($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'actionId' => 5]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('success', $responseBody->success); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $documentController->getStatusById($request, new \Slim\Http\Response(), ['id' => self::$id]); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('VAL', $responseBody->status->reference); - $this->assertSame('SIGN', $responseBody->status->mode); // Error action $response = $documentController->setAction($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'actionId' => 203]); $responseBody = json_decode((string)$response->getBody()); $this->assertSame('Action does not exist', $responseBody->errors); + + // Success action + $response = $documentController->setAction($fullRequest, new \Slim\Http\Response(), ['id' => self::$id, 'actionId' => 1]); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertSame('success', $responseBody->success); } - public function testGetProcessedDocumentById() + public function testGetContent() { $documentController = new \Document\controllers\DocumentController(); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $documentController->getProcessedDocumentById($request, new \Slim\Http\Response(), ['id' => self::$id]); + $response = $documentController->getContent($request, new \Slim\Http\Response(), ['id' => self::$id]); $responseBody = json_decode((string)$response->getBody()); $this->assertNotEmpty($responseBody->encodedDocument); -- GitLab