1 user.test | UserAdminTestCase::testUserAdmin() |
Registers a user and deletes it.
File
- core/
modules/ user/ tests/ user.test, line 1578 - Tests for user.module.
Class
Code
function testUserAdmin() {
// Create admin user to delete registered user.
$admin_user = $this->backdropCreateUser(array('administer users', 'access user profiles'));
$admin_user->created -= 2;
$admin_user->save();
$user_a = $this->backdropCreateUser(array());
$user_b = $this->backdropCreateUser(array('administer taxonomy'));
$user_c = $this->backdropCreateUser(array('administer taxonomy'));
$this->backdropLogin($admin_user);
$this->backdropGet('admin/people');
$this->assertText($user_a->name, 'Found user A on admin users page');
$this->assertText($user_b->name, 'Found user B on admin users page');
$this->assertText($user_c->name, 'Found user C on admin users page');
$this->assertText($admin_user->name, 'Found Admin user on admin users page');
// Test for existence of edit link in table.
$link = l(t('Edit'), "user/$user_a->uid/edit", array('query' => array('destination' => 'admin/people')));
$this->assertRaw($link, 'Found user A edit link on admin users page');
// Filter the users by role. Grab the system-generated role name for User C.
$c_roles = array_diff($user_c->roles, array(BACKDROP_AUTHENTICATED_ROLE));
$role_id = reset($c_roles);
$this->backdropGet('admin/people', array('query' => array('role' => $role_id)));
// Check if the correct users show up when filtered by role.
$this->assertNoText($user_a->name, 'User A not on filtered by role on admin users page');
$this->assertNoText($user_b->name, 'User B not on filtered by role on admin users page');
$this->assertText($user_c->name, 'User C on filtered by role on admin users page');
// Test blocking of a user.
$user_c = user_load($user_c->uid, TRUE);
$this->assertEqual($user_c->status, 1, 'User C not blocked');
$this->backdropGet('admin/people', array('query' => array('order' => 'created', 'sort' => 'asc')));
$checkbox = $this->xpath('//form[@id="views-form-user-admin-page"]//tr[last()]//input[@type="checkbox"]');
$user_c_checkbox = (string) $checkbox[0]['name'];
$edit = array();
$edit['action'] = 'user_block_user_action';
$edit[$user_c_checkbox] = TRUE;
$this->backdropPost('admin/people', $edit, t('Execute'), array('query' => array('order' => 'created', 'sort' => 'asc')));
$status_result = $this->xpath('//form[@id="views-form-user-admin-page"]//tr[last()]//td[position()=3]');
$this->assertEqual(trim($status_result[0]), 'Blocked', 'User C blocked');
// Test unblocking of a user from /admin/people page and sending of activation mail
$edit_unblock = array();
$edit_unblock['action'] = 'user_unblock_user_action';
$edit_unblock[$user_c_checkbox] = TRUE;
$this->backdropPost('admin/people', $edit_unblock, t('Execute'), array('query' => array('order' => 'created', 'sort' => 'asc')));
$status_result = $this->xpath('//form[@id="views-form-user-admin-page"]//tr[last()]//td[position()=3]');
$this->assertEqual(trim($status_result[0]), 'Active', 'User C unblocked');
$this->assertMail("to", $user_c->mail, "Activation mail sent to user C");
// Test blocking and unblocking another user from /user/[uid]/edit form and sending of activation mail
$user_d = $this->backdropCreateUser(array());
$account1 = user_load($user_d->uid, TRUE);
$this->backdropPost('user/' . $account1->uid . '/edit', array('status' => 0), t('Save'));
$account1 = user_load($user_d->uid, TRUE);
$this->assertEqual($account1->status, 0, 'User D blocked');
$this->backdropPost('user/' . $account1->uid . '/edit', array('status' => TRUE), t('Save'));
$account1 = user_load($user_d->uid, TRUE);
$this->assertEqual($account1->status, 1, 'User D unblocked');
$this->assertMail("to", $account1->mail, "Activation mail sent to user D");
}