function CurrentPathStackTest::testPathIsKeptPerRequest

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/Path/CurrentPathStackTest.php \Drupal\Tests\Core\Path\CurrentPathStackTest::testPathIsKeptPerRequest()

Tests that a path is kept per request, defaulting to the path info.

File

core/tests/Drupal/Tests/Core/Path/CurrentPathStackTest.php, line 24

Class

CurrentPathStackTest
Tests Drupal\Core\Path\CurrentPathStack.

Namespace

Drupal\Tests\Core\Path

Code

public function testPathIsKeptPerRequest() : void {
  $request_stack = new RequestStack();
  $current = Request::create('/node/1');
  $request_stack->push($current);
  $stack = new CurrentPathStack($request_stack);
  $other = Request::create('/node/2');
  $this->assertSame('/node/1', $stack->getPath());
  $stack->setPath('/system/path', $other);
  $this->assertSame('/system/path', $stack->getPath($other));
  $this->assertSame('/node/1', $stack->getPath($current));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.