You are here

public function RedirectAPITest::testLoopDetectionReset in Redirect 8

Test loop detection reset.

File

tests/src/Kernel/RedirectAPITest.php, line 246

Class

RedirectAPITest
Redirect entity and redirect API test coverage.

Namespace

Drupal\Tests\redirect\Kernel

Code

public function testLoopDetectionReset() {

  // Add a chained redirect that isn't a loop.

  /** @var \Drupal\redirect\Entity\Redirect $source */
  $source = $this->storage
    ->create();
  $source
    ->setSource('source-redirect');
  $source
    ->setRedirect('target');
  $source
    ->save();

  /** @var \Drupal\redirect\Entity\Redirect $target */
  $target = $this->storage
    ->create();
  $target
    ->setSource('target');
  $target
    ->setRedirect('second-target');
  $target
    ->save();

  /** @var \Drupal\redirect\RedirectRepository $repository */
  $repository = \Drupal::service('redirect.repository');
  $found = $repository
    ->findMatchingRedirect('target');
  $this
    ->assertEquals($target
    ->id(), $found
    ->id());
  $found = $repository
    ->findMatchingRedirect('source-redirect');
  $this
    ->assertEquals($target
    ->id(), $found
    ->id());
}