3 namespace Drupal\Tests\image\Unit\PageCache;
5 use Drupal\Core\PageCache\ResponsePolicyInterface;
6 use Drupal\image\PageCache\DenyPrivateImageStyleDownload;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\HttpFoundation\Response;
12 * @coversDefaultClass \Drupal\image\PageCache\DenyPrivateImageStyleDownload
15 class DenyPrivateImageStyleDownloadTest extends UnitTestCase {
18 * The response policy under test.
20 * @var \Drupal\image\PageCache\DenyPrivateImageStyleDownload
27 * @var \Symfony\Component\HttpFoundation\Request
34 * @var \Symfony\Component\HttpFoundation\Response
39 * The current route match.
41 * @var \Drupal\Core\Routing\RouteMatch|\PHPUnit_Framework_MockObject_MockObject
43 protected $routeMatch;
45 protected function setUp() {
46 $this->routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
47 $this->policy = new DenyPrivateImageStyleDownload($this->routeMatch);
48 $this->response = new Response();
49 $this->request = new Request();
53 * Asserts that caching is denied on the private image style download route.
55 * @dataProvider providerPrivateImageStyleDownloadPolicy
58 public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) {
59 $this->routeMatch->expects($this->once())
60 ->method('getRouteName')
61 ->will($this->returnValue($route_name));
63 $actual_result = $this->policy->check($this->response, $this->request);
64 $this->assertSame($expected_result, $actual_result);
68 * Provides data and expected results for the test method.
71 * Data and expected results.
73 public function providerPrivateImageStyleDownloadPolicy() {
75 [ResponsePolicyInterface::DENY, 'image.style_private'],
76 [NULL, 'some.other.route'],
80 [NULL, new \StdClass()],