Skip to content
Snippets Groups Projects
Commit b5dc3aa4 authored by Florian Azizian's avatar Florian Azizian
Browse files

testU

parent f33cd44b
No related branches found
No related tags found
No related merge requests found
......@@ -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');
......
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment