You are here

public function SubPathautoTest::testInboundPathProcessorMaxDepth in Sub-pathauto (Sub-path URL Aliases) 8

@covers ::processInbound

File

tests/src/Unit/SubPathautoTest.php, line 144

Class

SubPathautoTest
@coversDefaultClass \Drupal\subpathauto\PathProcessor @group subpathauto

Namespace

Drupal\Tests\subpathauto\Unit

Code

public function testInboundPathProcessorMaxDepth() {
  $this->pathValidator
    ->expects($this
    ->any())
    ->method('getUrlIfValidWithoutAccessCheck')
    ->willReturn(new Url('any_route'));
  $this->subPathautoSettings
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->willReturn(3);
  $this->aliasProcessor
    ->expects($this
    ->any())
    ->method('processInbound')
    ->willReturnCallback([
    $this,
    'pathAliasCallback',
  ]);

  // Subpath shouldn't be processed since the iterations has been limited.
  $processed = $this->pathProcessor
    ->processInbound('/content/first-node/first/second/third/fourth', Request::create('/content/first-node/first/second/third/fourth'));
  $this
    ->assertEquals('/content/first-node/first/second/third/fourth', $processed);

  // Subpath should be processed when the max depth doesn't exceed.
  $processed = $this->pathProcessor
    ->processInbound('/content/first-node/first/second/third', Request::create('/content/first-node/first/second/third'));
  $this
    ->assertEquals('/node/1/first/second/third', $processed);
}