Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / tests / src / Functional / Plugin / ViewsBulkTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Plugin;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6
7 /**
8  * Tests views bulk operation selection.
9  *
10  * @group views
11  */
12 class ViewsBulkTest extends ViewTestBase {
13
14   /**
15    * An admin user
16    *
17    * @var \Drupal\user\UserInterface
18    */
19   protected $admin_user;
20
21   /**
22    * Modules to enable.
23    *
24    * @var array
25    */
26   public static $modules = ['node', 'views'];
27
28   public function setUp($import_test_views = TRUE) {
29     parent::setUp($import_test_views);
30
31     $this->drupalCreateContentType(['type' => 'page']);
32     $this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']);
33   }
34
35   /**
36    * Tests bulk selection.
37    */
38   public function testBulkSelection() {
39
40     // Create first node, set updated time to the past.
41     $node_1 = $this->drupalCreateNode([
42       'type' => 'page',
43       'title' => 'The first node',
44       'changed' => \Drupal::time()->getRequestTime() - 180
45     ]);
46
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());
51
52     // Create second node now that the admin overview has been rendered.
53     $node_2 = $this->drupalCreateNode([
54       'type' => 'page',
55       'title' => 'The second node',
56       'changed' => \Drupal::time()->getRequestTime() - 120
57     ]);
58
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());
64
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();
67
68     // Render the overview page again.
69     $this->drupalGet('admin/content');
70
71     // Create third node now that the admin overview has been rendered.
72     $node_3 = $this->drupalCreateNode([
73       'type' => 'page',
74       'title' => 'The third node',
75     ]);
76
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());
82   }
83
84 }