function AutoassignroleUserCreationRolePerPathTestCase::testUserAutoRegistrationByPath in Auto Assign Role 7
Same name and namespace in other branches
- 7.2 autoassignrole.test \AutoassignroleUserCreationRolePerPathTestCase::testUserAutoRegistrationByPath()
Test the user registration based on a path.
See also
https://www.drupal.org/node/971320
File
- ./
autoassignrole.test, line 822 - Creates tests for auto assign role module.
Class
- AutoassignroleUserCreationRolePerPathTestCase
- Extend the DrupalWebTestCase.
Code
function testUserAutoRegistrationByPath() {
// enable clean urls.
variable_set('clean_url', 1);
// Login as the admin user.
$this
->drupalLogin($this->admin_user);
// Create the AAR registration page to assign to the new role.
$this
->createAarPage($this->rid);
// Logout as an admin.
$this
->drupalLogout();
// Register as a new user with the new path.
$this
->drupalGet($this->page_path);
// Fill in the register form.
$testUserName = 'testUser-' . $this
->randomName();
$form['name'] = $testUserName;
$form['mail'] = 'test@test.com';
// Check each of our roles and submit the form.
$this
->drupalPost($this->page_path, $form, t('Create new account'));
// Logout as user registered user.
$this
->drupalLogout();
// Login as admin user to check new users role.
$this
->drupalLogin($this->admin_user);
// Get the list of users.
$this
->drupalGet('admin/people');
// Get the user span details.
$userSpans = $this
->xpath('//span[@class="username"]');
$userUrl = '';
foreach ($userSpans as $user) {
if ($user[0] == $testUserName) {
foreach ($user[0]
->attributes() as $key => $value) {
if ($key == 'about') {
$userUrl = $value;
break;
}
}
}
}
// Load the user to check their roles.
preg_match('/\\/user\\/([0-9]+)/', $userUrl, $matches);
$userId = $matches[1];
$user = user_load($userId);
$this
->assertTrue(isset($user->roles[$this->rid]), t('The user [@userId] has been assigned role: \'@roleName\' [@rid] (roles [@roles]).', array(
'@userId' => $userId,
'@roleName' => $this->roleName,
'@rid' => $this->rid,
'@roles' => print_r($user->roles, true),
)));
}