public function testExecutionOfEnabledBlock()
 {
     $actionBlock = new ActionBlock();
     $actionBlock->setEnabled(true);
     $actionBlock->setActionName('CmfBlockBundle:Test:test');
     $content = "Rendered Action Block.";
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->kernel->expects($this->once())->method('render')->will($this->returnValue($content));
     $actionBlockService = new ActionBlockService('test-service', $this->templating, $this->kernel);
     $actionBlockService->setRequest($request);
     $response = $actionBlockService->execute(new BlockContext($actionBlock));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals($content, $response->getContent());
 }
 public function testInitCache()
 {
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $router->expects($this->any())->method('generate')->will($this->returnValue('http://cmf.symfony.com/symfony-cmf/block/cache/varnish/XXX/%2Fcms%2Fcontent%2Fhome%2FadditionalInfoBlock?updated_at=as'));
     $blockRenderer = $this->getMock('Sonata\\BlockBundle\\Block\\BlockRendererInterface');
     $blockLoader = $this->getMock('Sonata\\BlockBundle\\Block\\BlockLoaderInterface');
     $blockContextManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockContextManagerInterface');
     $content = '<esi:include src="http://cmf.symfony.com/symfony-cmf/block/cache/varnish/XXX/%2Fcms%2Fcontent%2Fhome%2FadditionalInfoBlock?updated_at=as';
     $this->fragmentHandler->expects($this->once())->method('render')->will($this->returnValue($content));
     $cache = new BlockVarnishCache('My Token', $router, $blockRenderer, $blockLoader, $blockContextManager, $this->fragmentHandler, array(), 'ban');
     $this->assertTrue($cache->flush(array()));
     $this->assertTrue($cache->flushAll());
     $keys = array('block_id' => '/cms/content/home/additionalInfoBlock', 'updated_at' => 'as');
     $cacheElement = $cache->set($keys, 'data');
     $this->assertInstanceOf('Sonata\\Cache\\CacheElement', $cacheElement);
     $this->assertTrue($cache->has(array('id' => 7)));
     $cacheElement = $cache->get($keys);
     $this->assertInstanceOf('Sonata\\Cache\\CacheElement', $cacheElement);
     $this->assertEquals($content, $cacheElement->getData()->getContent());
 }
Esempio n. 3
0
 public function testInvokeAction()
 {
     $controllerRefCount = 0;
     $controllerList = array('C1', 'B1', 'A5', 'D2');
     $action = 'awesomeAction';
     $params = array('goo' => 'boo');
     $request = new Request($query = array('foo' => 'bar', 'baz' => 'shoo'), $requestParams = array('a' => 'kaboom', 'd' => 'achoo'));
     $memberRequest = new Request(array(), array(), $attributes = array('app' => 'foobarbaz'));
     $this->sut->setRequest($memberRequest);
     $mergedParams = array_merge(array(), $params, $attributes);
     $mergedQuery = array_merge(array(), $query, $requestParams);
     $this->controllerManager->expects($this->any())->method('getControllers')->with($action)->will($this->returnValue($controllerList));
     $controllersAdded = array();
     $this->fragmentHandler->expects($this->exactly(count($controllerList)))->method('render')->with($this->logicalAnd($this->isInstanceOf('Symfony\\Component\\HttpKernel\\Controller\\ControllerReference'), $this->callback(function (ControllerReference $cr) use(&$controllersAdded, $controllerList, $mergedParams, $mergedQuery) {
         $controllersAdded[] = $cr->controller;
         // XXX PHPUnit bug prevents us from doing an order-based test here
         // TODO upgrade PHPUnit
         return in_array($cr->controller, $controllerList) && count(array_diff_assoc($mergedParams, $cr->attributes)) < 1 && count(array_diff_assoc($mergedQuery, $cr->query)) < 1;
     })));
     $this->sut->invokeAction($request, $action, $params);
     $this->assertEmpty(array_diff($controllerList, array_unique($controllersAdded)));
 }