Verified Commit c5525720 authored by Damien's avatar Damien

FEAT #11691 TIME 0:30 Create unit test + fix

parent 49ac450d
......@@ -25,7 +25,6 @@ use Group\controllers\PrivilegeController;
use History\controllers\HistoryController;
use Resource\controllers\ResController;
use Resource\controllers\StoreController;
use Resource\models\ChronoModel;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use setasign\Fpdi\Tcpdf\Fpdi;
......@@ -232,7 +231,7 @@ class AttachmentController
}
$attachment = AttachmentModel::get([
'select' => ['res_id', 'docserver_id', 'path', 'filename'],
'select' => ['res_id', 'docserver_id', 'path', 'filename', 'res_id_master'],
'where' => ['res_id = ?', 'status not in (?)'],
'data' => [$args['id'], ['DEL']],
'limit' => 1
......
<?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 AttachmentControllerTest extends TestCase
{
private static $id = null;
public function testCreate()
{
$attachmentController = new \Attachment\controllers\AttachmentController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$fileContent = file_get_contents('test/unitTests/samples/test.txt');
$encodedFile = base64_encode($fileContent);
$aArgs = [
'title' => 'Nulle pierre ne peut être polie sans friction, nul homme ne peut parfaire son expérience sans épreuve.',
'type' => 'response_project',
'chrono' => 'MAARCH/2019D/24',
'resIdMaster' => 100,
'encodedFile' => $encodedFile,
'format' => 'txt',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $attachmentController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->id;
$this->assertInternalType('int', self::$id);
// READ
$res = \Attachment\models\AttachmentModel::getById(['id' => self::$id, 'select' => ['*']]);
$this->assertInternalType('array', $res);
$this->assertSame($aArgs['title'], $res['title']);
$this->assertSame($aArgs['type'], $res['attachment_type']);
$this->assertSame('txt', $res['format']);
$this->assertSame('A_TRA', $res['status']);
$this->assertSame('superadmin', $res['typist']);
$this->assertSame(1, $res['relation']);
$this->assertSame($aArgs['chrono'], $res['identifier']);
$this->assertNotNull($res['path']);
$this->assertNotNull($res['filename']);
$this->assertNotNull($res['docserver_id']);
$this->assertNotNull($res['fingerprint']);
$this->assertNotNull($res['filesize']);
$this->assertNull($res['origin_id']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment