61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Dto\PageDto;
|
|
use App\Models\Customer;
|
|
use App\Models\Page;
|
|
use App\Models\User;
|
|
use App\Policies\Backend\PagePolicy;
|
|
use Domain\Enums\StaticPageSlug;
|
|
use Domain\Enums\UserRole;
|
|
|
|
describe('PagePolicy', function () {
|
|
test('update returns false for customer', function () {
|
|
// GIVEN
|
|
$customer = new Customer();
|
|
$policy = new PagePolicy();
|
|
$modelInstance = new Page();
|
|
|
|
// WHEN
|
|
$result = $policy->update($customer, $modelInstance);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
});
|
|
|
|
test('update returns true for admin user', function () {
|
|
// GIVEN
|
|
$user = new User();
|
|
$user->role = UserRole::Admin;
|
|
$policy = new PagePolicy();
|
|
$modelInstance = new Page();
|
|
|
|
// WHEN
|
|
$result = $policy->update($user, $modelInstance);
|
|
|
|
// THEN
|
|
expect($result)->toBeTrue();
|
|
});
|
|
|
|
test('update returns true for admin user with PageDto', function () {
|
|
// GIVEN
|
|
$user = new User();
|
|
$user->role = UserRole::Admin;
|
|
$policy = new PagePolicy();
|
|
$page = new Page();
|
|
$page->id = 1;
|
|
$page->slug = StaticPageSlug::FAQ;
|
|
$page->seo_title = 'SEO Title';
|
|
$page->seo_description = 'SEO Description';
|
|
$page->title = 'Title';
|
|
$page->content = 'Content';
|
|
$dto = PageDto::fromModel($page);
|
|
|
|
// WHEN
|
|
$result = $policy->update($user, $dto);
|
|
|
|
// THEN
|
|
expect($result)->toBeTrue();
|
|
});
|
|
});
|