Skip to content
Snippets Groups Projects
ResControllerTest.php 95.9 KiB
Newer Older
  • Learn to ignore specific revisions
  •         $res = \Resource\models\ResModel::getById(['resId' => self::$id3, 'select' => ['*']]);
            $this->assertIsArray($res);
            $this->assertEmpty($res);
    
    
        public function testCreateMultipleDocument()
        {
    
            $GLOBALS['login'] = 'cchaplin';
            $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
    
            $GLOBALS['id'] = $userInfo['id'];
    
    
            $resController = new \Resource\controllers\ResController();
    
            $aNewDocument = [
                1 => [
                    102,
                    'poiuytre1357nbvc',
                    'NEW'
                ],
                2 => [
                    103,
                    'poiuytre1379nbvc',
                    'COU'
                ],
                3 => [
                    104,
                    'poiuytre1391nbvc',
                    'ENVDONE'
                ]
            ];
    
    
            $entity = \Entity\models\EntityModel::getByEntityId(['entityId' => 'PJS', 'select' => ['id']]);
    
            $this->assertIsInt($entity['id']);
    
            foreach ($aNewDocument as $key => $value) {
                $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
                $request        = \Slim\Http\Request::createFromEnvironment($environment);
    
    Damien's avatar
    Damien committed
                $fileContent = file_get_contents('test/unitTests/samples/test.txt');
    
                $encodedFile = base64_encode($fileContent);
                $aArgs = [
    
                    'modelId'       => 1,
    
                    'status'        => $value[2],
                    'encodedFile'   => $encodedFile,
    
                    'confidentiality'   => false,
    
                    'documentDate'  => '2019-01-01 17:18:47',
                    'arrivalDate'   => '2019-01-01 17:18:47',
                    'doctype'       => $value[0],
    
                    'destination'   => $entity['id'],
                    'initiator'     => $entity['id'],
    
                    'subject'       => $key .' Breaking News : 12345 Superman is alive - PHP unit',
    
                    'typist'        => 19,
    
                    'priority'      => $value[1],
    
                    'diffusionList' => [['id' => 19, 'type' => 'user', 'mode' => 'dest'], ['id' => 20, 'type' => 'user', 'mode' => 'cc']],
                    'senders'       => [['type' => 'contact', 'id' => 1], ['type' => 'user', 'id' => 21], ['type' => 'entity', 'id' => 1]],
                    'recipients'    => [['type' => 'contact', 'id' => 2], ['type' => 'user', 'id' => 19], ['type' => 'entity', 'id' => 2]],
                    'tags'          => [1, 2],
                    'folders'       => [1, 2],
                    'customFields'  => [4 => 'référence externe']
    
                $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
    
                $response     = $resController->create($fullRequest, new \Slim\Http\Response());
    
                $responseBody = json_decode((string)$response->getBody());
                $newId = $responseBody->resId;
    
                $this->assertIsInt($newId);
    
                $GLOBALS['resources'][] = $newId;
    
            $GLOBALS['login'] = 'superadmin';
            $userInfo = \User\models\UserModel::getByLogin(['login' => $GLOBALS['login'], 'select' => ['id']]);
    
            $GLOBALS['id'] = $userInfo['id'];
    
    
        public function testGetBytesSizeFromPhpIni()
        {
            $size = '1K';
            $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
            $this->assertSame(1024, $byteSize );
    
            $size = '1M';
            $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
            $this->assertSame(1048576, $byteSize );
    
            $size = '1G';
            $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
            $this->assertSame(1073741824, $byteSize );
    
            $size = 1;
            $byteSize = \Resource\controllers\StoreController::getBytesSizeFromPhpIni(['size' => $size]);
            $this->assertSame(1, $byteSize );
        }
    
        public function testGetFormattedSizeFromBytes()
        {
            $size = 1073741824 + 1;
            $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
            $this->assertSame(round($size / 1073741824) . ' Go', $formatted );
    
            $size = 1048576 + 1;
            $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
            $this->assertSame(round($size / 1048576) . ' Mo', $formatted );
    
            $size = 1024 + 1;
            $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
            $this->assertSame(round($size / 1024) . ' Ko', $formatted );
    
            $size = 1;
            $formatted = \Resource\controllers\StoreController::getFormattedSizeFromBytes(['size' => $size]);
            $this->assertSame('1 o', $formatted );
        }