From b5dc3aa44d4de4be519b79b2f4547957c0c1b1e8 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Fri, 9 Jun 2017 15:37:31 +0100 Subject: [PATCH] testU --- core/Controllers/ParametersController.php | 2 +- core/Test/ParametersControllerTest.php | 217 +++++++++------------- sonar-project.properties | 2 +- 3 files changed, 93 insertions(+), 128 deletions(-) diff --git a/core/Controllers/ParametersController.php b/core/Controllers/ParametersController.php index 911141d33ca..1eb4fab9dd7 100644 --- a/core/Controllers/ParametersController.php +++ b/core/Controllers/ParametersController.php @@ -65,7 +65,7 @@ use Core\Models\ParametersModel; return $response->withJson($obj); } - public function update(RequestInterface $request, ResponseInterface $response) + public function update(RequestInterface $request, ResponseInterface $response, $aArgs) { $errors = $this->control($request, 'update'); diff --git a/core/Test/ParametersControllerTest.php b/core/Test/ParametersControllerTest.php index 46b8c4c7b98..bcd8c9740c8 100644 --- a/core/Test/ParametersControllerTest.php +++ b/core/Test/ParametersControllerTest.php @@ -20,112 +20,98 @@ class ParametersControllerTest extends \PHPUnit_Framework_TestCase $query .= 'param_value_string=abcd&'; $query .= 'description=papa'; - $environment = \Slim\Http\Environment::mock( - [ - 'REQUEST_METHOD' => 'POST', - 'QUERY_STRING' => $query, - ] - ); + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => $query, + ]); $parameter = new \Core\Controllers\ParametersController(); - $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); $compare = '[{"id":"TEST",' .'"description":"papa",' .'"param_value_string":"abcd",' .'"param_value_int":null,' .'"param_value_date":null}]'; - $this->assertSame($compare,(string)$response->getBody()); - $client = new \GuzzleHttp\Client([ - 'base_uri' => $_SESSION['config']['coreurl'] . 'rest/parameters', - // You can set any number of default request options. - 'timeout' => 2.0, - ]); + $this->assertSame($compare,(string)$response->getBody()); //TEST EXISTE DEJA - $aArgs = [ - 'id' => 'TEST', - 'description' => null, - 'param_value_string' => null, - 'param_value_int' => 1234, - 'param_value_date' => null - ]; - - $response = $client->request('POST', $_SESSION['config']['coreurl'] . 'rest/parameters', [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs - ]); + + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); $compare = '{"errors":["Identifiant TEST existe d\u00e9j\u00e0 !"]}'; $this->assertSame($compare,(string)$response->getBody()); //AUCUN PARAMETRE - - $aArgs = [ - 'id' => 'TEST3', - 'description' => null, - 'param_value_string' => null, - 'param_value_int' => null, - 'param_value_date' => null - ]; - - $response = $client->request('POST', $_SESSION['config']['coreurl'] . 'rest/parameters', [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + + $query = 'id=TEST3&'; + $query .= 'param_value_string=&'; + $query .= 'param_value_int=&'; + $query .= 'param_value_date=&'; + $query .= 'description='; + + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => $query, ]); + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + $compare = '{"errors":["_PARAM_VALUE_IS_EMPTY"]}'; $this->assertSame($compare,(string)$response->getBody()); //AUCUN ARGUMENTS - $aArgs = [ ]; - $response = $client->request('POST', $_SESSION['config']['coreurl'] . 'rest/parameters', [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + $query = ''; + + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => $query, ]); + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + $compare = '{"errors":["_ID_IS_EMPTY_CONTROLLER","_PARAM_VALUE_IS_EMPTY"]}'; $this->assertSame($compare,(string)$response->getBody()); //DATE MAUVAIS FORMAT - $aArgs = [ - 'id' => 'TEST4', - 'description' => null, - 'param_value_string' => null, - 'param_value_int' => null, - 'param_value_date' => '123456' - ]; - - $response = $client->request('POST', $_SESSION['config']['coreurl'] . 'rest/parameters', [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + $query = 'id=TEST4&'; + $query .= 'param_value_string=&'; + $query .= 'param_value_int=&'; + $query .= 'param_value_date=123456&'; + $query .= 'description='; + + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => $query, ]); + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + $compare = '{"errors":["PARAMETRE DATE INVALIDE."]}'; $this->assertSame($compare,(string)$response->getBody()); //TEST ID MAUVAIS FORMAT (REGEX) - $aArgs = [ - 'id' => 'A*-#==', - 'description' => "*///*//", - 'param_value_string' => "//-//**", - 'param_value_int' => null, - 'param_value_date' => null - ]; - - $response = $client->request('POST', $_SESSION['config']['coreurl'] . 'rest/parameters', [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + $query = 'id=A*-#==&'; + $query .= 'param_value_string=//-//**&'; + $query .= 'param_value_int=&'; + $query .= 'param_value_date=&'; + $query .= 'description=*///*//'; + + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => $query, ]); - $compare ='{"errors":["ID INVALIDE","DESCRIPTION INVALIDE","PARAM STRING INVALIDE"]}'; + $response = $parameter->create(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + + $compare = '{"errors":["ID INVALIDE","DESCRIPTION INVALIDE","PARAM STRING INVALIDE"]}'; $this->assertSame($compare,(string)$response->getBody()); } @@ -133,42 +119,35 @@ class ParametersControllerTest extends \PHPUnit_Framework_TestCase { $parameters = new \Core\Controllers\ParametersController(); - $environment = \Slim\Http\Environment::mock( - [ - 'REQUEST_METHOD' => 'GET', - ] - ); + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'GET' + ]); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = new \Slim\Http\Response(); - $response = $parameters->getList($request, $response); + $response = $parameters->getList(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); $this->assertNotNull((string)$response->getBody()); } public function testGetById() - { + { + $query = 'id=TEST'; - $aArgs = [ - 'id' => 'TEST' - ]; + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => $query, + ]); - $client = new \GuzzleHttp\Client([ - 'base_uri' => $_SESSION['config']['coreurl'] . 'rest/parameters', - // You can set any number of default request options. - 'timeout' => 2.0, - ]); + $parameters = new \Core\Controllers\ParametersController(); + $response = $parameters->getById(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response(), ['id' => 'TEST']); - $response = $client->request('GET', $_SESSION['config']['coreurl'] . 'rest/parameters/'.$aArgs['id'], [ - 'auth'=> ['superadmin','superadmin'] - ]); - $compare = '[[{"id":"TEST",' - .'"description":null,' + $compare = '[{"id":"TEST",' + .'"description":"papa",' .'"param_value_string":"abcd",' .'"param_value_int":null,' - .'"param_value_date":null}]]'; + .'"param_value_date":null}]'; $this->assertNotNull((string)$response->getBody()); + $this->assertSame($compare,(string)$response->getBody()); } public function testUpdate() @@ -177,40 +156,32 @@ class ParametersControllerTest extends \PHPUnit_Framework_TestCase $query = 'id=TEST&'; $query .= 'description=TEST AFTER UP'; - $environment = \Slim\Http\Environment::mock( - [ - 'REQUEST_METHOD' => 'PUT', - 'QUERY_STRING' => $query, - ] - ); + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'PUT', + 'QUERY_STRING' => $query, + ]); $parameter = new \Core\Controllers\ParametersController(); - $response = $parameter->update(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response()); + $response = $parameter->update(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response(), ['id' => 'TEST']); - $compare = '[{"id":"TEST",' - .'"description":"TEST AFTER UP",' - .'"param_value_string":"abcd",' - .'"param_value_int":null,' - .'"param_value_date":null}]'; + $compare = '[{"id":"TEST",' + .'"description":"TEST AFTER UP",' + .'"param_value_string":"abcd",' + .'"param_value_int":null,' + .'"param_value_date":null}]'; $this->assertSame((string)$response->getBody(), $compare); //TEST ID NULL + $query = 'id=NEWWW'; - $client = new \GuzzleHttp\Client([ - 'base_uri' => $_SESSION['config']['coreurl'] . 'rest/parameters', - // You can set any number of default request options. - 'timeout' => 2.0, - ]); - - $aArgs = [ - 'id' => 'NEW' - ]; - $response = $client->request('PUT', $_SESSION['config']['coreurl'] . 'rest/parameters/'.$aArgs['id'], [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'PUT', + 'QUERY_STRING' => $query, ]); + $response = $parameter->update(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response(), ['id' => 'NEWWW']); + $compare = '{"errors":["Identifiant n\'existe pas"]}'; $this->assertSame($compare,(string)$response->getBody()); @@ -219,24 +190,18 @@ class ParametersControllerTest extends \PHPUnit_Framework_TestCase public function testDelete() { - $aArgs = [ - 'id'=> 'TEST' - ]; - - $client = new \GuzzleHttp\Client([ - 'base_uri' => $_SESSION['config']['coreurl'] . 'rest/parameters', - // You can set any number of default request options. - 'timeout' => 2.0, - ]); - - $response = $client->request('DELETE', $_SESSION['config']['coreurl'] . 'rest/parameters/'.$aArgs['id'], [ - 'auth' => ['superadmin','superadmin'], - 'form_params' => $aArgs + $query = 'id=TEST'; + + $environment = \Slim\Http\Environment::mock([ + 'REQUEST_METHOD' => 'DELETE', + 'QUERY_STRING' => $query, ]); + + $parameter = new \Core\Controllers\ParametersController(); + $response = $parameter->delete(\Slim\Http\Request::createFromEnvironment($environment), new \Slim\Http\Response(), ['id' => 'TEST']); + $compare = 'true'; $this->assertSame($compare,(string)$response->getBody()); } } - -?> \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index 4a75593e4f3..55ccee7a4c5 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,7 +6,7 @@ sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. -sonar.sources=. +sonar.sources=core , apps/maarch_entreprise/Models , modules/visa/Models , modules/visa/Controllers , modules/attachments/Controllers , modules/attachments/Models , modules/basket/Models , modules/entities/Controllers , modules/entities/Models , modules/notes/Models # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 -- GitLab