You are here

public function ViewsBulkEditTest::testBulkEditMultipleBundles in Views Bulk Edit 8

Test editing an article and a page bundle.

File

tests/src/Functional/ViewsBulkEditTest.php, line 86

Class

ViewsBulkEditTest
Tests the Views Bulk Edit feature.

Namespace

Drupal\Tests\views_bulk_edit\Functional

Code

public function testBulkEditMultipleBundles() {
  $page1 = $this
    ->createNode();
  $article1 = $this
    ->createNode([
    'type' => 'article',
  ]);
  $this
    ->drupalPostForm('/admin/content', [
    'action' => 'node_bulk_edit',
    'node_bulk_form[0]' => $this
      ->getBulkKey($page1),
    'node_bulk_form[1]' => $this
      ->getBulkKey($article1),
  ], 'Apply to selected items');

  // @TODO, also change a field.
  $random_title = $this
    ->randomMachineName();
  $this
    ->drupalPostForm(NULL, [
    'page[field_selector][title]' => '1',
    'page[title][0][value]' => $random_title,
    'article[field_selector][title]' => '1',
    'article[title][0][value]' => $random_title,
  ], 'Save');

  // 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());
}