You are here

public function RedirectNodeFormTest::testNodeForm in Redirect 8

Test redirect functionality on the node edit form.

File

tests/src/Functional/RedirectNodeFormTest.php, line 71

Class

RedirectNodeFormTest
Test the redirect functionality on node forms.

Namespace

Drupal\Tests\redirect\Functional

Code

public function testNodeForm() {

  // Login as a regular user.
  $this
    ->drupalLogin($this->webUser);

  // Create "Basic page" content with title.
  $settings = [
    'title' => $this
      ->randomMachineName(8),
  ];
  $node = $this
    ->drupalCreateNode($settings);

  // Load the node edit form.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');

  // Make sure the redirect add button is not visible to this regular user.
  $this
    ->assertNoRaw('Add URL redirect');

  // Now edit the same node as an admin user.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');

  // Make sure the redirect add button is visible for the admin user.
  $this
    ->assertRaw('Add URL redirect');

  // Make sure the link works as expected.
  $this
    ->clickLink('Add URL redirect');
  $this
    ->assertUrl('admin/config/search/redirect/add');
  $this
    ->assertFieldsByValue($this
    ->xpath("//input[@id = 'edit-redirect-redirect-0-uri']"), '/node/' . $node
    ->id(), 'To: field correctly pre-filled.');
}