1 | <?php |
||
26 | class SsiCacheTest extends TestCase |
||
27 | { |
||
28 | private $router; |
||
29 | private $controllerResolver; |
||
30 | private $argumentResolver; |
||
31 | private $cache; |
||
32 | |||
33 | protected function setUp() |
||
49 | |||
50 | public function testInitCache() |
||
51 | { |
||
52 | $this->router->expects($this->any()) |
||
53 | ->method('generate') |
||
54 | ->will($this->returnValue('/cache/esi/TOKEN?controller=asdsad')); |
||
55 | |||
56 | $this->assertTrue($this->cache->flush([])); |
||
57 | $this->assertTrue($this->cache->flushAll()); |
||
58 | |||
59 | $cacheElement = $this->cache->set(['id' => 7], 'data'); |
||
60 | |||
61 | $this->assertInstanceOf(CacheElement::class, $cacheElement); |
||
62 | |||
63 | $this->assertTrue($this->cache->has(['id' => 7])); |
||
64 | |||
65 | $cacheElement = $this->cache->get([ |
||
66 | 'id' => 7, |
||
67 | 'controller' => 'foo.service::runAction', |
||
68 | 'parameters' => [], |
||
69 | ]); |
||
70 | |||
71 | $this->assertInstanceOf(CacheElement::class, $cacheElement); |
||
72 | |||
73 | $this->assertEquals( |
||
74 | '<!--# include virtual="/cache/esi/TOKEN?controller=asdsad" -->', |
||
75 | $cacheElement->getData()->getContent() |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException |
||
81 | */ |
||
82 | public function testActionInvalidToken(): void |
||
83 | { |
||
84 | $this->router->expects($this->any()) |
||
85 | ->method('generate') |
||
86 | ->will($this->returnValue( |
||
87 | 'http://sonata-project.orf/cache/esi/TOKEN?controller=asdsad' |
||
88 | )); |
||
89 | |||
90 | $request = Request::create('cache/esi/TOKEN?controller=asdsad', 'get', [ |
||
91 | 'token' => 'wrong', |
||
92 | ]); |
||
93 | |||
94 | $this->cache->cacheAction($request); |
||
95 | } |
||
96 | |||
97 | public function testValidToken(): void |
||
98 | { |
||
99 | $this->controllerResolver->expects($this->any()) |
||
100 | ->method('getController') |
||
101 | ->will($this->returnValue(function () { |
||
102 | return new Response(); |
||
103 | })); |
||
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 | /** |
||
125 | * @group legacy |
||
126 | * @expectedDeprecation Not providing a "Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface" instance to "Sonata\CacheBundle\Adapter\SsiCache::__construct" is deprecated since 3.x and will not be possible in 4.0 |
||
127 | */ |
||
128 | public function testConstructorLegacy() |
||
138 | } |
||
139 |