3 namespace Drupal\Tests\toolbar\Unit\PageCache;
5 use Drupal\toolbar\PageCache\AllowToolbarPath;
6 use Drupal\Core\PageCache\RequestPolicyInterface;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\HttpFoundation\Request;
11 * @coversDefaultClass \Drupal\toolbar\PageCache\AllowToolbarPath
14 class AllowToolbarPathTest extends UnitTestCase {
17 * The toolbar path policy under test.
19 * @var \Drupal\toolbar\PageCache\AllowToolbarPath
23 protected function setUp() {
24 $this->policy = new AllowToolbarPath();
28 * Asserts that caching is allowed if the request goes to toolbar subtree.
30 * @dataProvider providerTestAllowToolbarPath
33 public function testAllowToolbarPath($expected_result, $path) {
34 $request = Request::create($path);
35 $result = $this->policy->check($request);
36 $this->assertSame($expected_result, $result);
40 * Provides data and expected results for the test method.
43 * Data and expected results.
45 public function providerTestAllowToolbarPath() {
48 [NULL, '/other-path?q=/toolbar/subtrees/'],
49 [NULL, '/toolbar/subtrees/'],
50 [NULL, '/toolbar/subtrees/some-hash/langcode/additional-stuff'],
51 [RequestPolicyInterface::ALLOW, '/de/toolbar/subtrees/abcd'],
52 [RequestPolicyInterface::ALLOW, '/en-us/toolbar/subtrees/xyz'],
53 [RequestPolicyInterface::ALLOW, '/en-us/toolbar/subtrees/xyz/de'],
54 [RequestPolicyInterface::ALLOW, '/a/b/c/toolbar/subtrees/xyz/de'],
55 [RequestPolicyInterface::ALLOW, '/toolbar/subtrees/some-hash'],
56 [RequestPolicyInterface::ALLOW, '/toolbar/subtrees/some-hash/en'],