Version 1
[yaffs-website] / web / core / modules / image / tests / src / Unit / PageCache / DenyPrivateImageStyleDownloadTest.php
1 <?php
2
3 namespace Drupal\Tests\image\Unit\PageCache;
4
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;
10
11 /**
12  * @coversDefaultClass \Drupal\image\PageCache\DenyPrivateImageStyleDownload
13  * @group image
14  */
15 class DenyPrivateImageStyleDownloadTest extends UnitTestCase {
16
17   /**
18    * The response policy under test.
19    *
20    * @var \Drupal\image\PageCache\DenyPrivateImageStyleDownload
21    */
22   protected $policy;
23
24   /**
25    * A request object.
26    *
27    * @var \Symfony\Component\HttpFoundation\Request
28    */
29   protected $request;
30
31   /**
32    * A response object.
33    *
34    * @var \Symfony\Component\HttpFoundation\Response
35    */
36   protected $response;
37
38   /**
39    * The current route match.
40    *
41    * @var \Drupal\Core\Routing\RouteMatch|\PHPUnit_Framework_MockObject_MockObject
42    */
43   protected $routeMatch;
44
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();
50   }
51
52   /**
53    * Asserts that caching is denied on the private image style download route.
54    *
55    * @dataProvider providerPrivateImageStyleDownloadPolicy
56    * @covers ::check
57    */
58   public function testPrivateImageStyleDownloadPolicy($expected_result, $route_name) {
59     $this->routeMatch->expects($this->once())
60       ->method('getRouteName')
61       ->will($this->returnValue($route_name));
62
63     $actual_result = $this->policy->check($this->response, $this->request);
64     $this->assertSame($expected_result, $actual_result);
65   }
66
67   /**
68    * Provides data and expected results for the test method.
69    *
70    * @return array
71    *   Data and expected results.
72    */
73   public function providerPrivateImageStyleDownloadPolicy() {
74     return [
75       [ResponsePolicyInterface::DENY, 'image.style_private'],
76       [NULL, 'some.other.route'],
77       [NULL, NULL],
78       [NULL, FALSE],
79       [NULL, TRUE],
80       [NULL, new \StdClass()],
81       [NULL, [1, 2, 3]],
82     ];
83   }
84
85 }