public function RegistrationStandardTestCase::testRegistrationForm in Entity Registration 8.2
Same name in this branch
- 8.2 tests/registration.test \RegistrationStandardTestCase::testRegistrationForm()
- 8.2 src/RegistrationStandardTestCase.php \Drupal\registration\RegistrationStandardTestCase::testRegistrationForm()
Tests for the registration add/edit form.
File
- src/
RegistrationStandardTestCase.php, line 269
Class
- RegistrationStandardTestCase
- Creates a registration type Create node entity type ensure registration type exists
Namespace
Drupal\registrationCode
public function testRegistrationForm() {
// Setup environment - create all users we'll need for tests.
$permissions = array(
'create ' . $this->registration_type_name . ' registration',
'view own ' . $this->registration_type_name . ' registration',
'update own ' . $this->registration_type_name . ' registration',
'delete own ' . $this->registration_type_name . ' registration',
'create own ' . $this->registration_type_name . ' registration',
);
// Ensure permission set is valid before using them.
$this
->checkPermissions($permissions, TRUE);
// Create user with many permissions.
$user = $this
->drupalCreateUser($permissions);
// Create user with view permission only.
$permissions = array(
'view ' . $this->registration_type_name . ' registration',
);
$this
->checkPermissions($permissions, TRUE);
$user_view_permission = $this
->drupalCreateUser($permissions);
// Create a user with only "create own registration" permission to test with.
$permissions = array(
'create own ' . $this->registration_type_name . ' registration',
);
$this
->checkPermissions($permissions, TRUE);
$user_register_self_permission = $this
->drupalCreateUser($permissions);
// Create a user with no registration permissions to test with.
$user_no_permission = $this
->drupalCreateUser();
// #######################################################################.
// Login as user with many permissions - create registration.
// #######################################################################.
$this
->drupalLogin($user);
// Configure registration settings on host entity.
$this
->setHostEntitySettings(array(
'status' => 1,
'capacity' => 2,
'settings' => array(
'maximum_spaces' => 1,
),
));
// Submit a Registration form as the user with
// many registration permissions.
$this
->drupalGet($this->host_entity_path . '/register');
$this
->assertResponse(200, t('Register page loaded.'), 'Registration');
$registration_form = array(
'who_is_registering' => REGISTRATION_REGISTRANT_TYPE_SELF,
);
$this
->drupalPost($this->host_entity_path . '/register', $registration_form, t('Save Registration'));
$this
->assertText(t('Registration for'), t('Registration saved.'), 'Registration');
// Load registration that was just created and it's ID to be used again.
$registration_a_id = $this
->entityLastId('registration');
$registration_a = entity_load_single('registration', $registration_a_id);
// Ensure registration reports having space available.
// Capacity is set to 2 and only 1 user has registered.
$this
->assertTrue(registration_has_room($this->host_entity_type, $this->host_entity_id), t('Space available'), 'Registration');
// #######################################################################.
// Login as user with only view permission.
// #######################################################################.
$this
->drupalLogout();
$this
->drupalLogin($user_view_permission);
// Ensure user with view permission can the registration we just created.
$this
->drupalGet('registration/' . $registration_a_id);
$this
->assertResponse(200, t('User with permission can view registration'), 'Registration');
// #######################################################################.
// Login as user with no permissions.
// #######################################################################.
$this
->drupalLogout();
$this
->drupalLogin($user_no_permission);
// User with no permission - try to create, view, edit, delete registration.
// Expect failure for all attempted operations.
$this
->drupalGet($this->host_entity_path . '/register');
$this
->assertResponse(403, t('User without permission cannot create registration.'), 'Registration');
$this
->drupalGet('registration/' . $registration_a_id);
$this
->assertResponse(403, t('User without permission cannot view registration.'), 'Registration');
$this
->drupalGet('registration/' . $registration_a_id . '/edit');
$this
->assertResponse(403, t('User without permission cannot edit registration.'), 'Registration');
$this
->drupalGet('registration/' . $registration_a_id . '/delete');
$this
->assertResponse(403, t('User without permission cannot delete registration.'), 'Registration');
// #######################################################################.
// Test registered users - not necessary to be logged in as a particular
// user for this section of assertions.
// #######################################################################.
// Create a duplicate copy of the registration and unset the ID because
// registration_is_registered will exclude the passed registration.
$registration_b = $registration_a;
unset($registration_b->registration_id);
$this
->assertFalse(registration_is_registered($registration_b, $user_register_self_permission->mail), t('User who did not register is not registered.'), 'Registration');
$this
->assertTrue(registration_is_registered($registration_b, $user->mail), t('User who registered is registered.'), 'Registration');
// #######################################################################.
// Login as user with many permissions - edit, then delete registration.
// #######################################################################.
$this
->drupalLogout();
$this
->drupalLogin($user);
// Edit a registration.
$this
->drupalGet('registration/' . $registration_a_id . '/edit');
$this
->assertResponse(200, t('User can access registration edit page.'), 'Registration');
$edit = array(
'who_is_registering' => REGISTRATION_REGISTRANT_TYPE_OTHER,
'registrant_mail' => $user_no_permission->mail,
);
$this
->drupalPost('registration/' . $registration_a_id . '/edit', $edit, t('Save Registration'));
$this
->assertText(t('Registration for'), t('Registration form saved.'), 'Registration');
$this
->resetRegistration();
$registration_a = entity_load_single('registration', $registration_a_id);
$this
->drupalGet('registration/' . $registration_a_id);
$this
->assertEqual($registration_a->registrant_id, $user_no_permission->uid, t('Changed user on registration edit form.'), 'Registration');
// Delete a registration.
$this
->drupalGet('registration/' . $registration_a_id . '/delete');
$this
->assertResponse(200, 'User can access registration delete confirmation page.', 'Registration');
$this
->drupalPost('registration/' . $registration_a_id . '/delete', array(), t('Delete'));
$this
->resetRegistration();
$this
->assertFalse(entity_load_single('registration', $registration_a_id), t('Deleted registration via form'), 'Registration');
}