public function ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormAdvanced in Views Bulk Operations (VBO) 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormAdvanced()
- 8 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormAdvanced()
- 8.2 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormAdvanced()
More advanced test.
Uses the ViewsBulkOperationsAdvancedTestAction.
File
- tests/
src/ Functional/ ViewsBulkOperationsBulkFormTest.php, line 82
Class
- ViewsBulkOperationsBulkFormTest
- @coversDefaultClass \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm @group views_bulk_operations
Namespace
Drupal\Tests\views_bulk_operations\FunctionalCode
public function testViewsBulkOperationsBulkFormAdvanced() {
$assertSession = $this
->assertSession();
// Log in as a user with 'edit any page content' permission
// to have access to perform the test operation.
$admin_user = $this
->drupalCreateUser([
'edit any page content',
'execute advanced test action',
]);
$this
->drupalLogin($admin_user);
// First execute the simple action to test
// the ViewsBulkOperationsController class.
$selected = [
0,
2,
];
$data = [
'action' => 0,
];
$this
->executeAction('views-bulk-operations-test-advanced', t('Apply to selected items'), $selected, $data);
$assertSession
->pageTextContains(sprintf('Action processing results: Test (%d).', count($selected)), sprintf('Action has been executed on %d nodes.', count($selected)));
// Execute the advanced test action.
$selected = [
0,
1,
3,
];
$data = [
'action' => 1,
];
$this
->executeAction('views-bulk-operations-test-advanced', t('Apply to selected items'), $selected, $data);
// Check if the configuration form is open and contains the
// test_config field.
$assertSession
->fieldExists('edit-test-config', NULL, 'The configuration field appears.');
// Check if the configuration form contains selected entity labels.
// 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.
foreach ($selected as $index) {
$assertSession
->pageTextContains($this->testNodes[$index + 1]
->label());
}
$config_value = 'test value';
$edit = [
'test_config' => $config_value,
];
$this
->drupalPostForm(NULL, $edit, t('Apply'));
// Execute action by posting the confirmation form
// (also tests if the submit button exists on the page).
$this
->drupalPostForm(NULL, [], t('Execute action'));
// If all went well and Batch API did its job,
// 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']['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.
foreach ($selected as $index) {
$assertSession
->pageTextContains(sprintf('Test action (preconfig: %s, config: %s, label: %s)', $preconfig_setting, $config_value, $this->testNodes[$index + 1]
->label()));
}
// Test the exclude functionality with batching and entity
// property changes affecting view query results.
$edit = [
'action' => 1,
'select_all' => 1,
];
// Let's leave two checkboxes unchecked to test the exclude mode.
foreach ([
0,
2,
] as $index) {
$edit["views_bulk_operations_bulk_form[{$index}]"] = TRUE;
}
$this
->drupalPostForm(NULL, $edit, t('Apply to selected items'));
$this
->drupalPostForm(NULL, [
'test_config' => 'unpublish',
], t('Apply'));
$this
->drupalPostForm(NULL, [], t('Execute action'));
// Again, take offset into account (-1), also take 2 excluded
// rows into account (-2).
// Also, check if the custom completed message appears.
$assertSession
->pageTextContains(sprintf('Custom processing message: Test (%d).', count($this->testNodes) - 3), sprintf('Action has been executed on all %d nodes.', count($this->testNodes) - 3));
$this
->assertNotEmpty(count($this
->cssSelect('table.vbo-table tbody tr')) === 2, "The view shows only excluded results.");
}