diff --git a/core/lib/Drupal/Core/PageCache/ChainRequestPolicy.php b/core/lib/Drupal/Core/PageCache/ChainRequestPolicy.php index ea3b818..66e4c5f 100644 --- a/core/lib/Drupal/Core/PageCache/ChainRequestPolicy.php +++ b/core/lib/Drupal/Core/PageCache/ChainRequestPolicy.php @@ -36,15 +36,15 @@ class ChainRequestPolicy implements ChainRequestPolicyInterface { * {@inheritdoc} */ public function check(Request $request) { - $overall_result = NULL; + $final_result = NULL; foreach ($this->rules as $rule) { $result = $rule->check($request); if ($result === static::ALLOW) { - $overall_result = $result; + $final_result = $result; } elseif ($result === static::DENY) { - $overall_result = $result; + $final_result = $result; break; } elseif (isset($result)) { @@ -52,7 +52,7 @@ public function check(Request $request) { } } - return $overall_result; + return $final_result; } /** diff --git a/core/modules/image/src/Tests/PageCache/DenyPrivateImageStyleDownloadTest.php b/core/modules/image/src/Tests/PageCache/DenyPrivateImageStyleDownloadTest.php deleted file mode 100644 index 5bb4b83..0000000 --- a/core/modules/image/src/Tests/PageCache/DenyPrivateImageStyleDownloadTest.php +++ /dev/null @@ -1,90 +0,0 @@ -routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); - $this->policy = new DenyPrivateImageStyleDownload($this->routeMatch); - $this->response = new Response(); - $this->request = new Request(); - } - - /** - * Asserts that chaching is denied on the private image style download route. - * - * @dataProvider providerPrivateImageStyleDownloadPolicy - * @covers ::check - */ - public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) { - $this->routeMatch->expects($this->once()) - ->method('getRouteName') - ->will($this->returnValue($route_name)); - - $actual_result = $this->policy->check($this->response, $this->request); - $this->assertSame($expected_result, $actual_result); - } - - /** - * Provides data and expected results for the test method. - * - * @return array - * Data and expected results. - */ - public function providerPrivateImageStyleDownloadPolicy() { - return [ - [ResponsePolicyInterface::DENY, 'image.style_private'], - [NULL, 'some.other.route'], - [NULL, NULL], - [NULL, FALSE], - [NULL, TRUE], - [NULL, new \StdClass()], - [NULL, [1, 2, 3]], - ]; - } - -} diff --git a/core/modules/image/tests/src/Unit/PageCache/DenyPrivateImageStyleDownloadTest.php b/core/modules/image/tests/src/Unit/PageCache/DenyPrivateImageStyleDownloadTest.php new file mode 100644 index 0000000..bdb6f72 --- /dev/null +++ b/core/modules/image/tests/src/Unit/PageCache/DenyPrivateImageStyleDownloadTest.php @@ -0,0 +1,90 @@ +routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); + $this->policy = new DenyPrivateImageStyleDownload($this->routeMatch); + $this->response = new Response(); + $this->request = new Request(); + } + + /** + * Asserts that chaching is denied on the private image style download route. + * + * @dataProvider providerPrivateImageStyleDownloadPolicy + * @covers ::check + */ + public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) { + $this->routeMatch->expects($this->once()) + ->method('getRouteName') + ->will($this->returnValue($route_name)); + + $actual_result = $this->policy->check($this->response, $this->request); + $this->assertSame($expected_result, $actual_result); + } + + /** + * Provides data and expected results for the test method. + * + * @return array + * Data and expected results. + */ + public function providerPrivateImageStyleDownloadPolicy() { + return [ + [ResponsePolicyInterface::DENY, 'image.style_private'], + [NULL, 'some.other.route'], + [NULL, NULL], + [NULL, FALSE], + [NULL, TRUE], + [NULL, new \StdClass()], + [NULL, [1, 2, 3]], + ]; + } + +} diff --git a/core/modules/node/src/Tests/PageCache/DenyNodePreviewTest.php b/core/modules/node/src/Tests/PageCache/DenyNodePreviewTest.php deleted file mode 100644 index c7aaf01..0000000 --- a/core/modules/node/src/Tests/PageCache/DenyNodePreviewTest.php +++ /dev/null @@ -1,90 +0,0 @@ -routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); - $this->policy = new DenyNodePreview($this->routeMatch); - $this->response = new Response(); - $this->request = new Request(); - } - - /** - * Asserts that chaching is denied on the node preview route. - * - * @dataProvider providerPrivateImageStyleDownloadPolicy - * @covers ::check - */ - public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) { - $this->routeMatch->expects($this->once()) - ->method('getRouteName') - ->will($this->returnValue($route_name)); - - $actual_result = $this->policy->check($this->response, $this->request); - $this->assertSame($expected_result, $actual_result); - } - - /** - * Provides data and expected results for the test method. - * - * @return array - * Data and expected results. - */ - public function providerPrivateImageStyleDownloadPolicy() { - return [ - [ResponsePolicyInterface::DENY, 'entity.node.preview'], - [NULL, 'some.other.route'], - [NULL, NULL], - [NULL, FALSE], - [NULL, TRUE], - [NULL, new \StdClass()], - [NULL, [1, 2, 3]], - ]; - } - -} diff --git a/core/modules/node/tests/src/Unit/PageCache/DenyNodePreviewTest.php b/core/modules/node/tests/src/Unit/PageCache/DenyNodePreviewTest.php new file mode 100644 index 0000000..c5df27e --- /dev/null +++ b/core/modules/node/tests/src/Unit/PageCache/DenyNodePreviewTest.php @@ -0,0 +1,90 @@ +routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); + $this->policy = new DenyNodePreview($this->routeMatch); + $this->response = new Response(); + $this->request = new Request(); + } + + /** + * Asserts that chaching is denied on the node preview route. + * + * @dataProvider providerPrivateImageStyleDownloadPolicy + * @covers ::check + */ + public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) { + $this->routeMatch->expects($this->once()) + ->method('getRouteName') + ->will($this->returnValue($route_name)); + + $actual_result = $this->policy->check($this->response, $this->request); + $this->assertSame($expected_result, $actual_result); + } + + /** + * Provides data and expected results for the test method. + * + * @return array + * Data and expected results. + */ + public function providerPrivateImageStyleDownloadPolicy() { + return [ + [ResponsePolicyInterface::DENY, 'entity.node.preview'], + [NULL, 'some.other.route'], + [NULL, NULL], + [NULL, FALSE], + [NULL, TRUE], + [NULL, new \StdClass()], + [NULL, [1, 2, 3]], + ]; + } + +} diff --git a/core/modules/toolbar/src/Tests/PageCache/AllowToolbarPathTest.php b/core/modules/toolbar/src/Tests/PageCache/AllowToolbarPathTest.php deleted file mode 100644 index da2533f..0000000 --- a/core/modules/toolbar/src/Tests/PageCache/AllowToolbarPathTest.php +++ /dev/null @@ -1,60 +0,0 @@ -policy = new AllowToolbarPath(); - } - - /** - * Asserts that caching is allowed if the request goes to toolbar subtree. - * - * @dataProvider providerTestAllowToolbarPath - * @covers ::check - */ - public function testAllowToolbarPath($expected_result, $path) { - $request = Request::create($path); - $result = $this->policy->check($request); - $this->assertSame($expected_result, $result); - } - - /** - * Provides data and expected results for the test method. - * - * @return array - * Data and expected results. - */ - public function providerTestAllowToolbarPath() { - return [ - [NULL, '/'], - [NULL, '/other-path?q=/toolbar/subtrees/'], - [RequestPolicyInterface::ALLOW, '/de/toolbar/subtrees/abcd'], - [RequestPolicyInterface::ALLOW, '/en-us/toolbar/subtrees/'], - [RequestPolicyInterface::ALLOW, '/toolbar/subtrees/some-hash'], - ]; - } - -} diff --git a/core/modules/toolbar/tests/src/Unit/PageCache/AllowToolbarPathTest.php b/core/modules/toolbar/tests/src/Unit/PageCache/AllowToolbarPathTest.php new file mode 100644 index 0000000..cbd7c45 --- /dev/null +++ b/core/modules/toolbar/tests/src/Unit/PageCache/AllowToolbarPathTest.php @@ -0,0 +1,60 @@ +policy = new AllowToolbarPath(); + } + + /** + * Asserts that caching is allowed if the request goes to toolbar subtree. + * + * @dataProvider providerTestAllowToolbarPath + * @covers ::check + */ + public function testAllowToolbarPath($expected_result, $path) { + $request = Request::create($path); + $result = $this->policy->check($request); + $this->assertSame($expected_result, $result); + } + + /** + * Provides data and expected results for the test method. + * + * @return array + * Data and expected results. + */ + public function providerTestAllowToolbarPath() { + return [ + [NULL, '/'], + [NULL, '/other-path?q=/toolbar/subtrees/'], + [RequestPolicyInterface::ALLOW, '/de/toolbar/subtrees/abcd'], + [RequestPolicyInterface::ALLOW, '/en-us/toolbar/subtrees/'], + [RequestPolicyInterface::ALLOW, '/toolbar/subtrees/some-hash'], + ]; + } + +}