From d35eacbd5773db07b56d3220eacae651f4baa24f Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Sat, 11 Feb 2017 13:23:13 -0600 Subject: [PATCH] =?UTF-8?q?Issue=20#2846782=20by=20tacituseu,=20swentel,?= =?UTF-8?q?=20tim.plunkett,=20G=C3=A1bor=20Hojtsy,=20borisson=5F:=20Bulk?= =?UTF-8?q?=20operation=20actions=20might=20not=20act=20on=20the=20selecte?= =?UTF-8?q?d=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Plugin/views/field/BulkForm.php | 3 +- .../views/src/Tests/Plugin/ViewsBulkTest.php | 85 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 core/modules/views/src/Tests/Plugin/ViewsBulkTest.php diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php index f9f581b426ca..a2cfdd2583de 100644 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ b/core/modules/system/src/Plugin/views/field/BulkForm.php @@ -345,7 +345,8 @@ protected function getBulkOptions($filtered = TRUE) { public function viewsFormSubmit(&$form, FormStateInterface $form_state) { if ($form_state->get('step') == 'views_form_views_form') { // Filter only selected checkboxes. - $selected = array_filter($form_state->getValue($this->options['id'])); + $user_input = $form_state->getUserInput(); + $selected = array_filter($user_input[$this->options['id']]); $entities = array(); $action = $this->actions[$form_state->getValue('action')]; $count = 0; diff --git a/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php b/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php new file mode 100644 index 000000000000..fd988895349f --- /dev/null +++ b/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php @@ -0,0 +1,85 @@ +<?php + +namespace Drupal\views\Tests\Plugin; + +use Drupal\simpletest\WebTestBase; + +/** + * Tests views bulk operation selection. + * + * @group views + */ +class ViewsBulkTest extends WebTestBase { + + /** + * An admin user + * + * @var \Drupal\user\UserInterface + */ + protected $admin_user; + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('node', 'views'); + + public function setUp() { + parent::setUp(); + + $this->drupalCreateContentType(['type' => 'page']); + $this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']); + } + + /** + * Tests bulk selection. + */ + public function testBulkSelection() { + + // Create first node, set updated time to the past. + $node_1 = $this->drupalCreateNode([ + 'type' => 'page', + 'title' => 'The first node', + 'changed' => \Drupal::time()->getRequestTime() - 180 + ]); + + // Login as administrator and go to admin/content. + $this->drupalLogin($this->admin_user); + $this->drupalGet('admin/content'); + $this->assertText($node_1->getTitle()); + + // Create second node now that the admin overview has been rendered. + $node_2 = $this->drupalCreateNode([ + 'type' => 'page', + 'title' => 'The second node', + 'changed' => \Drupal::time()->getRequestTime() - 120 + ]); + + // Now click 'Apply to selected items' and assert the first node is selected + // on the confirm form. + $this->drupalPostForm(NULL, ['node_bulk_form[0]' => TRUE], 'Apply to selected items'); + $this->assertText($node_1->getTitle()); + $this->assertNoText($node_2->getTitle()); + + // Change the pager limit to 2. + $this->config('views.view.content')->set('display.default.display_options.pager.options.items_per_page', 2)->save(); + $this->drupalGet('admin/content'); + + // Render the overview page again. + $this->drupalGet('admin/content'); + + // Create third node now that the admin overview has been rendered. + $node_3 = $this->drupalCreateNode([ + 'type' => 'page', + 'title' => 'The third node'] + ); + + // Now click 'Apply to selected items' and assert the second node is + // selected on the confirm form. + $this->drupalPostForm(NULL, ['node_bulk_form[1]' => TRUE], 'Apply to selected items'); + $this->assertText($node_1->getTitle()); + $this->assertNoText($node_3->getTitle()); + } + +} -- GitLab