From 54f3de6f195fdc15bd2145fc3fe6762a63ded837 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Tue, 31 Mar 2020 22:52:55 +0100 Subject: [PATCH] FEAT #13676 TIME 1 unit test --- phpunit.xml | 4 +- .../AdministrationControllerTest.php | 38 ++++++++++ .../ContentManagementControllerTest.php | 76 +++++++++++++++++++ test/unitTests/core/CoreControllerTest.php | 13 ---- 4 files changed, 117 insertions(+), 14 deletions(-) create mode 100755 test/unitTests/app/administration/AdministrationControllerTest.php create mode 100755 test/unitTests/app/contentManagement/ContentManagementControllerTest.php diff --git a/phpunit.xml b/phpunit.xml index cabbf261af5..29cc94d5914 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,6 +5,7 @@ <!--directory>test</directory--> <file>test/unitTests/app/home/HomeControllerTest.php</file> <file>test/unitTests/app/action/ActionControllerTest.php</file> + <file>test/unitTests/app/administration/AdministrationControllerTest.php</file> <file>test/unitTests/app/attachment/AttachmentControllerTest.php</file> <file>test/unitTests/core/AutocompleteControllerTest.php</file> <file>test/unitTests/core/AuthenticationControllerTest.php</file> @@ -13,6 +14,7 @@ <file>test/unitTests/app/contact/ContactCustomFieldControllerTest.php</file> <file>test/unitTests/app/contact/ContactGroupControllerTest.php</file> <file>test/unitTests/app/customField/CustomFieldControllerTest.php</file> + <file>test/unitTests/app/contentManagement/ContentManagementControllerTest.php</file> <file>test/unitTests/core/CoreControllerTest.php</file> <file>test/unitTests/app/docserver/DocserverControllerTest.php</file> <file>test/unitTests/app/doctype/DoctypeControllerTest.php</file> @@ -55,6 +57,6 @@ <logging> <log type="coverage-clover" target="test/unitTests/build/tests-clover.xml"/> <log type="junit" target="test/unitTests/build/tests-phpunit.xml"/> - <!-- <log type="coverage-html" target="test/unitTests/build" lowUpperBound="35" highLowerBound="70"/> --> + <log type="coverage-html" target="test/unitTests/build" lowUpperBound="35" highLowerBound="70"/> </logging> </phpunit> diff --git a/test/unitTests/app/administration/AdministrationControllerTest.php b/test/unitTests/app/administration/AdministrationControllerTest.php new file mode 100755 index 00000000000..e841104bd7d --- /dev/null +++ b/test/unitTests/app/administration/AdministrationControllerTest.php @@ -0,0 +1,38 @@ +<?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 AdministrationControllerTest +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +use PHPUnit\Framework\TestCase; + +class AdministrationControllerTest extends TestCase +{ + public function testGetDetails() + { + $GLOBALS['userId'] = 'bblier'; + $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); + $GLOBALS['id'] = $userInfo['id']; + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $administrationController = new \Administration\controllers\AdministrationController(); + $response = $administrationController->getDetails($request, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertNotNull($responseBody->count); + $this->assertIsInt($responseBody->count->users); + $this->assertIsInt($responseBody->count->groups); + $this->assertIsInt($responseBody->count->entities); + + $GLOBALS['userId'] = 'superadmin'; + $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); + $GLOBALS['id'] = $userInfo['id']; + } +} diff --git a/test/unitTests/app/contentManagement/ContentManagementControllerTest.php b/test/unitTests/app/contentManagement/ContentManagementControllerTest.php new file mode 100755 index 00000000000..6d03984b9fb --- /dev/null +++ b/test/unitTests/app/contentManagement/ContentManagementControllerTest.php @@ -0,0 +1,76 @@ +<?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 ContentManagementControllerTest +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +use PHPUnit\Framework\TestCase; + +class ContentManagementControllerTest extends TestCase +{ + private static $uniqueId = null; + + public function testRenderJnlp() + { + $contentManagementController = new \ContentManagement\controllers\JnlpController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $contentManagementController->renderJnlp($request, new \Slim\Http\Response(), ['jnlpUniqueId' => 'superadmin_maarchCM_12345.js']); + $responseBody = json_decode((string)$response->getBody()); + $this->assertSame('File extension forbidden', $responseBody->errors); + } + + public function testGenerateJnlp() + { + $contentManagementController = new \ContentManagement\controllers\JnlpController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $contentManagementController->generateJnlp($request, new \Slim\Http\Response(), ['jnlpUniqueId' => 'superadmin_maarchCM_12345.js']); + $responseBody = json_decode((string)$response->getBody()); + $this->assertNotNull($responseBody->generatedJnlp); + $this->assertNotNull($responseBody->jnlpUniqueId); + + self::$uniqueId = $responseBody->jnlpUniqueId; + } + + public function testIsLockFileExisting() + { + $contentManagementController = new \ContentManagement\controllers\JnlpController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $contentManagementController->isLockFileExisting($request, new \Slim\Http\Response(), ['jnlpUniqueId' => self::$uniqueId]); + $responseBody = json_decode((string)$response->getBody()); + $this->assertNotNull($responseBody->lockFileFound); + $this->assertIsBool($responseBody->lockFileFound); + $this->assertSame(true, $responseBody->lockFileFound); + $this->assertNotNull($responseBody->fileTrunk); + $this->assertSame("tmp_file_".$GLOBALS['id']."_".self::$uniqueId, $responseBody->fileTrunk); + } + + public function testGetDocumentEditorConfig() + { + $documentEditorController = new \ContentManagement\controllers\DocumentEditorController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + + $response = $documentEditorController->get($request, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertIsArray($responseBody); + foreach ($responseBody as $value) { + $this->assertContains($value, ['java', 'onlyoffice']); + } + } +} diff --git a/test/unitTests/core/CoreControllerTest.php b/test/unitTests/core/CoreControllerTest.php index 9cdd0e4cc3c..d3e3fdd5f3c 100755 --- a/test/unitTests/core/CoreControllerTest.php +++ b/test/unitTests/core/CoreControllerTest.php @@ -56,17 +56,4 @@ class CoreControllerTest extends TestCase $this->assertIsArray($responseBody->user->groups); $this->assertIsArray($responseBody->user->entities); } - - public function testrenderJnlp() - { - $coreController = new \ContentManagement\controllers\JnlpController(); - - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - - $response = $coreController->renderJnlp($request, new \Slim\Http\Response(), ['jnlpUniqueId' => 'superadmin_maarchCM_12345.js']); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertSame('File extension forbidden', $responseBody->errors); - } } -- GitLab