01ca00457458d152c9967e7a0d9da41b4084123a
[yaffs-website] / PageCache / AllowToolbarPathTest.php
1 <?php
2
3 namespace Drupal\Tests\toolbar\Unit\PageCache;
4
5 use Drupal\toolbar\PageCache\AllowToolbarPath;
6 use Drupal\Core\PageCache\RequestPolicyInterface;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * @coversDefaultClass \Drupal\toolbar\PageCache\AllowToolbarPath
12  * @group toolbar
13  */
14 class AllowToolbarPathTest extends UnitTestCase {
15
16   /**
17    * The toolbar path policy under test.
18    *
19    * @var \Drupal\toolbar\PageCache\AllowToolbarPath
20    */
21   protected $policy;
22
23   protected function setUp() {
24     $this->policy = new AllowToolbarPath();
25   }
26
27   /**
28    * Asserts that caching is allowed if the request goes to toolbar subtree.
29    *
30    * @dataProvider providerTestAllowToolbarPath
31    * @covers ::check
32    */
33   public function testAllowToolbarPath($expected_result, $path) {
34     $request = Request::create($path);
35     $result = $this->policy->check($request);
36     $this->assertSame($expected_result, $result);
37   }
38
39   /**
40    * Provides data and expected results for the test method.
41    *
42    * @return array
43    *   Data and expected results.
44    */
45   public function providerTestAllowToolbarPath() {
46     return [
47       [NULL, '/'],
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'],
57     ];
58   }
59
60 }