mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-01-29 09:48:40 +00:00
add tests
This commit is contained in:
parent
fa0a46562f
commit
e3c725f16d
26
tests/Admin/AdminTest.php
Normal file
26
tests/Admin/AdminTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?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\tests\Editor\Admin;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AdminTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected const MODULE_NAME = 'Editor';
|
||||
protected const URI_LOAD = 'http://127.0.0.1/en/backend/editor';
|
||||
|
||||
use \Modules\tests\ModuleTestTrait;
|
||||
}
|
||||
102
tests/ControllerTest.php
Normal file
102
tests/ControllerTest.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?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\tests\Editor;
|
||||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use Modules\Editor\Controller\ApiController;
|
||||
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\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected ApplicationAbstract $app;
|
||||
protected ApiController $module;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->app = new class() extends ApplicationAbstract
|
||||
{
|
||||
protected string $appName = 'Api';
|
||||
};
|
||||
|
||||
$this->app->dbPool = $GLOBALS['dbpool'];
|
||||
$this->app->orgId = 1;
|
||||
$this->app->appName = 'Backend';
|
||||
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||
$this->app->appSettings = new CoreSettings($this->app->dbPool->get());
|
||||
$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');
|
||||
|
||||
$account = new Account();
|
||||
TestUtils::setMember($account, 'id', 1);
|
||||
|
||||
$permission = new AccountPermission();
|
||||
$permission->setUnit(1);
|
||||
$permission->setApp('backend');
|
||||
$permission->setPermission(
|
||||
PermissionType::READ
|
||||
| PermissionType::CREATE
|
||||
| PermissionType::MODIFY
|
||||
| PermissionType::DELETE
|
||||
| PermissionType::PERMISSION
|
||||
);
|
||||
|
||||
$account->addPermission($permission);
|
||||
|
||||
$this->app->accountManager->add($account);
|
||||
$this->app->router = new WebRouter();
|
||||
|
||||
$this->module = $this->app->moduleManager->get('Editor');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Editor\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateEditor() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->getHeader()->setAccount(1);
|
||||
$request->setData('title', 'Controller Test Title');
|
||||
$request->setData('plain', 'Controller Test Description');
|
||||
|
||||
$this->module->apiEditorCreate($request, $response);
|
||||
|
||||
self::assertEquals('Controller Test Title', $response->get('')['response']->getTitle());
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
}
|
||||
73
tests/Models/EditorDocMapperTest.php
Normal file
73
tests/Models/EditorDocMapperTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Editor\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Editor\Models\EditorDoc;
|
||||
use Modules\Editor\Models\EditorDocMapper;
|
||||
use phpOMS\Utils\RnG\Text;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class EditorDocMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Editor\Models\EditorDocMapper
|
||||
* @group module
|
||||
*/
|
||||
public function testCRUD() : void
|
||||
{
|
||||
$doc = new EditorDoc();
|
||||
|
||||
$doc->setCreatedBy(new NullAccount(1));
|
||||
$doc->setTitle('Title');
|
||||
$doc->setContent('Content');
|
||||
$doc->setPath('/some/test/path');
|
||||
|
||||
$id = EditorDocMapper::create($doc);
|
||||
self::assertGreaterThan(0, $doc->getId());
|
||||
self::assertEquals($id, $doc->getId());
|
||||
|
||||
$docR = EditorDocMapper::get($doc->getId());
|
||||
self::assertEquals($doc->getCreatedAt()->format('Y-m-d'), $docR->getCreatedAt()->format('Y-m-d'));
|
||||
self::assertEquals($doc->getCreatedBy()->getId(), $docR->getCreatedBy()->getId());
|
||||
self::assertEquals($doc->getContent(), $docR->getContent());
|
||||
self::assertEquals($doc->getTitle(), $docR->getTitle());
|
||||
self::assertEquals($doc->getPath(), $docR->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 0; $i < 100; ++$i) {
|
||||
$text = new Text();
|
||||
$doc = new EditorDoc();
|
||||
|
||||
// Test other
|
||||
|
||||
$doc->setCreatedBy(new NullAccount(\mt_rand(1, 1)));
|
||||
$doc->setTitle($text->generateText(\mt_rand(3, 7)));
|
||||
$doc->setContent($text->generateText(\mt_rand(20, 500)));
|
||||
$doc->setPath('/some/test/path');
|
||||
|
||||
$id = EditorDocMapper::create($doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
tests/Models/EditorDocTest.php
Normal file
68
tests/Models/EditorDocTest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Tasks\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Editor\Models\EditorDoc;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class EditorDocTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
{
|
||||
$doc = new EditorDoc();
|
||||
|
||||
self::assertEquals(0, $doc->getId());
|
||||
self::assertEquals(0, $doc->getCreatedBy()->getId());
|
||||
self::assertEquals('', $doc->getTitle());
|
||||
self::assertEquals('', $doc->getContent());
|
||||
self::assertEquals('', $doc->getPlain());
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $doc->getCreatedAt()->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
{
|
||||
$doc = new EditorDoc();
|
||||
|
||||
$doc->setCreatedBy(new NullAccount(1));
|
||||
self::assertEquals(1, $doc->getCreatedBy()->getId());
|
||||
|
||||
$doc->setTitle('Title');
|
||||
self::assertEquals('Title', $doc->getTitle());
|
||||
|
||||
$doc->setContent('Content');
|
||||
self::assertEquals('Content', $doc->getContent());
|
||||
|
||||
$doc->setPlain('Plain');
|
||||
self::assertEquals('Plain', $doc->getPlain());
|
||||
|
||||
$doc->setPath('/some/path');
|
||||
self::assertEquals('/some/path', $doc->getPath());
|
||||
|
||||
$arr = [
|
||||
'id' => 0,
|
||||
'title' => $doc->getTitle(),
|
||||
'plain' => $doc->getPlain(),
|
||||
'content' => $doc->getContent(),
|
||||
'createdAt' => $doc->getCreatedAt(),
|
||||
'createdBy' => $doc->getCreatedBy(),
|
||||
];
|
||||
self::assertEquals($arr, $doc->toArray());
|
||||
self::assertEquals($arr, $doc->jsonSerialize());
|
||||
self::assertEquals(\json_encode($arr), $doc->__toString());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user