1 | <?php |
||
23 | class VarnishCacheTest extends TestCase |
||
24 | { |
||
25 | private $router; |
||
26 | private $controllerResolver; |
||
27 | private $argumentResolver; |
||
28 | private $cache; |
||
29 | |||
30 | protected function setUp() |
||
48 | |||
49 | public function testInitCache() |
||
50 | { |
||
51 | $this->router->expects($this->any()) |
||
52 | ->method('generate') |
||
53 | ->will($this->returnValue( |
||
54 | 'https://sonata-project.org/cache/esi/TOKEN?controller=asdsad' |
||
55 | )); |
||
56 | |||
57 | $this->assertTrue($this->cache->flush([])); |
||
58 | $this->assertTrue($this->cache->flushAll()); |
||
59 | |||
60 | $cacheElement = $this->cache->set(['id' => 7], 'data'); |
||
61 | |||
62 | $this->assertInstanceOf(CacheElement::class, $cacheElement); |
||
63 | |||
64 | $this->assertTrue($this->cache->has(['id' => 7])); |
||
65 | |||
66 | $cacheElement = $this->cache->get([ |
||
67 | 'id' => 7, |
||
68 | 'controller' => 'foo.service::runAction', |
||
69 | 'parameters' => [], |
||
70 | ]); |
||
71 | |||
72 | $this->assertInstanceOf(CacheElement::class, $cacheElement); |
||
73 | |||
74 | $this->assertEquals( |
||
75 | '<esi:include src="https://sonata-project.org/cache/esi/TOKEN?controller=asdsad"/>', |
||
76 | $cacheElement->getData()->getContent() |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException |
||
82 | */ |
||
83 | public function testActionInvalidToken(): void |
||
84 | { |
||
85 | $this->router->expects($this->any()) |
||
86 | ->method('generate') |
||
87 | ->will($this->returnValue( |
||
88 | 'http://sonata-project.orf/cache/esi/TOKEN?controller=asdsad' |
||
89 | )); |
||
90 | |||
91 | $request = Request::create('cache/esi/TOKEN?controller=asdsad', 'get', [ |
||
92 | 'token' => 'wrong', |
||
93 | ]); |
||
94 | |||
95 | $this->cache->cacheAction($request); |
||
96 | } |
||
97 | |||
98 | public function testValidToken(): void |
||
99 | { |
||
100 | $this->controllerResolver->expects($this->any()) |
||
101 | ->method('getController') |
||
102 | ->will($this->returnValue(function () { |
||
103 | return new Response(); |
||
104 | })); |
||
105 | $resolver = interface_exists(ArgumentResolverInterface::class) ? |
||
106 | $this->argumentResolver : |
||
107 | $this->controllerResolver; |
||
108 | |||
109 | $resolver->expects($this->any()) |
||
110 | ->method('getArguments') |
||
111 | ->will($this->returnValue([])); |
||
112 | |||
113 | $request = Request::create('cache/esi/TOKEN', 'get', [ |
||
114 | 'token' => '44befdbd93f304ea693023aa6587729bed76a206ecdacfd9bbd9b43fcf2e1664', |
||
115 | 'parameters' => [ |
||
116 | 'controller' => 'asfsat', |
||
117 | 'parameters' => [], |
||
118 | ], |
||
119 | ]); |
||
120 | |||
121 | $this->cache->cacheAction($request); |
||
122 | } |
||
123 | |||
124 | public function testRunCommand(): void |
||
154 | |||
155 | /** |
||
156 | * @group legacy |
||
157 | * @expectedDeprecation Not providing a "Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface" instance to "Sonata\CacheBundle\Adapter\VarnishCache::__construct" is deprecated since 3.x and will not be possible in 4.0 |
||
158 | */ |
||
159 | public function testConstructorLegacy() |
||
169 | } |
||
170 |