mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 17:28:41 +00:00
fix @covers
This commit is contained in:
parent
2755594d3c
commit
faf9083ebe
|
|
@ -61,9 +61,9 @@ final class Installer extends InstallerAbstract
|
||||||
throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore
|
throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$mediaData = \json_decode($mediaFile, true);
|
$mediaData = \json_decode($mediaFile, true) ?? [];
|
||||||
if ($mediaData === false) {
|
if ($mediaData === false) {
|
||||||
throw new \Exception();
|
throw new \Exception(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($mediaData as $media) {
|
foreach ($mediaData as $media) {
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,4 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'^.*/media/find.*$' => [
|
|
||||||
[
|
|
||||||
'dest' => '\Modules\Media\Controller\ApiController:apiMediaFind',
|
|
||||||
'verb' => RouteVerb::GET,
|
|
||||||
'permission' => [
|
|
||||||
'module' => ApiController::MODULE_NAME,
|
|
||||||
'type' => PermissionType::READ,
|
|
||||||
'state' => PermissionState::MEDIA,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -71,30 +71,6 @@ use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||||
*/
|
*/
|
||||||
final class ApiController extends Controller
|
final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Api method to find media
|
|
||||||
*
|
|
||||||
* @param RequestAbstract $request Request
|
|
||||||
* @param ResponseAbstract $response Response
|
|
||||||
* @param mixed $data Generic data
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function apiMediaFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
|
||||||
{
|
|
||||||
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
|
|
||||||
$response->set(
|
|
||||||
$request->getUri()->__toString(),
|
|
||||||
\array_values(
|
|
||||||
MediaMapper::find((string) ($request->getData('search') ?? ''))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api method to upload media file.
|
* Api method to upload media file.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ use Modules\Media\Models\Media;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
use Modules\Media\Models\NullMedia;
|
use Modules\Media\Models\NullMedia;
|
||||||
use Modules\Media\Views\MediaView;
|
use Modules\Media\Views\MediaView;
|
||||||
use phpOMS\Asset\AssetType;
|
|
||||||
use phpOMS\Contract\RenderableInterface;
|
use phpOMS\Contract\RenderableInterface;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
|
|
@ -89,24 +88,7 @@ final class BackendController extends Controller
|
||||||
*/
|
*/
|
||||||
protected static array $dependencies = [];
|
protected static array $dependencies = [];
|
||||||
|
|
||||||
/**
|
use FileUploaderTrait;
|
||||||
* Routing end-point for application behaviour.
|
|
||||||
*
|
|
||||||
* @param RequestAbstract $request Request
|
|
||||||
* @param ResponseAbstract $response Response
|
|
||||||
* @param mixed $data Generic data
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public static function setUpFileUploader(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
|
||||||
{
|
|
||||||
/** @var \phpOMS\Model\Html\Head $head */
|
|
||||||
$head = $response->get('Content')->getData('head');
|
|
||||||
$head->addAsset(AssetType::JSLATE, 'Modules/Media/Controller.js', ['type' => 'module']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Routing end-point for application behaviour.
|
* Routing end-point for application behaviour.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.4
|
* PHP Version 7.4
|
||||||
*
|
*
|
||||||
* @package Modules\Media\Models
|
* @package Modules\Media\Controller
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Media\Models;
|
namespace Modules\Media\Controller;
|
||||||
|
|
||||||
use phpOMS\Asset\AssetType;
|
use phpOMS\Asset\AssetType;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
|
@ -21,7 +21,7 @@ use phpOMS\Message\ResponseAbstract;
|
||||||
/**
|
/**
|
||||||
* Options trait.
|
* Options trait.
|
||||||
*
|
*
|
||||||
* @package Modules\Media\Models
|
* @package Modules\Media\Controller
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -38,8 +38,9 @@ trait FileUploaderTrait
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function setUpFileUploader(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
public function setUpFileUploaderTrait(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||||
{
|
{
|
||||||
$head = $response->getHead();
|
$head = $response->getHead();
|
||||||
$head->addAsset(AssetType::JS, '/Modules/Media/ModuleMedia.js');
|
$head->addAsset(AssetType::JS, '/Modules/Media/ModuleMedia.js');
|
||||||
|
|
@ -249,7 +249,7 @@ class Media implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function setPassword(?string $password) : void
|
public function setPassword(?string $password) : void
|
||||||
{
|
{
|
||||||
$this->password = $password;
|
$this->password = \password_hash($password, \PASSWORD_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -546,6 +546,8 @@ class Media implements \JsonSerializable
|
||||||
'hidden' => $this->hidden,
|
'hidden' => $this->hidden,
|
||||||
'path' => $this->path,
|
'path' => $this->path,
|
||||||
'absolute' => $this->isAbsolute,
|
'absolute' => $this->isAbsolute,
|
||||||
|
'createdBy' => $this->createdBy,
|
||||||
|
'createdAt' => $this->createdAt,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,10 @@ class MediaView extends View
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected function isCollectionFunction(Media $media, string $sub) : bool
|
protected function isCollectionFunction(Media $media, string $sub = null) : bool
|
||||||
{
|
{
|
||||||
return ($media->getExtension() === 'collection'
|
return ($media->getExtension() === 'collection'
|
||||||
&& !\is_file($media->getPath() . $sub))
|
&& !\is_file($media->getPath() . ($sub ?? '')))
|
||||||
|| (\is_dir($media->getPath())
|
|| (\is_dir($media->getPath())
|
||||||
&& ($sub === null || \is_dir($media->getPath() . $sub))
|
&& ($sub === null || \is_dir($media->getPath() . $sub))
|
||||||
);
|
);
|
||||||
|
|
@ -107,15 +107,16 @@ class MediaView extends View
|
||||||
*/
|
*/
|
||||||
protected function getFileContent(string $path) : string
|
protected function getFileContent(string $path) : string
|
||||||
{
|
{
|
||||||
$output = \file_get_contents($path);
|
if (!\is_file($path)) {
|
||||||
|
|
||||||
if ($output === false) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = \str_replace(["\r\n", "\r"], "\n", $output);
|
$output = \file_get_contents($path);
|
||||||
|
if ($output === false) {
|
||||||
|
return ''; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
return $output;
|
return \str_replace(["\r\n", "\r"], "\n", $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,12 +130,15 @@ class MediaView extends View
|
||||||
*/
|
*/
|
||||||
protected function lineContentFunction(string $path) : array
|
protected function lineContentFunction(string $path) : array
|
||||||
{
|
{
|
||||||
$output = \file_get_contents($path);
|
if (!\is_file($path)) {
|
||||||
|
|
||||||
if ($output === false) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output = \file_get_contents($path);
|
||||||
|
if ($output === false) {
|
||||||
|
return []; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
$output = \str_replace(["\r\n", "\r"], "\n", $output);
|
$output = \str_replace(["\r\n", "\r"], "\n", $output);
|
||||||
|
|
||||||
return \explode("\n", $output);
|
return \explode("\n", $output);
|
||||||
|
|
@ -150,7 +154,7 @@ class MediaView extends View
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected function isImageFile(Media $media, string $path) : bool
|
protected function isImageFile(Media $media, string $path = '') : bool
|
||||||
{
|
{
|
||||||
return FileUtils::getExtensionType($media->getExtension()) === ExtensionType::IMAGE
|
return FileUtils::getExtensionType($media->getExtension()) === ExtensionType::IMAGE
|
||||||
|| FileUtils::getExtensionType(File::extension($path)) === ExtensionType::IMAGE;
|
|| FileUtils::getExtensionType(File::extension($path)) === ExtensionType::IMAGE;
|
||||||
|
|
@ -166,7 +170,7 @@ class MediaView extends View
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected function isTextFile(Media $media, string $path) : bool
|
protected function isTextFile(Media $media, string $path = '') : bool
|
||||||
{
|
{
|
||||||
$mediaExtension = FileUtils::getExtensionType($media->getExtension());
|
$mediaExtension = FileUtils::getExtensionType($media->getExtension());
|
||||||
$pathExtension = FileUtils::getExtensionType(File::extension($path));
|
$pathExtension = FileUtils::getExtensionType(File::extension($path));
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,4 @@ class AdminTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
Installer::installExternal($GLOBALS['dbpool'], ['path' => 'invalid.json']);
|
Installer::installExternal($GLOBALS['dbpool'], ['path' => 'invalid.json']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidMediaInstallJsonFile() : void
|
|
||||||
{
|
|
||||||
$this->expectException(\Exception::class);
|
|
||||||
|
|
||||||
Installer::installExternal($GLOBALS['dbpool'], ['path' => 'invalidJson.json']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"test": [],
|
|
||||||
}
|
|
||||||
55
tests/Models/CollectionMapperTest.php
Normal file
55
tests/Models/CollectionMapperTest.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?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\Models;
|
||||||
|
|
||||||
|
use Modules\Admin\Models\NullAccount;
|
||||||
|
use Modules\Media\Models\Collection;
|
||||||
|
use Modules\Media\Models\CollectionMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class CollectionMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\CollectionMapper
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testCR() : void
|
||||||
|
{
|
||||||
|
$media = new Collection();
|
||||||
|
$media->setCreatedBy(new NullAccount(1));
|
||||||
|
$media->setDescription('desc');
|
||||||
|
$media->setDescriptionRaw('descRaw');
|
||||||
|
$media->setPath('some/path');
|
||||||
|
$media->setSize(11);
|
||||||
|
$media->setName('Collection');
|
||||||
|
$id = CollectionMapper::create($media);
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $media->getId());
|
||||||
|
self::assertEquals($id, $media->getId());
|
||||||
|
|
||||||
|
$mediaR = CollectionMapper::get($media->getId());
|
||||||
|
self::assertEquals($media->getCreatedAt()->format('Y-m-d'), $mediaR->getCreatedAt()->format('Y-m-d'));
|
||||||
|
self::assertEquals($media->getCreatedBy()->getId(), $mediaR->getCreatedBy()->getId());
|
||||||
|
self::assertEquals($media->getDescription(), $mediaR->getDescription());
|
||||||
|
self::assertEquals($media->getDescriptionRaw(), $mediaR->getDescriptionRaw());
|
||||||
|
self::assertEquals($media->getPath(), $mediaR->getPath());
|
||||||
|
self::assertEquals($media->isAbsolute(), $mediaR->isAbsolute());
|
||||||
|
self::assertEquals($media->getSize(), $mediaR->getSize());
|
||||||
|
self::assertEquals($media->getExtension(), $mediaR->getExtension());
|
||||||
|
self::assertEquals($media->getName(), $mediaR->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -131,4 +131,21 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->media->addSource($d = new NullMedia(4));
|
$this->media->addSource($d = new NullMedia(4));
|
||||||
self::assertEquals([$a, $b, $c, $d], $this->media->getSources());
|
self::assertEquals([$a, $b, $c, $d], $this->media->getSources());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\Collection
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testIteration() : void
|
||||||
|
{
|
||||||
|
$this->media->setSources([$a = new NullMedia(1), $b = new NullMedia(2), $c = new NullMedia(3)]);
|
||||||
|
|
||||||
|
foreach ($this->media as $key => $media) {
|
||||||
|
if ($media->getId() !== $key + 1) {
|
||||||
|
self::assertEquals($key + 1, $media->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertTrue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ namespace Modules\Media\tests\Models;
|
||||||
use Modules\Admin\Models\NullAccount;
|
use Modules\Admin\Models\NullAccount;
|
||||||
use Modules\Media\Models\Media;
|
use Modules\Media\Models\Media;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
|
use Modules\Media\Models\CollectionMapper;
|
||||||
|
use Modules\Media\Models\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|
@ -113,4 +115,74 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($media->getExtension(), $mediaR->getExtension());
|
self::assertEquals($media->getExtension(), $mediaR->getExtension());
|
||||||
self::assertEquals($media->getName(), $mediaR->getName());
|
self::assertEquals($media->getName(), $mediaR->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\MediaMapper
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testGetVirtualPath() : void
|
||||||
|
{
|
||||||
|
$media = new Media();
|
||||||
|
$media->setCreatedBy(new NullAccount(1));
|
||||||
|
$media->setDescription('desc');
|
||||||
|
$media->setPath('https://avatars0.githubusercontent.com/u/16034994');
|
||||||
|
$media->setVirtualPath('/test/path');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
$media->setSize(11);
|
||||||
|
$media->setExtension('png');
|
||||||
|
$media->setName('Absolute path');
|
||||||
|
$id = MediaMapper::create($media);
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $media->getId());
|
||||||
|
self::assertEquals($id, $media->getId());
|
||||||
|
|
||||||
|
$found = MediaMapper::getByVirtualPath($media->getVirtualPath());
|
||||||
|
$mediaR = \reset($found);
|
||||||
|
self::assertEquals($media->getCreatedAt()->format('Y-m-d'), $mediaR->getCreatedAt()->format('Y-m-d'));
|
||||||
|
self::assertEquals($media->getCreatedBy()->getId(), $mediaR->getCreatedBy()->getId());
|
||||||
|
self::assertEquals($media->getDescription(), $mediaR->getDescription());
|
||||||
|
self::assertEquals($media->getPath(), $mediaR->getPath());
|
||||||
|
self::assertEquals($media->isAbsolute(), $mediaR->isAbsolute());
|
||||||
|
self::assertEquals($media->getSize(), $mediaR->getSize());
|
||||||
|
self::assertEquals($media->getExtension(), $mediaR->getExtension());
|
||||||
|
self::assertEquals($media->getName(), $mediaR->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\MediaMapper
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testParentcollection() : void
|
||||||
|
{
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->setCreatedBy(new NullAccount(1));
|
||||||
|
$collection->setDescription('desc');
|
||||||
|
$collection->setDescriptionRaw('descRaw');
|
||||||
|
$collection->setPath('some/path');
|
||||||
|
$collection->setVirtualPath('/virtual/path');
|
||||||
|
$collection->setSize(11);
|
||||||
|
$collection->setName('Collection');
|
||||||
|
$idCollection = CollectionMapper::create($collection);
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $collection->getId());
|
||||||
|
self::assertEquals($idCollection, $collection->getId());
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setCreatedBy(new NullAccount(1));
|
||||||
|
$media->setDescription('desc');
|
||||||
|
$media->setPath('https://avatars0.githubusercontent.com/u/16034994');
|
||||||
|
$media->setVirtualPath('/virtual/path/Collection');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
$media->setSize(11);
|
||||||
|
$media->setExtension('png');
|
||||||
|
$media->setName('Absolute path');
|
||||||
|
$idMedia = MediaMapper::create($media);
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $media->getId());
|
||||||
|
self::assertEquals($idMedia, $media->getId());
|
||||||
|
|
||||||
|
$collectionR = MediaMapper::getParentCollection($media->getVirtualPath());
|
||||||
|
self::assertEquals($idCollection, $collectionR->getId());
|
||||||
|
self::assertEquals($collection->getName(), $collectionR->getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ class MediaTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals('/', $this->media->getVirtualPath());
|
self::assertEquals('/', $this->media->getVirtualPath());
|
||||||
self::assertEquals(0, $this->media->getSize());
|
self::assertEquals(0, $this->media->getSize());
|
||||||
self::assertFalse($this->media->isVersioned());
|
self::assertFalse($this->media->isVersioned());
|
||||||
|
self::assertFalse($this->media->compareNonce('something'));
|
||||||
|
self::assertFalse($this->media->isEncrypted());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -161,4 +163,67 @@ class MediaTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->media->setHidden(true);
|
$this->media->setHidden(true);
|
||||||
self::assertTrue($this->media->isHidden());
|
self::assertTrue($this->media->isHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\Media
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testNonceInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->media->setNonce('test');
|
||||||
|
self::assertTrue($this->media->compareNonce('test'));
|
||||||
|
self::assertFalse($this->media->compareNonce('test2'));
|
||||||
|
self::assertTrue($this->media->isEncrypted());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\Media
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testPasswordInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->media->setPassword('test');
|
||||||
|
self::assertTrue($this->media->comparePassword('test'));
|
||||||
|
self::assertFalse($this->media->comparePassword('test2'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\Media
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
$this->media->setCreatedBy($acc = new NullAccount(1));
|
||||||
|
$this->media->setExtension('pdf');
|
||||||
|
$this->media->setPath('/home/root');
|
||||||
|
$this->media->setAbsolute(true);
|
||||||
|
$this->media->setName('Report');
|
||||||
|
$this->media->setDescription('This is a description');
|
||||||
|
$this->media->setDescriptionRaw('This is a description raw');
|
||||||
|
$this->media->setSize(11);
|
||||||
|
$this->media->setVersioned(true);
|
||||||
|
$this->media->setVirtualPath('/test/path');
|
||||||
|
$this->media->setHidden(true);
|
||||||
|
|
||||||
|
self::assertEquals($this->media->toArray(), $this->media->jsonSerialize());
|
||||||
|
|
||||||
|
$arr = $this->media->toArray();
|
||||||
|
unset($arr['createdAt']);
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'createdBy' => $acc,
|
||||||
|
'name' => 'Report',
|
||||||
|
'description' => 'This is a description',
|
||||||
|
'descriptionRaw' => 'This is a description raw',
|
||||||
|
'extension' => 'pdf',
|
||||||
|
'virtualpath' => '/test/path',
|
||||||
|
'size' => 11,
|
||||||
|
'hidden' => true,
|
||||||
|
'path' => '/home/root',
|
||||||
|
'absolute' => true,
|
||||||
|
],
|
||||||
|
$arr
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
tests/Models/NullCollectionTest.php
Normal file
42
tests/Models/NullCollectionTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?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\Models;
|
||||||
|
|
||||||
|
use Modules\Media\Models\NullCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class NullCollectionTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\NullCollection
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testNull() : void
|
||||||
|
{
|
||||||
|
self::assertInstanceOf('\Modules\Media\Models\Collection', new NullCollection());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\NullCollection
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testId() : void
|
||||||
|
{
|
||||||
|
$null = new NullCollection(2);
|
||||||
|
self::assertEquals(2, $null->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
42
tests/Models/NullMediaTest.php
Normal file
42
tests/Models/NullMediaTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?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\Models;
|
||||||
|
|
||||||
|
use Modules\Media\Models\NullMedia;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class NullMediaTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\NullMedia
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testNull() : void
|
||||||
|
{
|
||||||
|
self::assertInstanceOf('\Modules\Media\Models\Media', new NullMedia());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Models\NullMedia
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testId() : void
|
||||||
|
{
|
||||||
|
$null = new NullMedia(2);
|
||||||
|
self::assertEquals(2, $null->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
234
tests/Views/MediaViewTest.php
Normal file
234
tests/Views/MediaViewTest.php
Normal file
|
|
@ -0,0 +1,234 @@
|
||||||
|
<?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\Views;
|
||||||
|
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
|
use Modules\Media\Views\MediaView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class MediaViewTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected MediaView $view;
|
||||||
|
|
||||||
|
public function setUp() : void
|
||||||
|
{
|
||||||
|
$this->view = new MediaView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testFilePath() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'filePathFunction');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
self::assertEquals(
|
||||||
|
\ltrim(__DIR__, '/'),
|
||||||
|
$method->invoke($this->view, $media, '/sub/path')
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertEquals(
|
||||||
|
__DIR__ . '/MediaViewTest.php',
|
||||||
|
$method->invoke($this->view, $media, '/MediaViewTest.php')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDirPath() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'dirPathFunction');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
self::assertEquals(
|
||||||
|
\ltrim(__DIR__, '/'),
|
||||||
|
$method->invoke($this->view, $media, '/sub/path')
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(\realpath(__DIR__ . '/../'));
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertEquals(
|
||||||
|
\realpath(__DIR__ . '/../Controller'),
|
||||||
|
$method->invoke($this->view, $media, '/Controller')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testIscollection() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'isCollectionFunction');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertFalse(
|
||||||
|
$method->invoke($this->view, $media, '/sub/path')
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
$media->setExtension('collection');
|
||||||
|
self::assertFalse(
|
||||||
|
$method->invoke($this->view, $media, '/MediaViewTest.php')
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__ . '/../');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertTrue(
|
||||||
|
$method->invoke($this->view, $media, '/Views/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__);
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
$media->setExtension('collection');
|
||||||
|
self::assertTrue(
|
||||||
|
$method->invoke($this->view, $media, '/something')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testFileContent() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'getFileContent');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
"Line 1\nLine 2",
|
||||||
|
$method->invoke($this->view, __DIR__ . '/test.md')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidFileContentPath() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'getFileContent');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
'',
|
||||||
|
$method->invoke($this->view, __DIR__ . '/invalid.txt')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testFileLineContent() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'lineContentFunction');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'Line 1',
|
||||||
|
'Line 2',
|
||||||
|
],
|
||||||
|
$method->invoke($this->view, __DIR__ . '/test.md')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidFileLineContentPath() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'lineContentFunction');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[],
|
||||||
|
$method->invoke($this->view, __DIR__ . '/invalid.txt')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testIsImage() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'isImageFile');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setPath(__DIR__ . '/test.md');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertFalse(
|
||||||
|
$method->invoke($this->view, $media)
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__ . '/test.jpg');
|
||||||
|
$media->setExtension('jpg');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertTrue(
|
||||||
|
$method->invoke($this->view, $media)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Media\Views\MediaView
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testIsText() : void
|
||||||
|
{
|
||||||
|
$method = new \ReflectionMethod($this->view, 'isTextFile');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$media = new Media();
|
||||||
|
$media->setPath(__DIR__ . '/test.jpg');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertFalse(
|
||||||
|
$method->invoke($this->view, $media)
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__ . '/test.md');
|
||||||
|
$media->setExtension('md');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertTrue(
|
||||||
|
$method->invoke($this->view, $media)
|
||||||
|
);
|
||||||
|
|
||||||
|
$media->setPath(__DIR__ . '/test.jpg');
|
||||||
|
$media->setExtension('jpg');
|
||||||
|
$media->setAbsolute(true);
|
||||||
|
self::assertTrue(
|
||||||
|
$method->invoke($this->view, $media, __DIR__ . '/test.md')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
tests/Views/test.md
Normal file
2
tests/Views/test.md
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Line 1
|
||||||
|
Line 2
|
||||||
Loading…
Reference in New Issue
Block a user