Skip to content
Snippets Groups Projects
Commit 02a1c3e2 authored by Brian Canini's avatar Brian Canini
Browse files

Updating drupal/views_bulk_operations (3.4.0 => 3.8.0)

parent 8553f256
No related branches found
No related tags found
No related merge requests found
Showing
with 296 additions and 195 deletions
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "97a7b4312e4113ee81b8d863f237ad12",
"content-hash": "9385d966f0e46610c11ed19f6983d8c3",
"packages": [
{
"name": "alchemy/zippy",
......@@ -8216,29 +8216,32 @@
},
{
"name": "drupal/views_bulk_operations",
"version": "3.4.0",
"version": "3.8.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/views_bulk_operations.git",
"reference": "8.x-3.4"
"reference": "8.x-3.8"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/views_bulk_operations-8.x-3.4.zip",
"reference": "8.x-3.4",
"shasum": "549eb149f82fbf30e975155a14cd7a0d4653dfe9"
"url": "https://ftp.drupal.org/files/projects/views_bulk_operations-8.x-3.8.zip",
"reference": "8.x-3.8",
"shasum": "0f8a736d14e034db42de685ebd6cc5f86583375b"
},
"require": {
"drupal/core": "~8.5"
"drupal/core": "^8.8 || ^9"
},
"require-dev": {
"drush/drush": "^10"
},
"suggest": {
"drush/drush": "^9 || ^10"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev"
},
"drupal": {
"version": "8.x-3.4",
"datestamp": "1580924754",
"version": "8.x-3.8",
"datestamp": "1591296880",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -8246,13 +8249,13 @@
},
"drush": {
"services": {
"drush.services.yml": "^9"
"drush.services.yml": "^9 || ^10"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
......
......@@ -8472,30 +8472,33 @@
},
{
"name": "drupal/views_bulk_operations",
"version": "3.4.0",
"version_normalized": "3.4.0.0",
"version": "3.8.0",
"version_normalized": "3.8.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/views_bulk_operations.git",
"reference": "8.x-3.4"
"reference": "8.x-3.8"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/views_bulk_operations-8.x-3.4.zip",
"reference": "8.x-3.4",
"shasum": "549eb149f82fbf30e975155a14cd7a0d4653dfe9"
"url": "https://ftp.drupal.org/files/projects/views_bulk_operations-8.x-3.8.zip",
"reference": "8.x-3.8",
"shasum": "0f8a736d14e034db42de685ebd6cc5f86583375b"
},
"require": {
"drupal/core": "~8.5"
"drupal/core": "^8.8 || ^9"
},
"require-dev": {
"drush/drush": "^10"
},
"suggest": {
"drush/drush": "^9 || ^10"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev"
},
"drupal": {
"version": "8.x-3.4",
"datestamp": "1580924754",
"version": "8.x-3.8",
"datestamp": "1591296880",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -8503,14 +8506,14 @@
},
"drush": {
"services": {
"drush.services.yml": "^9"
"drush.services.yml": "^9 || ^10"
}
}
},
"installation-source": "dist",
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
......
......@@ -13,15 +13,21 @@
"issues": "https://www.drupal.org/project/issues/views_bulk_operations?version=8.x",
"docs": "https://www.drupal.org/docs/8/modules/views-bulk-operations-vbo"
},
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"drupal/core": "~8.5"
"drupal/core": "^8.8 || ^9"
},
"require-dev": {
"drush/drush": "^10"
},
"suggest": {
"drush/drush": "^9 || ^10"
},
"extra": {
"drush": {
"services": {
"drush.services.yml": "^9"
"drush.services.yml": "^9 || ^10"
}
}
}
......
......@@ -18,11 +18,17 @@ views.field.views_bulk_operations_bulk_form:
type: string
label: 'Title of the action selector form element'
selected_actions:
type: ignore
label: 'Selected actions array'
preconfiguration:
type: ignore
label: 'Preliminary configuration array'
type: sequence
label: 'Selected actions data array'
sequence:
type: mapping
mapping:
action_id:
type: string
label: 'Action plugin ID'
preconfiguration:
label: 'Preliminary configuration array for the plugin'
type: ignore
clear_on_exposed:
type: boolean
label: 'Clear selection when exposed filters change'
......@@ -22,22 +22,6 @@
Drupal.viewsBulkOperationsUi = function () {
var uiElement = $(this);
// Show / hide actions' preliminary configuration.
uiElement.find('.vbo-action-state').each(function () {
var matches = $(this).attr('name').match(/.*\[.*?\]\[(.*?)\]\[.*?\]/);
if (typeof (matches[1]) != 'undefined') {
var preconfigurationElement = uiElement.find('*[data-for="' + matches[1] + '"]');
$(this).change(function (event) {
if ($(this).is(':checked')) {
preconfigurationElement.show('fast');
}
else {
preconfigurationElement.hide('fast');
}
});
}
});
// Select / deselect all functionality.
var actionsElementWrapper = uiElement.find('details.vbo-actions-widget > .details-wrapper');
if (actionsElementWrapper.length) {
......
......@@ -2,11 +2,11 @@ type: module
name: 'Actions Permissions'
description: 'Adds access permissions on all actions allowing admins to restrict access on a per-role basis.'
package: 'Views Bulk Operations'
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:views_bulk_operations
# Information added by Drupal.org packaging script on 2020-02-04
version: '8.x-3.4'
# Information added by Drupal.org packaging script on 2020-06-04
version: '8.x-3.8'
project: 'views_bulk_operations'
datestamp: 1580807961
datestamp: 1591296882
......@@ -2,11 +2,11 @@ type: module
name: 'Views Bulk Operations example'
description: 'Defines an example action with all possible options.'
package: 'Examples'
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:views_bulk_operations
# Information added by Drupal.org packaging script on 2020-02-04
version: '8.x-3.4'
# Information added by Drupal.org packaging script on 2020-06-04
version: '8.x-3.8'
project: 'views_bulk_operations'
datestamp: 1580807961
datestamp: 1591296882
......@@ -2,8 +2,8 @@
namespace Drupal\views_bulk_operations\Action;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Core\Action\ActionBase;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\Core\Session\AccountInterface;
......@@ -14,7 +14,7 @@
* Provides a base implementation for a configurable
* and preconfigurable VBO Action plugin.
*/
abstract class ViewsBulkOperationsActionBase extends ActionBase implements ViewsBulkOperationsActionInterface, ConfigurablePluginInterface {
abstract class ViewsBulkOperationsActionBase extends ActionBase implements ViewsBulkOperationsActionInterface, ConfigurableInterface {
/**
* Action context.
......@@ -124,13 +124,6 @@ public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* Default custom access callback.
*
......
......@@ -142,6 +142,7 @@ public function __construct(
$this->tempStoreFactory = $tempStoreFactory;
$this->currentUser = $currentUser;
$this->requestStack = $requestStack;
}
/**
......@@ -352,10 +353,9 @@ protected function defineOptions() {
$options['batch_size'] = ['default' => 10];
$options['form_step'] = ['default' => TRUE];
$options['buttons'] = ['default' => FALSE];
$options['clear_on_exposed'] = ['default' => FALSE];
$options['clear_on_exposed'] = ['default' => TRUE];
$options['action_title'] = ['default' => $this->t('Action')];
$options['selected_actions'] = ['default' => []];
$options['preconfiguration'] = ['default' => []];
return $options;
}
......@@ -411,7 +411,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['clear_on_exposed'] = [
'#type' => 'checkbox',
'#title' => $this->t('Clear selection when exposed filters change.'),
'#description' => $this->t('With this enabled, selection will be cleared everey time exposed filters are changed, select all will select all rows with exposed filters applied and view total count will take exposed filters into account. When disabled, select all selects all results in the view with empty exposed filters and one can change exposed filters while selecting rows without the selection being lost.'),
'#description' => $this->t('With this enabled, selection will be cleared every time exposed filters are changed, select all will select all rows with exposed filters applied and view total count will take exposed filters into account. When disabled, select all selects all results in the view with empty exposed filters and one can change exposed filters while selecting rows without the selection being lost.'),
'#default_value' => $this->options['clear_on_exposed'],
];
......@@ -433,56 +433,70 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// Load values for display.
$form_values = $form_state->getValue(['options', 'selected_actions']);
if (is_null($form_values)) {
$selected_actions = $this->options['selected_actions'];
$preconfiguration = $this->options['preconfiguration'];
$config_data = $this->options['selected_actions'];
$selected_actions_data = [];
foreach ($config_data as $key => $item) {
$selected_actions_data[$item['action_id']] = $item;
}
}
else {
$selected_actions = [];
$preconfiguration = [];
foreach ($form_values as $id => $value) {
$selected_actions[$id] = $value['state'] ? $id : 0;
$preconfiguration[$id] = isset($value['preconfiguration']) ? $value['preconfiguration'] : [];
}
$selected_actions_data = $form_values;
}
$delta = 0;
foreach ($this->actions as $id => $action) {
$form['selected_actions'][$id]['state'] = [
$form['selected_actions'][$delta]['action_id'] = [
'#type' => 'value',
'#value' => $id,
];
$form['selected_actions'][$delta]['state'] = [
'#type' => 'checkbox',
'#title' => $action['label'],
'#default_value' => empty($selected_actions[$id]) ? 0 : 1,
'#default_value' => empty($selected_actions_data[$id]) ? 0 : 1,
'#attributes' => ['class' => ['vbo-action-state']],
];
// There are problems with AJAX on this form when adding
// new elements (Views issue), a workaround is to render
// all elements and show/hide them when needed.
$form['selected_actions'][$id]['preconfiguration'] = [
$form['selected_actions'][$delta]['preconfiguration'] = [
'#type' => 'fieldset',
'#title' => $this->t('Preconfiguration for "@action"', [
'@action' => $action['label'],
]),
'#attributes' => [
'data-for' => $id,
'style' => empty($selected_actions[$id]) ? 'display: none' : NULL,
'#states' => [
'visible' => [
sprintf('[name="options[selected_actions][%d][state]"]', $delta) => ['checked' => TRUE],
],
],
];
// Default label_override element.
$form['selected_actions'][$id]['preconfiguration']['label_override'] = [
$form['selected_actions'][$delta]['preconfiguration']['label_override'] = [
'#type' => 'textfield',
'#title' => $this->t('Override label'),
'#description' => $this->t('Leave empty for the default label.'),
'#default_value' => isset($preconfiguration[$id]['label_override']) ? $preconfiguration[$id]['label_override'] : '',
'#default_value' => isset($selected_actions_data[$id]['preconfiguration']['label_override']) ? $selected_actions_data[$id]['preconfiguration']['label_override'] : '',
];
// Load preconfiguration form if available.
if (method_exists($action['class'], 'buildPreConfigurationForm')) {
if (!isset($preconfiguration[$id])) {
$preconfiguration[$id] = [];
if (!isset($selected_actions_data[$id]['preconfiguration'])) {
$selected_actions_data[$id]['preconfiguration'] = [];
}
$actionObject = $this->actionManager->createInstance($id);
$form['selected_actions'][$id]['preconfiguration'] = $actionObject->buildPreConfigurationForm($form['selected_actions'][$id]['preconfiguration'], $preconfiguration[$id], $form_state);
// Set the view so the configuration form can access to it.
if ($this->view instanceof ViewExecutable) {
if ($this->view->inited !== TRUE) {
$this->view->initHandlers();
}
$actionObject->setView($this->view);
}
$form['selected_actions'][$delta]['preconfiguration'] = $actionObject->buildPreConfigurationForm($form['selected_actions'][$delta]['preconfiguration'], $selected_actions_data[$id]['preconfiguration'], $form_state);
}
$delta++;
}
parent::buildOptionsForm($form, $form_state);
......@@ -492,18 +506,17 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$options = &$form_state->getValue('options');
foreach ($options['selected_actions'] as $id => $action) {
if (!empty($action['state'])) {
if (isset($action['preconfiguration'])) {
$options['preconfiguration'][$id] = $action['preconfiguration'];
unset($options['selected_actions'][$id]['preconfiguration']);
}
$options['selected_actions'][$id] = $id;
$selected_actions = &$form_state->getValue(['options', 'selected_actions']);
$selected_actions = array_filter($selected_actions, function ($action_data) {
return !empty($action_data['state']);
});
foreach ($selected_actions as $delta => &$item) {
unset($item['state']);
if (empty($item['preconfiguration']['label_override'])) {
unset($item['preconfiguration']['label_override']);
}
else {
unset($options['preconfiguration'][$id]);
$options['selected_actions'][$id] = 0;
if (empty($item['preconfiguration'])) {
unset($item['preconfiguration']);
}
}
parent::submitOptionsForm($form, $form_state);
......@@ -767,12 +780,13 @@ public static function viewsFormAjax(array $form, FormStateInterface $form_state
protected function getBulkOptions() {
if (!isset($this->bulkOptions)) {
$this->bulkOptions = [];
foreach ($this->actions as $id => $definition) {
// Filter out actions that weren't selected.
if (!in_array($id, $this->options['selected_actions'], TRUE)) {
foreach ($this->options['selected_actions'] as $key => $selected_action_data) {
if (!isset($this->actions[$selected_action_data['action_id']])) {
continue;
}
$definition = $this->actions[$selected_action_data['action_id']];
// Check access permission, if defined.
if (!empty($definition['requirements']['_permission']) && !$this->currentUser->hasPermission($definition['requirements']['_permission'])) {
continue;
......@@ -784,11 +798,11 @@ protected function getBulkOptions() {
}
// Override label if applicable.
if (!empty($this->options['preconfiguration'][$id]['label_override'])) {
$this->bulkOptions[$id] = $this->options['preconfiguration'][$id]['label_override'];
if (!empty($selected_action_data['preconfiguration']['label_override'])) {
$this->bulkOptions[$key] = $selected_action_data['preconfiguration']['label_override'];
}
else {
$this->bulkOptions[$id] = $definition['label'];
$this->bulkOptions[$key] = $definition['label'];
}
}
}
......@@ -807,14 +821,14 @@ protected function getBulkOptions() {
public function viewsFormSubmit(array &$form, FormStateInterface $form_state) {
if ($form_state->get('step') == 'views_form_views_form') {
$action_id = $form_state->getValue('action');
$action_config = $this->options['selected_actions'][$form_state->getValue('action')];
$action = $this->actions[$action_id];
$action = $this->actions[$action_config['action_id']];
$this->tempStoreData['action_id'] = $action_id;
$this->tempStoreData['action_label'] = empty($this->options['preconfiguration'][$action_id]['label_override']) ? (string) $action['label'] : $this->options['preconfiguration'][$action_id]['label_override'];
$this->tempStoreData['action_id'] = $action_config['action_id'];
$this->tempStoreData['action_label'] = empty($action_config['preconfiguration']['label_override']) ? (string) $action['label'] : $action_config['preconfiguration']['label_override'];
$this->tempStoreData['relationship_id'] = $this->options['relationship'];
$this->tempStoreData['preconfiguration'] = isset($this->options['preconfiguration'][$action_id]) ? $this->options['preconfiguration'][$action_id] : [];
$this->tempStoreData['preconfiguration'] = isset($action_config['preconfiguration']) ? $action_config['preconfiguration'] : [];
$this->tempStoreData['clear_on_exposed'] = $this->options['clear_on_exposed'];
$configurable = $this->isActionConfigurable($action);
......@@ -918,17 +932,23 @@ public function clearSelection(array &$form, FormStateInterface $form_state) {
public function viewsFormValidate(&$form, FormStateInterface $form_state) {
if ($this->options['buttons']) {
$trigger = $form_state->getTriggeringElement();
$action_id = end($trigger['#parents']);
$form_state->setValue('action', $action_id);
$action_delta = end($trigger['#parents']);
$form_state->setValue('action', $action_delta);
}
else {
$action_delta = $form_state->getValue('action');
}
if (empty($form_state->getValue('action'))) {
if ($action_delta === '') {
$form_state->setErrorByName('action', $this->t('Please select an action to perform.'));
}
// This happened once, can't reproduce but here's a safety switch.
if (!isset($this->actions[$form_state->getValue('action')])) {
$form_state->setErrorByName('action', $this->t('Form error occurred, please try again.'));
else {
if (!isset($this->options['selected_actions'][$action_delta])) {
$form_state->setErrorByName('action', $this->t('Form error occurred, please try again.'));
}
elseif (!isset($this->actions[$this->options['selected_actions'][$action_delta]['action_id']])) {
$form_state->setErrorByName('action', $this->t('Form error occurred, Unavailable action selected.'));
}
}
if (!$form_state->getValue('select_all')) {
......
......@@ -65,7 +65,10 @@ protected function findDefinitions() {
// Incompatible actions.
$incompatible = [
// Deprecated anyway, to be deleted eventually.
'node_delete_action',
// Those are up to date.
'entity:delete_action:node',
'user_cancel_user_action',
];
......
......@@ -210,6 +210,26 @@ public function getPageList($page) {
$this->view->setExposedInput(['_views_bulk_operations_override' => TRUE]);
}
// In some cases we may encounter nondeterministic bahaviour in
// db queries with sorts allowing different order of results.
// To fix this we're removing all sorts and setting one sorting
// rule by the view base id field.
$sorts = $this->view->getHandlers('sort');
foreach ($sorts as $id => $sort) {
$this->view->setHandler($this->bulkFormData['display_id'], 'sort', $id, NULL);
}
$base_field = $this->view->storage->get('base_field');
$this->view->setHandler($this->bulkFormData['display_id'], 'sort', $base_field, [
'id' => $base_field,
'table' => $this->view->storage->get('base_table'),
'field' => $base_field,
'order' => 'ASC',
'relationship' => 'none',
'group_type' => 'group',
'exposed' => 'FALSE',
'plugin_id' => 'standard',
]);
$this->view->setItemsPerPage($this->bulkFormData['batch_size']);
$this->view->setCurrentPage($page);
$this->view->build();
......
......@@ -3,6 +3,7 @@
namespace Drupal\views_bulk_operations\Service;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Drupal\Core\Pager\PagerManagerInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Views;
......@@ -22,6 +23,13 @@ class ViewsBulkOperationsViewData implements ViewsBulkOperationsViewDataInterfac
*/
protected $eventDispatcher;
/**
* Pager manager service.
*
* @var \Drupal\Core\Pager\PagerManagerInterface
*/
protected $pagerManager;
/**
* The current view.
*
......@@ -62,9 +70,15 @@ class ViewsBulkOperationsViewData implements ViewsBulkOperationsViewDataInterfac
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* The event dispatcher service.
* @param \Drupal\Core\Pager\PagerManagerInterface $pagerManager
* Pager manager service.
*/
public function __construct(EventDispatcherInterface $eventDispatcher) {
public function __construct(
EventDispatcherInterface $eventDispatcher,
PagerManagerInterface $pagerManager
) {
$this->eventDispatcher = $eventDispatcher;
$this->pagerManager = $pagerManager;
}
/**
......@@ -159,30 +173,6 @@ public function getEntity(ResultRow $row) {
}
}
/**
* Helper function that restores pager data.
*
* Pager data is stored in global variables and changed every
* time the view is executed, even if in a new object instance
* so we need to save and restore the original values.
*/
protected function fixPagerData() {
static $values;
if (!isset($values)) {
foreach (['pager_page_array', 'pager_total', 'pager_total_items'] as $key) {
if (isset($GLOBALS[$key])) {
$values[$key] = $GLOBALS[$key];
}
}
}
elseif (!empty($values)) {
foreach ($values as $key => $value) {
$GLOBALS[$key] = $value;
}
unset($values);
}
}
/**
* Get the total count of results on all pages.
*
......@@ -196,6 +186,11 @@ public function getTotalResults($clear_on_exposed = FALSE) {
$total_results = NULL;
if (!$clear_on_exposed && !empty($this->view->getExposedInput())) {
if ($pager = $this->view->getPager()) {
$pager_options = $pager->options;
$pager_options['total_items'] = $pager->getTotalItems();
}
// Execute the view without exposed input set.
$view = Views::getView($this->view->id());
$view->setDisplay($this->view->current_display);
......@@ -208,19 +203,16 @@ public function getTotalResults($clear_on_exposed = FALSE) {
// We have to set exposed input to some value here, empty
// value will be overwritten with query params by Views so
// setting an empty array wouldn't work.
$pager = $view->getPager();
$view->setExposedInput(['_views_bulk_operations_override' => TRUE]);
}
else {
$view = $this->view;
}
$this->fixPagerData();
// Execute the view if not already executed.
$view->execute();
$this->fixPagerData();
if (!empty($view->pager->total_items)) {
$total_results = $view->pager->total_items;
}
......@@ -228,6 +220,10 @@ public function getTotalResults($clear_on_exposed = FALSE) {
$total_results = $view->total_rows;
}
if (!empty($pager_options)) {
$this->pagerManager->createPager($pager_options['total_items'], $pager_options['items_per_page'], $pager_options['id']);
}
return $total_results;
}
......
<?php
namespace Drupal\Tests\views_bulk_operations\Functional;
use Drupal\Tests\BrowserTestBase;
use Drush\TestTraits\DrushTestTrait;
/**
* @coversDefaultClass \Drupal\views_bulk_operations\Commands\ViewsBulkOperationsCommands
* @group views_bulk_operations
*/
class DrushCommandsTest extends BrowserTestBase {
use DrushTestTrait;
const TEST_NODE_COUNT = 15;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to install.
*
* @var array
*/
public static $modules = [
'node',
'views',
'views_bulk_operations',
'views_bulk_operations_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some nodes for testing.
$this->drupalCreateContentType(['type' => 'page']);
$this->testNodes = [];
$time = $this->container->get('datetime.time')->getRequestTime();
for ($i = 0; $i < self::TEST_NODE_COUNT; $i++) {
// Ensure nodes are sorted in the same order they are inserted in the
// array.
$time -= $i;
$this->testNodes[] = $this->drupalCreateNode([
'type' => 'page',
'title' => 'Title ' . $i,
'sticky' => FALSE,
'created' => $time,
'changed' => $time,
]);
}
}
/**
* Tests the VBO Drush command.
*/
public function testDrushCommand() {
$this->drush('vbo-exec', ['views_bulk_operations_test', 'views_bulk_operations_simple_test_action']);
$this->assertStringContainsString('Test action (preconfig: , label: Title 0)', $this->getErrorOutput());
$this->assertStringContainsString('Test action (preconfig: , label: Title 14)', $this->getErrorOutput());
}
}
......@@ -13,6 +13,11 @@ class ViewsBulkOperationsBulkFormTest extends BrowserTestBase {
const TEST_NODE_COUNT = 15;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stable';
/**
* Modules to install.
*
......@@ -103,7 +108,7 @@ public function testViewsBulkOperationsBulkFormSimple() {
// Test that the views edit header appears first.
$first_form_element = $this->xpath('//form/div[1][@id = :id]', [':id' => 'edit-header']);
$this->assertTrue($first_form_element, 'The views form edit header appears first.');
$this->assertNotEmpty($first_form_element, 'The views form edit header appears first.');
// Make sure a checkbox appears on all rows.
$edit = [];
......@@ -112,7 +117,7 @@ public function testViewsBulkOperationsBulkFormSimple() {
}
// The advanced action should not be shown on the form - no permission.
$this->assertTrue(empty($this->cssSelect('select[name=views_bulk_operations_advanced_test_action]')), t('Advanced action is not selectable.'));
$this->assertEmpty($this->cssSelect('input[value=views_bulk_operations_advanced_test_action]'), t('Advanced action is not selectable.'));
// Log in as a user with 'edit any page content' permission
// to have access to perform the test operation.
......@@ -131,7 +136,7 @@ public function testViewsBulkOperationsBulkFormSimple() {
$testViewConfig = \Drupal::service('config.factory')->get('views.view.views_bulk_operations_test');
$configData = $testViewConfig->getRawData();
$preconfig_setting = $configData['display']['default']['display_options']['fields']['views_bulk_operations_bulk_form']['preconfiguration']['views_bulk_operations_simple_test_action']['preconfig'];
$preconfig_setting = $configData['display']['default']['display_options']['fields']['views_bulk_operations_bulk_form']['selected_actions'][0]['preconfiguration']['preconfig'];
foreach ($selected as $index) {
$assertSession->pageTextContains(
......@@ -182,7 +187,7 @@ public function testViewsBulkOperationsBulkFormAdvanced() {
// First execute the simple action to test
// the ViewsBulkOperationsController class.
$edit = [
'action' => 'views_bulk_operations_simple_test_action',
'action' => 0,
];
$selected = [0, 2];
foreach ($selected as $index) {
......@@ -197,7 +202,7 @@ public function testViewsBulkOperationsBulkFormAdvanced() {
// Execute the advanced test action.
$edit = [
'action' => 'views_bulk_operations_advanced_test_action',
'action' => 1,
];
$selected = [0, 1, 3];
foreach ($selected as $index) {
......@@ -230,7 +235,7 @@ public function testViewsBulkOperationsBulkFormAdvanced() {
// the next page should display results.
$testViewConfig = \Drupal::service('config.factory')->get('views.view.views_bulk_operations_test_advanced');
$configData = $testViewConfig->getRawData();
$preconfig_setting = $configData['display']['default']['display_options']['fields']['views_bulk_operations_bulk_form']['preconfiguration']['views_bulk_operations_advanced_test_action']['test_preconfig'];
$preconfig_setting = $configData['display']['default']['display_options']['fields']['views_bulk_operations_bulk_form']['selected_actions'][1]['preconfiguration']['test_preconfig'];
// NOTE: The view pager has an offset set on this view, so checkbox
// indexes are not equal to test nodes array keys. Hence the $index + 1.
......@@ -245,7 +250,7 @@ public function testViewsBulkOperationsBulkFormAdvanced() {
// Test the exclude functionality with batching and entity
// property changes affecting view query results.
$edit = [
'action' => 'views_bulk_operations_advanced_test_action',
'action' => 1,
'select_all' => 1,
];
// Let's leave two checkboxes unchecked to test the exclude mode.
......@@ -261,7 +266,8 @@ public function testViewsBulkOperationsBulkFormAdvanced() {
sprintf('Action processing results: Test (%d).', (count($this->testNodes) - 3)),
sprintf('Action has been executed on all %d nodes.', (count($this->testNodes) - 3))
);
$this->assertTrue((count($this->cssSelect('table.views-table tbody tr')) === 2), t("The view shows only excluded results."));
$this->assertNotEmpty((count($this->cssSelect('table.vbo-table tbody tr')) === 2), "The view shows only excluded results.");
}
/**
......@@ -302,7 +308,7 @@ public function testViewsBulkOperationsBulkFormPassing() {
// Populate form values.
$edit = [
'action' => 'views_bulk_operations_passing_test_action',
'action' => 2,
];
if ($case['selection']) {
foreach ($selected as $index) {
......
......@@ -2,8 +2,6 @@
namespace Drupal\Tests\views_bulk_operations\Kernel;
use Drupal\node\NodeInterface;
/**
* @coversDefaultClass \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor
* @group views_bulk_operations
......@@ -34,19 +32,14 @@ public function setUp() {
protected function assertNodeStatuses(array $list, $exclude = FALSE) {
$nodeStorage = $this->container->get('entity_type.manager')->getStorage('node');
$expected = [
$exclude ? NodeInterface::PUBLISHED : NodeInterface::NOT_PUBLISHED,
$exclude ? NodeInterface::NOT_PUBLISHED : NodeInterface::PUBLISHED,
];
$statuses = [];
foreach ($this->testNodesData as $id => $lang_data) {
$node = $nodeStorage->load($id);
$statuses[$id] = intval($node->status->value);
$statuses[$id] = $node->isPublished();
// Reset node status.
$node->status->value = 1;
$node->setPublished();
$node->save();
}
......@@ -54,13 +47,13 @@ protected function assertNodeStatuses(array $list, $exclude = FALSE) {
$asserted = FALSE;
foreach ($list as $item) {
if ($item[3] == $id) {
$this->assertEquals($expected[0], $status);
$this->assertEquals((bool) $exclude, $status);
$asserted = TRUE;
break;
}
}
if (!$asserted) {
$this->assertEquals($expected[1], $status);
$this->assertEquals(!(bool) $exclude, $status);
}
}
}
......
......@@ -94,12 +94,12 @@ public function testOperation() {
->with('test_view')
->will($this->returnValue($view));
$entity_manager = $this->createMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->any())
$entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface');
$entity_type_manager->expects($this->any())
->method('getStorage')
->with('view')
->will($this->returnValue($view_storage));
$this->container->set('entity.manager', $entity_manager);
$this->container->set('entity_type.manager', $entity_type_manager);
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
......
......@@ -170,15 +170,15 @@ display:
buttons: true
action_title: Action
selected_actions:
views_bulk_operations_simple_test_action: views_bulk_operations_simple_test_action
views_bulk_operations_advanced_test_action: views_bulk_operations_advanced_test_action
preconfiguration:
views_bulk_operations_simple_test_action:
label_override: 'Simple test action'
preconfig: 'Test setting'
views_bulk_operations_advanced_test_action:
label_override: ''
preconfig: 'Test setting'
0:
action_id: views_bulk_operations_simple_test_action
preconfiguration:
label_override: 'Simple test action'
preconfig: 'Test setting'
1:
action_id: views_bulk_operations_advanced_test_action
preconfiguration:
preconfig: 'Test setting'
plugin_id: views_bulk_operations_bulk_form
filters: { }
sorts:
......
......@@ -167,18 +167,17 @@ display:
buttons: false
action_title: Action
selected_actions:
views_bulk_operations_simple_test_action: views_bulk_operations_simple_test_action
views_bulk_operations_advanced_test_action: views_bulk_operations_advanced_test_action
views_bulk_operations_passing_test_action: views_bulk_operations_passing_test_action
preconfiguration:
views_bulk_operations_simple_test_action:
label_override: 'Simple test action'
preconfig: 'Test setting'
views_bulk_operations_advanced_test_action:
label_override: ''
test_preconfig: 'Test setting'
views_bulk_operations_passing_test_action:
label_override: ''
0:
action_id: views_bulk_operations_simple_test_action
preconfiguration:
label_override: 'Simple test action'
preconfig: 'Test setting'
1:
action_id: views_bulk_operations_advanced_test_action
preconfiguration:
test_preconfig: 'Test setting'
2:
action_id: views_bulk_operations_passing_test_action
plugin_id: views_bulk_operations_bulk_form
filters:
status:
......
......@@ -51,7 +51,7 @@ public function execute($entity = NULL) {
if (!$entity->isDefaultTranslation()) {
$entity = \Drupal::service('entity_type.manager')->getStorage('node')->load($entity->id());
}
$entity->setPublished(FALSE);
$entity->setUnpublished();
$entity->save();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment