You are here

public function ViewsBulkEditTest::testViewsBulkEdit in Views Bulk Edit 8

Test VBE from the UI using the node module.

File

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

Class

ViewsBulkEditTest
Tests the Views Bulk Edit feature.

Namespace

Drupal\Tests\views_bulk_edit\Functional

Code

public function testViewsBulkEdit() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $page1 = $this
    ->createNode();
  $page2 = $this
    ->createNode();
  $article1 = $this
    ->createNode([
    'type' => 'article',
  ]);

  // Test editing a single article with properties and fields.
  $this
    ->drupalPostForm('/admin/content', [
    'action' => 'node_bulk_edit',
    'node_bulk_form[0]' => $this
      ->getBulkKey($page1),
    'node_bulk_form[1]' => $this
      ->getBulkKey($page2),
  ], 'Apply to selected items');
  $random_title = $this
    ->randomMachineName();
  $this
    ->drupalPostForm(NULL, [
    'page[field_selector][title]' => '1',
    'page[title][0][value]' => $random_title,
  ], 'Save');

  // Assert property was changes. Assert field was changed.
  $storage
    ->resetCache();
  $nodes = array_values($storage
    ->loadMultiple([
    $page1
      ->id(),
    $page2
      ->id(),
    $article1
      ->id(),
  ]));
  $this
    ->assertEquals($random_title, $nodes[0]
    ->getTitle());
  $this
    ->assertEquals($random_title, $nodes[1]
    ->getTitle());
  $this
    ->assertNotEquals($random_title, $nodes[2]
    ->getTitle());

  // Visiting the path directly when we have no selected entities should
  // show us a warning.
  $this
    ->drupalGet('/admin/content/bulk-edit');
  $this
    ->assertSession()
    ->pageTextContains('You must use a valid bulk operations form to first select the entities to change');
}