function RegistrationWaitlistTestCase::testHostRegistrationWaitlistStatus in Entity Registration 8.2
Same name in this branch
- 8.2 modules/registration_waitlist/registration_waitlist.test \RegistrationWaitlistTestCase::testHostRegistrationWaitlistStatus()
- 8.2 modules/registration_waitlist/src/RegistrationWaitlistTestCase.php \Drupal\registration_waitlist\RegistrationWaitlistTestCase::testHostRegistrationWaitlistStatus()
Check internal status modifiers for the wait list.
File
- modules/
registration_waitlist/ src/ RegistrationWaitlistTestCase.php, line 26
Class
- RegistrationWaitlistTestCase
- Creates a registration type Create node entity type Ensure registration type exists
Namespace
Drupal\registration_waitlistCode
function testHostRegistrationWaitlistStatus() {
$user = \Drupal::currentUser();
$permissions = array(
'create ' . $this->registration_type_name . ' registration',
);
$this
->checkPermissions($permissions, TRUE);
$basic_user = $this
->drupalCreateUser($permissions);
$permissions = array(
'administer ' . $this->registration_type_name . ' registration',
);
$this
->checkPermissions($permissions, TRUE);
$admin_user = $this
->drupalCreateUser($permissions);
// Start with the basic user.
$user = $basic_user;
// Enable waitlist, wl capacity = unlimited.
$this
->setHostEntitySettings(array(
'status' => 1,
'capacity' => 10,
'settings' => array(
'registration_waitlist_enable' => 1,
'registration_waitlist_capacity' => 4,
),
));
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is opened with wait list enabled.'), 'Registration');
// Fill capacity.
$registrations = array();
for ($i = 0; $i < 6; $i++) {
$registrations[$i] = $this
->createRegistration(array(
'count' => 2,
));
}
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is opened, filled with registrations.'), 'Registration');
$last_registration = entity_metadata_wrapper('registration', end($registrations));
$this
->assertTrue($last_registration->state->name
->value() === REGISTRATION_WAITLIST_STATE, t('Last registration placed on wait list.'), 'Registration');
// Test that wait list limit and reserved slots is enforced.
$registrations[] = $this
->createRegistration(array(
'count' => 2,
));
$this
->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, wait list full.'), 'Registration');
// Switch back to basic user.
$user = $basic_user;
// Unfill capacity by one registration.
end($registrations)->registration_id
->delete();
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Deleted a registration, wait list now not at maximum.'), 'Registration');
// Test dates.
$this
->setHostEntitySettings(array(
'status' => 1,
'open' => date('Y-m-d H:i:s', time() + 3600),
'close' => NULL,
'settings' => array(
'registration_waitlist_enable' => 1,
'registration_waitlist_capacity' => 0,
'registration_waitlist_reserved' => 0,
),
));
$this
->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, open time has not passed.'), 'Registration');
$this
->setHostEntitySettings(array(
'status' => 1,
'open' => date('Y-m-d H:i:s', time() - 3600),
'close' => date('Y-m-d H:i:s', time() + 3600),
'settings' => array(
'registration_waitlist_enable' => 1,
'registration_waitlist_capacity' => 0,
'registration_waitlist_reserved' => 0,
),
));
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is open, in between open and closing times.'), 'Registration');
$this
->setHostEntitySettings(array(
'status' => 1,
'open' => NULL,
'close' => date('Y-m-d H:i:s', time() - 3600),
'settings' => array(
'registration_waitlist_enable' => 1,
'registration_waitlist_capacity' => 0,
'registration_waitlist_reserved' => 0,
),
));
$this
->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, closing time has passed.'), 'Registration');
}