You are here

public function ViewsBulkEditActionTest::testBulkEditMultipleBundles in Views Bulk Edit 8.2

Test editing an article and a page bundle.

File

tests/src/Functional/ViewsBulkEditActionTest.php, line 101

Class

ViewsBulkEditActionTest
Tests the core edit action.

Namespace

Drupal\Tests\views_bulk_edit\Functional

Code

public function testBulkEditMultipleBundles() {
  $page1 = $this
    ->createNode();
  $article1 = $this
    ->createNode([
    'type' => 'article',
  ]);
  $this
    ->drupalGet('test-node-bulk-form');
  $this
    ->submitForm([
    'action' => 'node_edit_action',
    'node_bulk_form[0]' => TRUE,
    'node_bulk_form[1]' => TRUE,
  ], 'Apply to selected items');
  $random_title = $this
    ->randomMachineName();
  $this
    ->submitForm([
    'node[page][_field_selector][title]' => '1',
    'node[page][title][0][value]' => $random_title,
    'node[article][_field_selector][title]' => '1',
    'node[article][title][0][value]' => $random_title,
  ], 'Confirm');

  // Assert property and field is changed.
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $storage
    ->resetCache();
  $nodes = array_values($storage
    ->loadMultiple([
    $page1
      ->id(),
    $article1
      ->id(),
  ]));
  $this
    ->assertEquals($random_title, $nodes[0]
    ->getTitle());
  $this
    ->assertEquals($random_title, $nodes[1]
    ->getTitle());
}