Skip to content
Snippets Groups Projects
Verified Commit f76e9138 authored by Damien's avatar Damien
Browse files

FEAT #11691 TIME 0:20 Unit tests

parent e08685ac
No related branches found
No related tags found
No related merge requests found
......@@ -171,6 +171,7 @@ class AttachmentController
return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
}
$body['id'] = $args['id'];
$isStored = StoreController::storeAttachment($body);
if (empty($isStored) || !empty($isStored['errors'])) {
return $response->withStatus(500)->withJson(['errors' => '[AttachmentController update] ' . $isStored['errors']]);
......
......@@ -40,6 +40,12 @@ class AttachmentControllerTest extends TestCase
self::$id = $responseBody->id;
$this->assertInternalType('int', self::$id);
$response = $attachmentController->create($fullRequest, new \Slim\Http\Response());
$this->assertSame(400, $response->getStatusCode());
$response = (array)json_decode((string)$response->getBody());
$this->assertSame('Body type is empty or not a string', $response['errors']);
// READ
$res = \Attachment\models\AttachmentModel::getById(['id' => self::$id, 'select' => ['*']]);
......@@ -60,4 +66,71 @@ class AttachmentControllerTest extends TestCase
$this->assertNotNull($res['filesize']);
$this->assertNull($res['origin_id']);
}
public function testUpdate()
{
$attachmentController = new \Attachment\controllers\AttachmentController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'title' => 'La plus chétive cabane renferme plus de vertus que les palais des rois.',
'type' => 'response_project',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $attachmentController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$this->assertSame(204, $response->getStatusCode());
unset($aArgs['type']);
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $attachmentController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$this->assertSame(400, $response->getStatusCode());
$response = (array)json_decode((string)$response->getBody());
$this->assertSame('Body type is empty or not a string', $response['errors']);
// READ
$response = $attachmentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$res = (array)json_decode((string)$response->getBody());
$this->assertInternalType('array', $res);
$this->assertSame($aArgs['title'], $res['title']);
$this->assertSame($aArgs['type'], $res['type']);
$this->assertSame('A_TRA', $res['status']);
$this->assertSame(1, $res['relation']);
}
public function testDelete()
{
$attachmentController = new \Attachment\controllers\AttachmentController();
// DELETE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $attachmentController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
$this->assertSame(204, $response->getStatusCode());
// DELETE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $attachmentController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
$res = (array)json_decode((string)$response->getBody());
$this->assertSame(400, $response->getStatusCode());
$this->assertSame('Attachment does not exist', $res['errors']);
// READ
$response = $attachmentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$res = (array)json_decode((string)$response->getBody());
$this->assertSame(400, $response->getStatusCode());
$this->assertSame('Attachment does not exist', $res['errors']);
}
}
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