mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-01-11 14:28:40 +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
|
||||
if ($i >= 10000) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Draw', 'Draw failed.', null);
|
||||
return;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$fullPath = __DIR__ . '/../../../' . $path . '/' . $filename;
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* Media object.
|
||||
*
|
||||
* @var int|Media
|
||||
* @var null|int|Media
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $media = null;
|
||||
public null|int|Media $media = null;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
|
|
@ -55,32 +55,6 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
|||
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}
|
||||
*/
|
||||
|
|
@ -88,7 +62,7 @@ class DrawImage implements \JsonSerializable, ArrayableInterface
|
|||
{
|
||||
return [
|
||||
'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
|
||||
{
|
||||
$image = new self();
|
||||
$image->setMedia($media);
|
||||
$image->media = $media;
|
||||
|
||||
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);
|
||||
|
||||
namespace Modules\Draw\tests;
|
||||
namespace Modules\Draw\tests\Controller;
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
use phpOMS\Account\Account;
|
||||
use phpOMS\Account\AccountManager;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\Dispatcher\Dispatcher;
|
||||
use phpOMS\Event\EventManager;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Module\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
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
|
||||
*/
|
||||
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}
|
||||
|
|
@ -52,10 +66,11 @@ final class ControllerTest extends \PHPUnit\Framework\TestCase
|
|||
$this->app->orgId = 1;
|
||||
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||
$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->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();
|
||||
TestUtils::setMember($account, 'id', 1);
|
||||
|
|
@ -96,7 +111,23 @@ final class ControllerTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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