<?php
namespace Drupal\user\Tests\Views;
class BulkFormTest extends UserTestBase {
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',
);
}
public function testBulkForm() {
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer permissions',
)));
$edit = array(
'action' => 'user_block_user_action',
);
$this
->drupalPost('test-user-bulk-form', $edit, t('Apply'));
$this
->drupalGet('test-user-bulk-form');
$this
->assertText(t('No users selected.'));
$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'));
$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'));
$account = entity_load('user', $account
->id(), TRUE);
$this
->assertFalse($account
->hasRole($role), 'The user no longer has the custom role.');
$this
->assertTrue($account->status->value, 'The user is not blocked.');
$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'));
$account = entity_load('user', $account
->id(), TRUE);
$this
->assertFalse($account->status->value, 'The user is blocked.');
$this
->assertNoRaw($account
->label(), 'The user is not found in the table.');
$view = views_get_view('test_user_bulk_form');
$view
->removeItem('default', 'filter', 'status');
$view->storage
->save();
$this
->drupalGet('test-user-bulk-form');
$this
->assertText(config('user.settings')
->get('anonymous'));
$edit = array(
'user_bulk_form[0]' => TRUE,
'action' => 'user_block_user_action',
);
$this
->drupalPost(NULL, $edit, t('Apply'));
$anonymous_account = user_load(0);
$this
->assertFalse($anonymous_account->status, 0, 'Ensure the anonymous user got blocked.');
}
}