You are here

public function SubPathautoKernelTest::testProcessOutbound in Sub-pathauto (Sub-path URL Aliases) 8

@covers ::processOutbound

File

tests/src/Kernel/SubPathautoKernelTest.php, line 105

Class

SubPathautoKernelTest
@coversDefaultClass \Drupal\subpathauto\PathProcessor @group subpathauto

Namespace

Drupal\Tests\subpathauto\Kernel

Code

public function testProcessOutbound() {

  // Alias should not be converted for invalid paths.
  $processed = $this->pathProcessor
    ->processOutbound('/kittens/are-fake');
  $this
    ->assertEquals('/kittens/are-fake', $processed);

  // Alias should be converted even when the user doesn't have permissions to
  // view the page.
  $processed = $this->pathProcessor
    ->processOutbound('/node/1/edit');
  $this
    ->assertEquals('/kittens/edit', $processed);

  // Alias should be converted also for user that has access to view the page.
  $admin_user = $this
    ->createUser();
  \Drupal::currentUser()
    ->setAccount($admin_user);
  $processed = $this->pathProcessor
    ->processOutbound('/node/1/edit');
  $this
    ->assertEquals('/kittens/edit', $processed);

  // Check that alias is converted for absolute paths. The Redirect module,
  // for instance, requests an absolute path when it checks if a redirection
  // is needed.
  $options = [
    'absolute' => TRUE,
  ];
  $processed = $this->pathProcessor
    ->processOutbound('/node/1/edit', $options);
  $this
    ->assertEquals('/kittens/edit', $processed);
}