public function testExecutionOfEnabledBlock() { $template = 'CmfBlockBundle:Block:block_container.html.twig'; $simpleBlock1 = new SimpleBlock(); $simpleBlock1->setId(1); $simpleBlock2 = new SimpleBlock(); $simpleBlock2->setId(2); $childrenCollectionMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\ChildrenCollection')->disableOriginalConstructor()->getMock(); $containerBlock = new ContainerBlock('foo'); $containerBlock->setEnabled(true); $containerBlock->setChildren($childrenCollectionMock); $settings = array('divisible_by' => 0, 'divisible_class' => '', 'child_class' => '', 'template' => $template); $blockContext = new BlockContext($containerBlock, $settings); $responseContent1 = 'Rendered Simple Block 1.'; $responseContent2 = 'Rendered Simple Block 2.'; $blockRendererMock = $this->getMockBuilder('Sonata\\BlockBundle\\Block\\BlockRendererInterface')->disableOriginalConstructor()->getMock(); $templatingMock = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface')->disableOriginalConstructor()->getMock(); $templatingMock->expects($this->once())->method('renderResponse')->with($this->equalTo($template), $this->equalTo(array('block' => $containerBlock, 'settings' => $settings)), $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response'))->will($this->returnValue(new Response($responseContent1 . $responseContent2))); $containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock); $response = $containerBlockService->execute($blockContext); $this->assertInstanceof('Symfony\\Component\\HttpFoundation\\Response', $response); $this->assertEquals($responseContent1 . $responseContent2, $response->getContent()); }