You are here

public function ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormSimple in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormSimple()
  2. 8.2 tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormSimple()
  3. 4.0.x tests/src/Functional/ViewsBulkOperationsBulkFormTest.php \Drupal\Tests\views_bulk_operations\Functional\ViewsBulkOperationsBulkFormTest::testViewsBulkOperationsBulkFormSimple()

Tests the VBO bulk form with simple test action.

File

tests/src/Functional/ViewsBulkOperationsBulkFormTest.php, line 95

Class

ViewsBulkOperationsBulkFormTest
@coversDefaultClass \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm @group views_bulk_operations

Namespace

Drupal\Tests\views_bulk_operations\Functional

Code

public function testViewsBulkOperationsBulkFormSimple() {
  $assertSession = $this
    ->assertSession();
  $this
    ->drupalGet('views-bulk-operations-test');

  // 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.');

  // Make sure a checkbox appears on all rows.
  $edit = [];
  for ($i = 0; $i < 4; $i++) {
    $assertSession
      ->fieldExists('edit-views-bulk-operations-bulk-form-' . $i, NULL, format_string('The checkbox on row @row appears.', [
      '@row' => $i,
    ]));
  }

  // 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.'));

  // 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',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Execute the simple test action.
  $edit = [];
  $selected = [
    0,
    2,
    3,
  ];
  foreach ($selected as $index) {
    $edit["views_bulk_operations_bulk_form[{$index}]"] = TRUE;
  }

  // Tests: actions as buttons, label override.
  $this
    ->drupalPostForm('views-bulk-operations-test', $edit, t('Simple test action'));
  $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'];
  foreach ($selected as $index) {
    $assertSession
      ->pageTextContains(sprintf('Test action (preconfig: %s, label: %s)', $preconfig_setting, $this->testNodes[$index]
      ->label()), sprintf('Action has been executed on node "%s".', $this->testNodes[$index]
      ->label()));
  }

  // Test the select all functionality.
  $edit = [
    'select_all' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Simple test action'));
  $assertSession
    ->pageTextContains(sprintf('Action processing results: Test (%d).', count($this->testNodes)), sprintf('Action has been executed on %d nodes.', count($this->testNodes)));
}