View source
<?php
namespace Drupal\Tests\rng\Kernel;
use Drupal\simpletest\UserCreationTrait;
use Drupal\rng\EventManagerInterface;
class RngRegistrationAccessTest extends RngKernelTestBase {
use UserCreationTrait {
createUser as drupalCreateUser;
}
public static $modules = [
'system',
'entity_test',
];
protected $eventManager;
protected $registrationType;
protected function setUp() {
parent::setUp();
$this->eventManager = \Drupal::service('rng.event_manager');
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('registration');
$this
->installEntitySchema('registrant');
$this
->installEntitySchema('rng_rule');
$this
->installEntitySchema('rng_rule_component');
$this
->installEntitySchema('user');
$this
->installConfig('rng');
$this
->installSchema('system', [
'sequences',
]);
$this->registrationType = $this
->createRegistrationType();
$this
->createEventType('entity_test', 'entity_test');
}
public function testRegisterSelf() {
$event_meta = $this
->createEvent();
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->createUserRoleRules([], [
'create' => TRUE,
]);
$this
->assertTrue($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfNoDefaultRules() {
$event_meta = $this
->createEvent();
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->assertFalse($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfRuleNoRoles() {
$event_meta = $this
->createEvent();
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->createUserRoleRules([], [
'create' => TRUE,
]);
$this
->assertTrue($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfRuleRoleAlternative() {
$event_meta = $this
->createEvent();
$role1 = $this
->createRole([]);
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->createUserRoleRules([
$role1 => $role1,
], [
'create' => TRUE,
]);
$this
->assertFalse($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfNoPermission() {
$event_meta = $this
->createEvent();
$role1 = $this
->createRole([]);
$user1 = $this
->drupalCreateUser();
$this
->setCurrentUser($user1);
$this
->createUserRoleRules([
$role1 => $role1,
], [
'create' => TRUE,
]);
$this
->assertFalse($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfNoDuplicates() {
$event_meta = $this
->createEvent([
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS => 0,
]);
$this
->createUserRoleRules([], [
'create' => TRUE,
]);
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->assertTrue($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
$this
->createRegistration($event_meta
->getEvent(), $this->registrationType, [
$user1,
]);
$this
->assertFalse($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
public function testRegisterSelfWithDuplicates() {
$event_meta = $this
->createEvent([
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS => 1,
]);
$this
->createUserRoleRules([], [
'create' => TRUE,
]);
$user1 = $this
->drupalCreateUser([
'rng register self',
]);
$this
->setCurrentUser($user1);
$this
->assertTrue($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
$this
->createRegistration($event_meta
->getEvent(), $this->registrationType, [
$user1,
]);
$this
->assertTrue($event_meta
->identitiesCanRegister('user', [
$user1
->id(),
]));
}
}