mirror of
https://github.com/Karaka-Management/oms-Profile.git
synced 2026-02-02 09:18:42 +00:00
add tests
This commit is contained in:
parent
21efcaebae
commit
3a4663e282
|
|
@ -20,6 +20,7 @@ use Modules\Profile\Models\ProfileMapper;
|
|||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
||||
/**
|
||||
* Profile class.
|
||||
|
|
@ -139,6 +140,9 @@ final class ApiController extends Controller
|
|||
$uploadedFiles = $request->getFiles() ?? [];
|
||||
|
||||
if (empty($uploadedFiles)) {
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Profile', 'Invalid profile image', $uploadedFiles);
|
||||
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,15 +226,15 @@ class Profile implements \JsonSerializable
|
|||
/**
|
||||
* Add contact element.
|
||||
*
|
||||
* @param ContactElement $contactElements Contact Element
|
||||
* @param ContactElement $contactElement Contact Element
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addContactElements(ContactElement $contactElements) : void
|
||||
public function addContactElement(ContactElement $contactElement) : void
|
||||
{
|
||||
$this->contactElements[] = $contactElements;
|
||||
$this->contactElements[] = $contactElement;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -321,11 +321,14 @@ class Profile implements \JsonSerializable
|
|||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'account' => $this->account,
|
||||
'image' => $this->image,
|
||||
'location' => $this->location,
|
||||
'contactelement' => $this->contactElements,
|
||||
'id' => $this->id,
|
||||
'sex' => $this->sex,
|
||||
'gender' => $this->gender,
|
||||
'account' => $this->account,
|
||||
'image' => $this->image,
|
||||
'birthday' => $this->birthday,
|
||||
'locations' => $this->location,
|
||||
'contactelements' => $this->contactElements,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Profile\tests;
|
||||
namespace Modules\Profile\tests\Controller;
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use phpOMS\Account\Account;
|
||||
use phpOMS\Account\AccountManager;
|
||||
use phpOMS\Account\PermissionType;
|
||||
|
|
@ -28,11 +30,13 @@ use phpOMS\Module\ModuleManager;
|
|||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ControllerTest extends \PHPUnit\Framework\TestCase
|
||||
class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $app = null;
|
||||
|
||||
|
|
@ -47,7 +51,6 @@ class ControllerTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$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');
|
||||
|
|
@ -83,7 +86,7 @@ class ControllerTest extends \PHPUnit\Framework\TestCase
|
|||
* @covers Modules\Profile\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testCreateProfile() : void
|
||||
public function testApiProfileCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
|
@ -96,4 +99,65 @@ class ControllerTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('admin', $response->get('')['response'][0]->getAccount()->getName());
|
||||
self::assertGreaterThan(0, $response->get('')['response'][0]->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiProfileCreateDbEntry() : void
|
||||
{
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->getHeader()->setAccount(1);
|
||||
|
||||
$profile = new Profile(new \Modules\Admin\Models\Account());
|
||||
$profile->getAccount()->setName('ProfileCreateDb');
|
||||
$profile->getAccount()->setEmail('profile_create_db@email.com');
|
||||
|
||||
$this->module->apiProfileCreateDbEntry($profile, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiProfileImageSet() : void
|
||||
{
|
||||
\copy(__DIR__ . '/icon.png', __DIR__ . '/temp_icon.png');
|
||||
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->getHeader()->setAccount(1);
|
||||
$request->setData('name', 'Profile Logo');
|
||||
$request->setData('id', 1);
|
||||
|
||||
TestUtils::setMember($request, 'files', [
|
||||
'file1' => [
|
||||
'name' => 'icon.png',
|
||||
'type' => MimeType::M_PNG,
|
||||
'tmp_name' => __DIR__ . '/temp_icon.png',
|
||||
'error' => \UPLOAD_ERR_OK,
|
||||
'size' => \filesize(__DIR__ . '/icon.png'),
|
||||
],
|
||||
]);
|
||||
$this->module->apiSettingsAccountImageSet($request, $response);
|
||||
|
||||
$image = ProfileMapper::get(3)->getImage();
|
||||
self::assertEquals('Profile Logo', $image->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiProfileImageSetInvalid() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$this->module->apiSettingsAccountImageSet($request, $response);
|
||||
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode());
|
||||
}
|
||||
}
|
||||
BIN
tests/Controller/icon.png
Normal file
BIN
tests/Controller/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
42
tests/Models/NullProfileTest.php
Normal file
42
tests/Models/NullProfileTest.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\Profile\tests\Models;
|
||||
|
||||
use Modules\Profile\Models\NullProfile;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullProfileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Profile\Models\NullProfile
|
||||
* @group module
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Profile\Models\Profile', new NullProfile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\NullProfile
|
||||
* @group module
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullProfile(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -14,35 +14,162 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Profile\tests\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Profile\Models\GenderType;
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\Profile\Models\SexType;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use phpOMS\Stdlib\Base\Location;
|
||||
use Modules\Profile\Models\ContactElement;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ProfileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private Profile $profile;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->profile = new Profile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
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());
|
||||
self::assertEquals(0, $this->profile->getId());
|
||||
self::assertEquals(GenderType::OTHER, $this->profile->getGender());
|
||||
self::assertEquals(SexType::OTHER, $this->profile->getSex());
|
||||
self::assertEquals([], $this->profile->getLocation());
|
||||
self::assertEquals([], $this->profile->getContactElements());
|
||||
self::assertInstanceOf('\Modules\Media\Models\Media', $this->profile->getImage());
|
||||
self::assertInstanceOf('\Modules\Admin\Models\Account', $this->profile->getAccount());
|
||||
self::assertInstanceOf('\DateTime', $this->profile->getBirthday());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testSetGet() : void
|
||||
public function testGenderInputOutput() : void
|
||||
{
|
||||
$profile = new Profile();
|
||||
$this->profile->setGender(GenderType::FEMALE);
|
||||
self::assertEquals(GenderType::FEMALE, $this->profile->getGender());
|
||||
}
|
||||
|
||||
$profile->setBirthday($date = new \DateTime('now'));
|
||||
self::assertEquals($date, $profile->getBirthday());
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testInvalidGender() : void
|
||||
{
|
||||
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$this->profile->setGender(9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testSexInputOutput() : void
|
||||
{
|
||||
$this->profile->setSex(SexType::FEMALE);
|
||||
self::assertEquals(SexType::FEMALE, $this->profile->getSex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testInvalidSex() : void
|
||||
{
|
||||
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$this->profile->setSex(9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testBirthdayInputOutput() : void
|
||||
{
|
||||
$this->profile->setBirthday($date = new \DateTime('now'));
|
||||
self::assertEquals($date, $this->profile->getBirthday());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testImageInputOutput() : void
|
||||
{
|
||||
$this->profile->setImage(new NullMedia(1));
|
||||
self::assertEquals(1, $this->profile->getImage()->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testLocationInputOutput() : void
|
||||
{
|
||||
$this->profile->addLocation(new Location());
|
||||
self::assertCount(1, $this->profile->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testContactElementInputOutput() : void
|
||||
{
|
||||
$this->profile->addContactElement(new ContactElement());
|
||||
self::assertCount(1, $this->profile->getContactElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testAccountInputOutput() : void
|
||||
{
|
||||
$this->profile->setAccount(new NullAccount(1));
|
||||
self::assertEquals(1, $this->profile->getAccount()->getId());
|
||||
|
||||
$profile = new Profile(new NullAccount(1));
|
||||
self::assertEquals(1, $profile->getAccount()->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Profile\Models\Profile
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->profile->setGender(GenderType::FEMALE);
|
||||
$this->profile->setSex(SexType::FEMALE);
|
||||
$this->profile->setBirthday($date = new \DateTime('now'));
|
||||
$this->profile->setImage(new NullMedia(1));
|
||||
$this->profile->setAccount($a = new NullAccount(1));
|
||||
$this->profile->setImage($i = new NullMedia(1));
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'sex' => SexType::FEMALE,
|
||||
'gender' => GenderType::FEMALE,
|
||||
'account' => $a,
|
||||
'image' => $i,
|
||||
'birthday' => $date,
|
||||
'locations' => [],
|
||||
'contactelements' => [],
|
||||
],
|
||||
$this->profile->jsonSerialize()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user