Newer
Older
Alex Pott
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* Contains \Drupal\user\Tests\Views\BulkFormTest.
*/
namespace Drupal\user\Tests\Views;
/**
* Tests the views bulk form test.
*
* @see \Drupal\user\Plugin\views\field\BulkForm
*/
class BulkFormTest extends UserTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_user_bulk_form');
public static function getInfo() {
return array(
'name' => 'User: Bulk form',
'description' => 'Tests a user bulk form.',
'group' => 'Views module integration',
);
}
/**
* Tests the user bulk form.
*/
public function testBulkForm() {
$this->drupalLogin($this->drupalCreateUser(array('administer permissions')));
// Test submitting the page with no selection.
$edit = array(
'action' => 'user_block_user_action',
);
$this->drupalPost('test-user-bulk-form', $edit, t('Apply'));
// @todo Validation errors are only shown on page refresh.
$this->drupalGet('test-user-bulk-form');
$this->assertText(t('No users selected.'));
// Assign a role to a user.
$account = entity_load('user', $this->users[0]->id());
$roles = user_role_names(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
$role = key($roles);
$this->assertFalse($account->hasRole($role), 'The user currently does not have a custom role.');
$edit = array(
'user_bulk_form[1]' => TRUE,
'action' => 'user_add_role_action.' . $role,
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the user and check their roles.
$account = entity_load('user', $account->id(), TRUE);
$this->assertTrue($account->hasRole($role), 'The user now has the custom role.');
$edit = array(
'user_bulk_form[1]' => TRUE,
'action' => 'user_remove_role_action.' . $role,
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the user and check their roles.
$account = entity_load('user', $account->id(), TRUE);
$this->assertFalse($account->hasRole($role), 'The user no longer has the custom role.');
// Block a user using the bulk form.
$this->assertTrue($account->isActive(), 'The user is not blocked.');
Alex Pott
committed
$this->assertRaw($account->label(), 'The user is found in the table.');
$edit = array(
'user_bulk_form[1]' => TRUE,
'action' => 'user_block_user_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the user and check their status.
$account = entity_load('user', $account->id(), TRUE);
$this->assertTrue($account->isBlocked(), 'The user is blocked.');
Alex Pott
committed
$this->assertNoRaw($account->label(), 'The user is not found in the table.');
// Remove the user status filter from the view.
$view = views_get_view('test_user_bulk_form');
$view->removeItem('default', 'filter', 'status');
$view->storage->save();
// Ensure the anonymous user is found.
$this->drupalGet('test-user-bulk-form');
$this->assertText(config('user.settings')->get('anonymous'));
// Attempt to block the anonymous user.
$edit = array(
'user_bulk_form[0]' => TRUE,
'action' => 'user_block_user_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
$anonymous_account = user_load(0);
$this->assertTrue($anonymous_account->isBlocked(), 'Ensure the anonymous user got blocked.');