You are here

public function StaticRedirectTest::testRedirect in Tome 8

@covers \Drupal\tome_static\StaticGenerator::requestPath @covers \Drupal\tome_static\EventSubscriber\RedirectPathSubscriber::collectPaths @covers \Drupal\tome_static\EventSubscriber\RedirectPathSubscriber::replacePathPlaceholder

File

modules/tome_static/tests/src/Kernel/StaticRedirectTest.php, line 43

Class

StaticRedirectTest
Tests that static redirect generation works.

Namespace

Drupal\Tests\tome_static\Kernel

Code

public function testRedirect() {

  /** @var \Drupal\tome_static\StaticGenerator $static */
  $static = \Drupal::service('tome_static.generator');
  $base_dir = Settings::get('tome_static_directory');
  $redirect = Redirect::create();
  $redirect
    ->setSource('test');
  $redirect
    ->setRedirect('node');
  $redirect
    ->setStatusCode(301);
  $redirect
    ->save();
  $invoke_paths = $static
    ->requestPath('_redirect:' . $redirect
    ->id());
  $this
    ->assertFileExists("{$base_dir}/test/index.html");
  $this
    ->assertStringContainsString('<meta http-equiv="refresh"', file_get_contents("{$base_dir}/test/index.html"));
  $this
    ->assertContains('/node', $invoke_paths);
}