You are here

public function PathautoNodeWebTest::testNodeOperations in Pathauto 8

Test node operations.

File

tests/src/Functional/PathautoNodeWebTest.php, line 152

Class

PathautoNodeWebTest
Tests pathauto node UI integration.

Namespace

Drupal\Tests\pathauto\Functional

Code

public function testNodeOperations() {
  $node1 = $this
    ->drupalCreateNode([
    'title' => 'node1',
  ]);
  $node2 = $this
    ->drupalCreateNode([
    'title' => 'node2',
  ]);

  // Delete all current URL aliases.
  $this
    ->deleteAllAliases();
  $this
    ->drupalGet('admin/content');

  // Check which of the two nodes is first.
  if (strpos($this
    ->getTextContent(), 'node1') < strpos($this
    ->getTextContent(), 'node2')) {
    $index = 0;
  }
  else {
    $index = 1;
  }
  $edit = [
    'action' => 'pathauto_update_alias_node',
    'node_bulk_form[' . $index . ']' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
  $this
    ->assertText('Update URL alias was applied to 1 item.');
  $this
    ->assertEntityAlias($node1, '/content/' . $node1
    ->getTitle());
  $this
    ->assertEntityAlias($node2, '/node/' . $node2
    ->id());
}