diff --git a/core/Test/ReportControllerTest.php b/core/Test/ReportControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fda6d573c5e7711c5c9930982b70f801821d13e9 --- /dev/null +++ b/core/Test/ReportControllerTest.php @@ -0,0 +1,100 @@ +<?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/phpunit.xml b/phpunit.xml index da77dcd82fb708d22c2ed81a5a73cdd8c57c5273..0864bb1b9c673c66647e3c458777033e50c55fdd 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,10 +5,11 @@ <!--directory>core/Test</directory--> <!--file>core/Test/ActionControllerTest.php</file--> <file>core/Test/ResControllerTest.php</file> - <file>core/Test/PriorityControllerTest.php</file> - <file>core/Test/StatusControllerTest.php</file> <file>core/Test/UserControllerTest.php</file> <file>core/Test/BasketControllerTest.php</file> + <file>core/Test/PriorityControllerTest.php</file> + <file>core/Test/StatusControllerTest.php</file> + <file>core/Test/ReportControllerTest.php</file> <file>modules/convert/Test/ProcessConvertTest.php</file> <file>modules/convert/Test/ProcessFulltextTest.php</file> <file>modules/convert/Test/ProcessThumbnailsTest.php</file>