trait RngTestTrait in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Tests/RngTestTrait.php \Drupal\rng\Tests\RngTestTrait
- 3.x src/Tests/RngTestTrait.php \Drupal\rng\Tests\RngTestTrait
Hierarchy
- trait \Drupal\rng\Tests\RngTestTrait
3 files declare their use of RngTestTrait
- RngBrowserTestBase.php in tests/
src/ Functional/ RngBrowserTestBase.php - RngKernelTestBase.php in tests/
src/ Kernel/ RngKernelTestBase.php - RngViewsTest.php in tests/
src/ Kernel/ Views/ RngViewsTest.php
File
- src/
Tests/ RngTestTrait.php, line 14
Namespace
Drupal\rng\TestsView source
trait RngTestTrait {
/**
* Create and save a registration type entity.
*
* @return \Drupal\rng\RegistrationTypeInterface
* A registration type entity
*/
protected function createRegistrationType() {
$registration_type = RegistrationType::create([
'id' => 'registration_type_a',
'label' => 'Registration Type A',
'description' => 'Description for registration type a',
]);
$registration_type
->save();
return $registration_type;
}
/**
* Creates an event type config.
*
* @param string $entity_type_id
* An entity type ID
* @param string $bundle
* An entity type bundle.
* @param array $values
* Optional values for the event type.
*
* @return \Drupal\rng\EventTypeInterface
* An event type config.
*/
protected function createEventType($entity_type_id, $bundle, $values = []) {
$event_type = EventType::create($values + [
'label' => 'Event Type A',
'entity_type' => $entity_type_id,
'bundle' => $bundle,
'mirror_operation_to_event_manage' => 'update',
]);
$event_type
->setIdentityTypeReference('user', 'user', TRUE);
$event_type
->setDefaultRegistrantType('registrant');
$event_type
->save();
return $event_type;
}
/**
* Create an event.
*
* @return \Drupal\rng\EventMetaInterface
*/
protected function createEvent($values = []) {
$event = EntityTest::create($values + [
EventManagerInterface::FIELD_REGISTRATION_TYPE => $this->registrationType
->id(),
EventManagerInterface::FIELD_STATUS => TRUE,
EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS => 0,
]);
$event
->save();
return $this->eventManager
->getMeta($event);
}
/**
* Create a registration and add an identity as a registrant.
*
* @param \Drupal\Core\Entity\EntityInterface $event
* An event entity
* @param \Drupal\rng\RegistrationTypeInterface $registration_type
* A registration type.
* @param \Drupal\Core\Entity\EntityInterface[] $identities
* An array of identities.
*
* @return \Drupal\rng\RegistrationInterface
* A saved registration
*/
protected function createRegistration(EntityInterface $event, RegistrationTypeInterface $registration_type, array $identities) {
$registration = Registration::create([
'type' => $registration_type
->id(),
]);
foreach ($identities as $identity) {
$registration
->addIdentity($identity);
}
$registration
->setEvent($event)
->save();
return $registration;
}
/**
* Create rules for an event type.
*
* @param array $roles
* An array of role ID to add access.
* @param array $operations
* An array of operations. Value is boolean whether to grant, key can be
* any of 'create', 'view', 'update', 'delete'.
*/
protected function createUserRoleRules($roles = [], $operations = []) {
$rule = EventTypeRule::create([
'trigger' => 'rng_event.register',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'machine_name' => 'user_role',
]);
$rule
->setCondition('role', [
'id' => 'rng_user_role',
'roles' => $roles,
]);
$rule
->setAction('registration_operations', [
'id' => 'registration_operations',
'configuration' => [
'operations' => $operations,
],
]);
$rule
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RngTestTrait:: |
protected | function | Create an event. | |
RngTestTrait:: |
protected | function | Creates an event type config. | |
RngTestTrait:: |
protected | function | Create a registration and add an identity as a registrant. | 1 |
RngTestTrait:: |
protected | function | Create and save a registration type entity. | |
RngTestTrait:: |
protected | function | Create rules for an event type. |