public function testOnKernelResponseGetWithExpression() { $tag = new Tag(array('expression' => '"item-"~id')); $request = new Request(); $request->setMethod('GET'); $request->attributes->set('_tag', array($tag)); $request->attributes->set('id', '123'); $event = $this->getEvent($request); $this->listener->onKernelResponse($event); $this->assertEquals( 'item-123', $event->getResponse()->headers->get($this->cacheManager->getTagsHeader()) ); }
public function testTagResponse() { $ban = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\BanInterface'); $router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface'); $tags1 = array('post-1', 'posts'); $tags2 = array('post-2'); $tags3 = array('different'); $cacheManager = new CacheManager($ban, $router); $response = new Response(); $response->headers->set($cacheManager->getTagsHeader(), ''); $cacheManager->tagResponse($response, $tags1); $this->assertTrue($response->headers->has($cacheManager->getTagsHeader())); $this->assertEquals(implode(',', $tags1), $response->headers->get($cacheManager->getTagsHeader())); $cacheManager->tagResponse($response, $tags2); $this->assertEquals(implode(',', array_merge($tags1, $tags2)), $response->headers->get($cacheManager->getTagsHeader())); $cacheManager->tagResponse($response, $tags3, true); $this->assertEquals(implode(',', $tags3), $response->headers->get($cacheManager->getTagsHeader())); }