public function ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormAdvanced in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 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()
- 4.0.x 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 163
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.
$edit = [
'action' => 'views_bulk_operations_simple_test_action',
];
$selected = [
0,
2,
];
foreach ($selected as $index) {
$edit["views_bulk_operations_bulk_form[{$index}]"] = TRUE;
}
$this
->drupalPostForm('views-bulk-operations-test-advanced', $edit, t('Apply to selected items'));
$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.
$edit = [
'action' => 'views_bulk_operations_advanced_test_action',
];
$selected = [
0,
1,
3,
];
foreach ($selected as $index) {
$edit["views_bulk_operations_bulk_form[{$index}]"] = TRUE;
}
$this
->drupalPostForm('views-bulk-operations-test-advanced', $edit, t('Apply to selected items'));
// 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']['preconfiguration']['views_bulk_operations_advanced_test_action']['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 select all functionality with batching and entity
// property changes affecting view query results.
$edit = [
'action' => 'views_bulk_operations_advanced_test_action',
'select_all' => 1,
];
$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).
$assertSession
->pageTextContains(sprintf('Action processing results: Test (%d).', count($this->testNodes) - 1), sprintf('Action has been executed on all %d nodes.', count($this->testNodes) - 1));
$this
->assertTrue(empty($this
->cssSelect('table.views-table tr')), t("The view doesn't show any results."));
}