You are here

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

Same name and namespace in other branches
  1. 8 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 16

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
    ->assertNotEmpty($first_form_element, 'The views form edit header appears first.');

  // Make sure a checkbox appears on all rows and every checkbox has
  // the correct label.
  for ($i = 0; $i < 4; $i++) {
    $checkbox_selector = 'edit-views-bulk-operations-bulk-form-' . $i;
    $assertSession
      ->fieldExists($checkbox_selector, NULL, new FormattableMarkup('The checkbox on row @row appears.', [
      '@row' => $i,
    ]));
    $assertSession
      ->elementTextContains('css', "label[for={$checkbox_selector}]", $this->testNodes[$i]
      ->label());
  }

  // The advanced action should not be shown on the form - no permission.
  $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.
  $admin_user = $this
    ->drupalCreateUser([
    'edit any page content',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Execute the simple test action.
  $selected = [
    0,
    2,
    3,
  ];
  $this
    ->executeAction('views-bulk-operations-test', t('Simple test action'), $selected);
  $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']['selected_actions'][0]['preconfiguration']['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.
  // With the exclude mode, we also have to select all rows of the
  // view, otherwise those will be treated as excluded. In the UI
  // this is handled by JS.
  $selected = [
    0,
    1,
    2,
    3,
  ];
  $data = [
    'select_all' => 1,
  ];
  $this
    ->executeAction(NULL, t('Simple test action'), $selected, $data);
  $assertSession
    ->pageTextContains(sprintf('Action processing results: Test (%d).', self::TEST_NODE_COUNT), sprintf('Action has been executed on %d nodes.', self::TEST_NODE_COUNT));
}