3 namespace Drupal\Tests\views\Functional\Plugin;
5 use Drupal\Tests\views\Functional\ViewTestBase;
8 * Tests views bulk operation selection.
12 class ViewsBulkTest extends ViewTestBase {
17 * @var \Drupal\user\UserInterface
19 protected $admin_user;
26 public static $modules = ['node', 'views'];
28 public function setUp($import_test_views = TRUE) {
29 parent::setUp($import_test_views);
31 $this->drupalCreateContentType(['type' => 'page']);
32 $this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']);
36 * Tests bulk selection.
38 public function testBulkSelection() {
40 // Create first node, set updated time to the past.
41 $node_1 = $this->drupalCreateNode([
43 'title' => 'The first node',
44 'changed' => \Drupal::time()->getRequestTime() - 180
47 // Login as administrator and go to admin/content.
48 $this->drupalLogin($this->admin_user);
49 $this->drupalGet('admin/content');
50 $this->assertText($node_1->getTitle());
52 // Create second node now that the admin overview has been rendered.
53 $node_2 = $this->drupalCreateNode([
55 'title' => 'The second node',
56 'changed' => \Drupal::time()->getRequestTime() - 120
59 // Now click 'Apply to selected items' and assert the first node is selected
60 // on the confirm form.
61 $this->drupalPostForm(NULL, ['node_bulk_form[0]' => TRUE], 'Apply to selected items');
62 $this->assertText($node_1->getTitle());
63 $this->assertNoText($node_2->getTitle());
65 // Change the pager limit to 2.
66 $this->config('views.view.content')->set('display.default.display_options.pager.options.items_per_page', 2)->save();
68 // Render the overview page again.
69 $this->drupalGet('admin/content');
71 // Create third node now that the admin overview has been rendered.
72 $node_3 = $this->drupalCreateNode([
74 'title' => 'The third node']
77 // Now click 'Apply to selected items' and assert the second node is
78 // selected on the confirm form.
79 $this->drupalPostForm(NULL, ['node_bulk_form[1]' => TRUE], 'Apply to selected items');
80 $this->assertText($node_1->getTitle());
81 $this->assertNoText($node_3->getTitle());