mirror of
https://github.com/Karaka-Management/oms-Profile.git
synced 2026-01-29 07:18:42 +00:00
add tests
This commit is contained in:
parent
d392136dde
commit
7f8c88599d
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\Profile\Admin;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AdminTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected const MODULE_NAME = 'Profile';
|
||||
protected const URI_LOAD = 'http://127.0.0.1/en/backend/profile';
|
||||
|
||||
use \Modules\tests\ModuleTestTrait;
|
||||
}
|
||||
100
tests/ControllerTest.php
Normal file
100
tests/ControllerTest.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?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\Profile;
|
||||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
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 $app = null;
|
||||
protected $module = null;
|
||||
|
||||
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('Profile');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateProfile() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->getHeader()->setAccount(1);
|
||||
$request->setData('iaccount-idlist', '1');
|
||||
|
||||
$this->module->apiProfileCreate($request, $response);
|
||||
|
||||
self::assertEquals('admin', $response->get('')['response'][0]->getAccount()->getName());
|
||||
self::assertGreaterThan(0, $response->get('')['response'][0]->getId());
|
||||
}
|
||||
}
|
||||
64
tests/Models/ProfileMapperTest.php
Normal file
64
tests/Models/ProfileMapperTest.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?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\ClientMapper\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ProfileMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Profile\Models\ProfileMapper
|
||||
* @group module
|
||||
*/
|
||||
public function testCRUD() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->setCreatedBy(new NullAccount(1));
|
||||
$media->setDescription('desc');
|
||||
$media->setPath('Web/Backend/img/default-user.jpg');
|
||||
$media->setSize(11);
|
||||
$media->setExtension('png');
|
||||
$media->setName('Image');
|
||||
|
||||
if (($profile = ProfileMapper::getFor(1, 'account'))->getId() === 0) {
|
||||
$profile = new Profile();
|
||||
|
||||
$profile->setAccount(AccountMapper::get(1));
|
||||
$profile->setImage($media);
|
||||
$profile->setBirthday($date = new \DateTime('now'));
|
||||
|
||||
$id = ProfileMapper::create($profile);
|
||||
self::assertGreaterThan(0, $profile->getId());
|
||||
self::assertEquals($id, $profile->getId());
|
||||
} else {
|
||||
$profile->setImage($media);
|
||||
$profile->setBirthday($date = new \DateTime('now'));
|
||||
|
||||
ProfileMapper::update($profile);
|
||||
}
|
||||
|
||||
$profileR = ProfileMapper::get($profile->getId());
|
||||
self::assertEquals($profile->getBirthday()->format('Y-m-d'), $profileR->getBirthday()->format('Y-m-d'));
|
||||
self::assertEquals($profile->getImage()->getName(), $profileR->getImage()->getName());
|
||||
self::assertEquals($profile->getAccount()->getName1(), $profileR->getAccount()->getName1());
|
||||
}
|
||||
}
|
||||
40
tests/Models/ProfileTest.php
Normal file
40
tests/Models/ProfileTest.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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\Profile\Models;
|
||||
|
||||
use Modules\Profile\Models\Profile;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ProfileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
{
|
||||
$profile = new Profile();
|
||||
|
||||
self::assertEquals(0, $profile->getId());
|
||||
self::assertInstanceOf('\Modules\Media\Models\Media', $profile->getImage());
|
||||
self::assertInstanceOf('\DateTime', $profile->getBirthday());
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
{
|
||||
$profile = new Profile();
|
||||
|
||||
$profile->setBirthday($date = new \DateTime('now'));
|
||||
self::assertEquals($date, $profile->getBirthday());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user