mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-02-17 07:28:39 +00:00
get overall coverage to 76%
This commit is contained in:
parent
760848e18e
commit
23fb23e016
|
|
@ -98,8 +98,10 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
// protection against infinite loop
|
// protection against infinite loop
|
||||||
if ($i >= 10000) {
|
if ($i >= 10000) {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Draw', 'Draw failed.', null);
|
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Draw', 'Draw failed.', null);
|
||||||
return;
|
return;
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
$fullPath = __DIR__ . '/../../../' . $path . '/' . $filename;
|
$fullPath = __DIR__ . '/../../../' . $path . '/' . $filename;
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
||||||
/**
|
/**
|
||||||
* Media object.
|
* Media object.
|
||||||
*
|
*
|
||||||
* @var int|Media
|
* @var null|int|Media
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $media = null;
|
public null|int|Media $media = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
|
|
@ -55,32 +55,6 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get media
|
|
||||||
*
|
|
||||||
* @return int|Media
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getMedia()
|
|
||||||
{
|
|
||||||
return $this->media;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set media
|
|
||||||
*
|
|
||||||
* @param int|Media $media Media
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setMedia($media) : void
|
|
||||||
{
|
|
||||||
$this->media = $media;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -88,7 +62,7 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'media' => \is_scalar($this->media) ? $this->media : $this->media->toArray(),
|
'media' => $this->media,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +86,7 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
||||||
public static function fromMedia(Media $media) : self
|
public static function fromMedia(Media $media) : self
|
||||||
{
|
{
|
||||||
$image = new self();
|
$image = new self();
|
||||||
$image->setMedia($media);
|
$image->media = $media;
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
51
tests/ControllerTest.php → tests/Controller/ApiControllerTest.php
Executable file → Normal file
51
tests/ControllerTest.php → tests/Controller/ApiControllerTest.php
Executable file → Normal file
|
|
@ -12,31 +12,45 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Draw\tests;
|
namespace Modules\Draw\tests\Controller;
|
||||||
|
|
||||||
use Model\CoreSettings;
|
use Model\CoreSettings;
|
||||||
use Modules\Admin\Models\AccountPermission;
|
use Modules\Admin\Models\AccountPermission;
|
||||||
|
use phpOMS\DataStorage\Session\HttpSession;
|
||||||
use phpOMS\Account\Account;
|
use phpOMS\Account\Account;
|
||||||
use phpOMS\Account\AccountManager;
|
use phpOMS\Account\AccountManager;
|
||||||
use phpOMS\Account\PermissionType;
|
use phpOMS\Account\PermissionType;
|
||||||
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\Message\Http\HttpRequest;
|
use phpOMS\Module\ModuleAbstract;
|
||||||
use phpOMS\Message\Http\HttpResponse;
|
|
||||||
use phpOMS\Module\ModuleManager;
|
use phpOMS\Module\ModuleManager;
|
||||||
use phpOMS\Router\WebRouter;
|
use phpOMS\Router\WebRouter;
|
||||||
use phpOMS\Uri\HttpUri;
|
|
||||||
use phpOMS\Utils\TestUtils;
|
use phpOMS\Utils\TestUtils;
|
||||||
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
|
use Modules\Media\Models\MediaMapper;
|
||||||
|
use Modules\Media\Models\PathSettings;
|
||||||
|
use Modules\Media\Models\UploadStatus;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\DataStorage\Database\DatabaseType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @testdox Modules\Draw\tests\Controller\ApiControllerTest: Draw api controller
|
||||||
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class ControllerTest extends \PHPUnit\Framework\TestCase
|
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
protected $app = null;
|
protected ApplicationAbstract $app;
|
||||||
|
|
||||||
protected $module = null;
|
/**
|
||||||
|
* @var \Modules\Draw\Controller\ApiController
|
||||||
|
*/
|
||||||
|
protected ModuleAbstract $module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
@ -52,10 +66,11 @@ final class ControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->app->orgId = 1;
|
$this->app->orgId = 1;
|
||||||
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||||
$this->app->appSettings = new CoreSettings();
|
$this->app->appSettings = new CoreSettings();
|
||||||
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules/');
|
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
|
||||||
$this->app->dispatcher = new Dispatcher($this->app);
|
$this->app->dispatcher = new Dispatcher($this->app);
|
||||||
$this->app->eventManager = new EventManager($this->app->dispatcher);
|
$this->app->eventManager = new EventManager($this->app->dispatcher);
|
||||||
$this->app->eventManager->importFromFile(__DIR__ . '/../../../Web/Api/Hooks.php');
|
$this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php');
|
||||||
|
$this->app->sessionManager = new HttpSession(36000);
|
||||||
|
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
TestUtils::setMember($account, 'id', 1);
|
TestUtils::setMember($account, 'id', 1);
|
||||||
|
|
@ -96,7 +111,23 @@ final class ControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$this->module->apiDrawCreate($request, $response);
|
$this->module->apiDrawCreate($request, $response);
|
||||||
|
|
||||||
self::assertEquals('Draw Title', $response->get('')['response']->getMedia()->name);
|
self::assertEquals('Draw Title', $response->get('')['response']->media->name);
|
||||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Draw\Controller\ApiController
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testApiDrawCreateInvalidData() : void
|
||||||
|
{
|
||||||
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('invalid', '1');
|
||||||
|
|
||||||
|
$this->module->apiDrawCreate($request, $response);
|
||||||
|
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
69
tests/Models/DrawImageTest.php
Normal file
69
tests/Models/DrawImageTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @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\Draw\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Draw\Models\DrawImage;
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class DrawImageTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private DrawImage $img;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->img = new DrawImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Draw\Models\DrawImage
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDefault() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(0, $this->img->getId());
|
||||||
|
self::assertEquals(null, $this->img->media);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Draw\Models\DrawImage
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testFromMedia() : void
|
||||||
|
{
|
||||||
|
$img = DrawImage::fromMedia($temp = new Media());
|
||||||
|
self::assertEquals($temp, $img->media);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Draw\Models\DrawImage
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'media' => null,
|
||||||
|
],
|
||||||
|
$this->img->jsonSerialize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user