mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-15 16:58:42 +00:00
parent
315cfa3b54
commit
e89b3efb32
89
tests/Controller/Api/ApiControllerCollectionTrait.php
Normal file
89
tests/Controller/Api/ApiControllerCollectionTrait.php
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Media\tests\Controller\Api;
|
||||||
|
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Utils\TestUtils;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
|
||||||
|
trait ApiControllerCollectionTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiCollectionCreate() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->getHeader()->setAccount(1);
|
||||||
|
$request->setData('name', 'Test Upload');
|
||||||
|
|
||||||
|
if (!\file_exists(__DIR__ . '/temp')) {
|
||||||
|
\mkdir(__DIR__ . '/temp');
|
||||||
|
}
|
||||||
|
|
||||||
|
\copy(__DIR__ . '/testFile1.txt', __DIR__ . '/temp/testFile1.txt');
|
||||||
|
\copy(__DIR__ . '/testFile2.txt', __DIR__ . '/temp/testFile2.txt');
|
||||||
|
|
||||||
|
$files = [
|
||||||
|
[
|
||||||
|
'error' => \UPLOAD_ERR_OK,
|
||||||
|
'type' => 'txt',
|
||||||
|
'name' => 'testFile1.txt',
|
||||||
|
'tmp_name' => __DIR__ . '/temp/testFile1.txt',
|
||||||
|
'size' => \filesize(__DIR__ . '/testFile1.txt'),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'error' => \UPLOAD_ERR_OK,
|
||||||
|
'type' => 'txt',
|
||||||
|
'name' => 'testFile2.txt',
|
||||||
|
'tmp_name' => __DIR__ . '/temp/testFile2.txt',
|
||||||
|
'size' => \filesize(__DIR__ . '/testFile2.txt'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
TestUtils::setMember($request, 'files', $files);
|
||||||
|
|
||||||
|
$this->module->apiMediaUpload($request, $response);
|
||||||
|
|
||||||
|
if (\file_exists(__DIR__ . '/temp')) {
|
||||||
|
Directory::delete(__DIR__ . '/temp');
|
||||||
|
}
|
||||||
|
|
||||||
|
$media = [];
|
||||||
|
$createdMedia = $response->get('')['response'];
|
||||||
|
foreach ($createdMedia as $file) {
|
||||||
|
$media[] = $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->getHeader()->setAccount(1);
|
||||||
|
$request->setData('name', 'Test Collection');
|
||||||
|
$request->setData('virtualpath', '/');
|
||||||
|
$request->setData('media-list', \json_encode($media));
|
||||||
|
|
||||||
|
$this->module->apiCollectionCreate($request, $response);
|
||||||
|
|
||||||
|
$collection = $response->get('')['response'];
|
||||||
|
self::assertEquals('Test Collection', $collection);
|
||||||
|
self::assertCount(2, $collection->getSources());
|
||||||
|
}
|
||||||
|
}
|
||||||
110
tests/Controller/Api/ApiControllerMediaTrait.php
Normal file
110
tests/Controller/Api/ApiControllerMediaTrait.php
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Media\tests\Controller\Api;
|
||||||
|
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use Modules\Media\Models\UploadStatus;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
use phpOMS\Utils\TestUtils;
|
||||||
|
|
||||||
|
trait ApiControllerMediaTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testCreateDbEntries() : void
|
||||||
|
{
|
||||||
|
$status = [
|
||||||
|
[
|
||||||
|
'status' => UploadStatus::OK,
|
||||||
|
'extension' => 'png',
|
||||||
|
'filename' => 'logo.png',
|
||||||
|
'name' => 'logo.png',
|
||||||
|
'path' => 'Modules/tests/Media/Files/',
|
||||||
|
'size' => 90210,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'status' => UploadStatus::FAILED_HASHING,
|
||||||
|
'extension' => 'png',
|
||||||
|
'filename' => 'logo.png',
|
||||||
|
'name' => 'logo.png',
|
||||||
|
'path' => 'Modules/tests/Media/Files/',
|
||||||
|
'size' => 90210,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'status' => UploadStatus::OK,
|
||||||
|
'extension' => 'png',
|
||||||
|
'filename' => 'logo2.png',
|
||||||
|
'name' => 'logo2.png',
|
||||||
|
'path' => 'Modules/tests/Media/Files/',
|
||||||
|
'size' => 90210,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$ids = $this->module->createDbEntries($status, 1);
|
||||||
|
self::assertCount(2, $ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiMediaUpload() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->getHeader()->setAccount(1);
|
||||||
|
$request->setData('name', 'Test Upload');
|
||||||
|
|
||||||
|
if (!\file_exists(__DIR__ . '/temp')) {
|
||||||
|
\mkdir(__DIR__ . '/temp');
|
||||||
|
}
|
||||||
|
|
||||||
|
\copy(__DIR__ . '/testFile1.txt', __DIR__ . '/temp/testFile1.txt');
|
||||||
|
\copy(__DIR__ . '/testFile2.txt', __DIR__ . '/temp/testFile2.txt');
|
||||||
|
|
||||||
|
$files = [
|
||||||
|
[
|
||||||
|
'error' => \UPLOAD_ERR_OK,
|
||||||
|
'type' => 'txt',
|
||||||
|
'name' => 'testFile1.txt',
|
||||||
|
'tmp_name' => __DIR__ . '/temp/testFile1.txt',
|
||||||
|
'size' => \filesize(__DIR__ . '/testFile1.txt'),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'error' => \UPLOAD_ERR_OK,
|
||||||
|
'type' => 'txt',
|
||||||
|
'name' => 'testFile2.txt',
|
||||||
|
'tmp_name' => __DIR__ . '/temp/testFile2.txt',
|
||||||
|
'size' => \filesize(__DIR__ . '/testFile2.txt'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
TestUtils::setMember($request, 'files', $files);
|
||||||
|
|
||||||
|
$this->module->apiMediaUpload($request, $response);
|
||||||
|
|
||||||
|
if (\file_exists(__DIR__ . '/temp')) {
|
||||||
|
Directory::delete(__DIR__ . '/temp');
|
||||||
|
}
|
||||||
|
|
||||||
|
$media = $response->get('')['response'];
|
||||||
|
self::assertCount(2, $media);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,13 +15,14 @@ declare(strict_types=1);
|
||||||
namespace Modules\Media\tests\Controller;
|
namespace Modules\Media\tests\Controller;
|
||||||
|
|
||||||
use Model\CoreSettings;
|
use Model\CoreSettings;
|
||||||
use Modules\Media\Models\UploadStatus;
|
|
||||||
use phpOMS\Account\AccountManager;
|
use phpOMS\Account\AccountManager;
|
||||||
use phpOMS\Application\ApplicationAbstract;
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
use phpOMS\Dispatcher\Dispatcher;
|
use phpOMS\Dispatcher\Dispatcher;
|
||||||
use phpOMS\Event\EventManager;
|
use phpOMS\Event\EventManager;
|
||||||
use phpOMS\Module\ModuleManager;
|
use phpOMS\Module\ModuleManager;
|
||||||
use phpOMS\Router\WebRouter;
|
use phpOMS\Router\WebRouter;
|
||||||
|
use Modules\Media\tests\Controller\Api\ApiControllerMediaTrait;
|
||||||
|
use Modules\Media\tests\Controller\Api\ApiControllerCollectionTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|
@ -53,40 +54,6 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->module = $this->app->moduleManager->get('Media');
|
$this->module = $this->app->moduleManager->get('Media');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
use ApiControllerMediaTrait;
|
||||||
* @covers Modules\Media\Controller\ApiController
|
use ApiControllerCollectionTrait;
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testCreateDbEntries() : void
|
|
||||||
{
|
|
||||||
$status = [
|
|
||||||
[
|
|
||||||
'status' => UploadStatus::OK,
|
|
||||||
'extension' => 'png',
|
|
||||||
'filename' => 'logo.png',
|
|
||||||
'name' => 'logo.png',
|
|
||||||
'path' => 'Modules/tests/Media/Files/',
|
|
||||||
'size' => 90210,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'status' => UploadStatus::FAILED_HASHING,
|
|
||||||
'extension' => 'png',
|
|
||||||
'filename' => 'logo.png',
|
|
||||||
'name' => 'logo.png',
|
|
||||||
'path' => 'Modules/tests/Media/Files/',
|
|
||||||
'size' => 90210,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'status' => UploadStatus::OK,
|
|
||||||
'extension' => 'png',
|
|
||||||
'filename' => 'logo2.png',
|
|
||||||
'name' => 'logo2.png',
|
|
||||||
'path' => 'Modules/tests/Media/Files/',
|
|
||||||
'size' => 90210,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$ids = $this->module->createDbEntries($status, 1);
|
|
||||||
self::assertCount(2, $ids);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user