feat: pending roles from crm to be confirmed by superadmins
This commit is contained in:
@@ -6,6 +6,8 @@ namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\User;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
@@ -23,4 +25,64 @@ class UserTest extends TestCase
|
||||
$isMatch = $user->hasHotelCodeMatch('XXDEFXX');
|
||||
$this->assertFalse($isMatch);
|
||||
}
|
||||
|
||||
public function testPendingMarkersAreLabelledButNotAssignable(): void
|
||||
{
|
||||
$user = (new User())->setRoles([
|
||||
User::PENDING_ROLES['ROLE_ADMIN'],
|
||||
User::PENDING_ROLES['ROLE_HOUSE_MANAGER'],
|
||||
'ROLE_TEAMER',
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
['Admin (nicht freigeschaltet)', 'Hausleitung (nicht freigeschaltet)', 'Teamer'],
|
||||
$user->getRolesLabels(),
|
||||
);
|
||||
$this->assertSame(['ROLE_TEAMER'], $user->getAssignedRoles());
|
||||
$this->assertSame(
|
||||
[User::PENDING_ROLES['ROLE_ADMIN'], User::PENDING_ROLES['ROLE_HOUSE_MANAGER']],
|
||||
$user->getPendingRoles(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSuperAdminRequiresRoleAdmin(): void
|
||||
{
|
||||
$user = (new User())
|
||||
->setRoles(['ROLE_MANAGER'])
|
||||
->setSuperAdmin(true)
|
||||
;
|
||||
|
||||
$violations = $this->validate($user);
|
||||
|
||||
$this->assertCount(1, $violations);
|
||||
$this->assertSame('superAdmin', $violations[0]->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testSuperAdminWithRoleAdminIsValid(): void
|
||||
{
|
||||
$user = (new User())
|
||||
->setRoles(['ROLE_ADMIN'])
|
||||
->setSuperAdmin(true)
|
||||
;
|
||||
|
||||
$this->assertCount(0, $this->validate($user));
|
||||
}
|
||||
|
||||
public function testNonSuperAdminWithoutRoleAdminIsValid(): void
|
||||
{
|
||||
$user = (new User())
|
||||
->setRoles(['ROLE_TEAMER'])
|
||||
;
|
||||
|
||||
$this->assertCount(0, $this->validate($user));
|
||||
}
|
||||
|
||||
private function validate(User $user): ConstraintViolationListInterface
|
||||
{
|
||||
return Validation::createValidatorBuilder()
|
||||
->enableAttributeMapping()
|
||||
->getValidator()
|
||||
->validate($user)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user