Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into slideshow

  • Loading branch information...
commit 0b2ecc37dba495982ceb446e277c82595ee0fc3c 2 parents 37ab49e + 2997c17
Reto Ryter authored
View
5 .travis.yml
@@ -2,11 +2,10 @@ language: php
env:
- SYMFONY_VERSION=2.1.*
- - SYMFONY_VERSION=dev-master
+ - SYMFONY_VERSION=2.2.*
before_script:
- - composer require symfony/framework-bundle:${SYMFONY_VERSION}
- - composer install --dev
+ - composer require symfony/framework-bundle:${SYMFONY_VERSION} --dev
script: phpunit --coverage-text
View
30 Block/ActionBlockService.php
@@ -3,6 +3,7 @@
namespace Symfony\Cmf\Bundle\BlockBundle\Block;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\HttpKernel;
use Sonata\BlockBundle\Block\BlockServiceInterface;
@@ -10,21 +11,21 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\BaseBlockService;
+use Symfony\Component\HttpKernel\Kernel;
class ActionBlockService extends BaseBlockService implements BlockServiceInterface
{
-
- protected $kernel;
+ protected $renderer;
/**
* @param string $name
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
- * @param \Symfony\Bundle\FrameworkBundle\HttpKernel $kernel
+ * @param \Symfony\Component\HttpKernel\Fragment\FragmentHandler|\Symfony\Bundle\FrameworkBundle\HttpKernel $renderer
*/
- public function __construct($name, EngineInterface $templating, HttpKernel $kernel)
+ public function __construct($name, EngineInterface $templating, $renderer)
{
parent::__construct($name, $templating);
- $this->kernel = $kernel;
+ $this->renderer = $renderer;
}
/**
@@ -63,9 +64,26 @@ public function execute(BlockInterface $block, Response $response = null)
}
if ($block->getEnabled()) {
- $response = new Response($this->kernel->render($block->getActionName(), array('attributes' => array('block' => $block))));
+ $response = $this->render($block->getActionName(), array('block' => $block));
}
return $response;
}
+
+ /**
+ * @param $controller
+ * @param $attributes
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ private function render($controller, $attributes)
+ {
+ if (!class_exists('Symfony\Component\HttpKernel\Fragment\FragmentHandler')) {
+ // TODO: Symfony 2.1 compatibility
+ $response = $this->renderer->render($controller, array('attributes' => $attributes));
+ } else {
+ $response = $this->renderer->render(new ControllerReference($controller, $attributes));
+ }
+
+ return new Response($response);
+ }
}
View
7 DependencyInjection/SymfonyCmfBlockExtension.php
@@ -2,6 +2,7 @@
namespace Symfony\Cmf\Bundle\BlockBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
@@ -74,6 +75,12 @@ public function load(array $configs, ContainerBuilder $container)
$blockLoader = $container->getDefinition('symfony_cmf.block.service');
$blockLoader->replaceArgument(1, $config['document_manager_name']);
+ // TODO: Symfony 2.1 compatibility
+ if (!class_exists('Symfony\Component\HttpKernel\Fragment\FragmentHandler')) {
+ $blockAction = $container->getDefinition('symfony_cmf.block.action');
+ $blockAction->replaceArgument(2, new Reference('http_kernel'));
+ }
+
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['SymfonyCmfCreateBundle'])) {
$blockLoader = $container->getDefinition('symfony_cmf.block.simple');
View
2  Resources/config/services.xml
@@ -42,7 +42,7 @@
<tag name="sonata.block" />
<argument>symfony_cmf.block.action</argument>
<argument type="service" id="templating" />
- <argument type="service" id="http_kernel" />
+ <argument type="service" id="fragment.handler" />
</service>
<service id="symfony_cmf.block.rss_controller" class="%symfony_cmf_block.rss_controller_class%" >
View
5 Tests/Block/ActionBlockServiceTest.php
@@ -12,6 +12,7 @@ public function testExecutionOfDisabledBlock()
{
$actionBlock = new ActionBlock();
$actionBlock->setEnabled(false);
+ $actionBlock->setActionName('SymfonyCmfBlockBundle:Test:test');
$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
@@ -44,10 +45,6 @@ public function testExecutionOfEnabledBlock()
->getMock();
$kernelMock->expects($this->once())
->method('render')
- ->with(
- $this->equalTo($actionBlock->getActionName()),
- array('attributes' => array('block' => $actionBlock))
- )
->will($this->returnValue($actionResponse->getContent()));
$actionBlockService = new ActionBlockService('test-service', $templatingMock, $kernelMock);
View
32 Tests/Block/ContainerBlockServiceTest.php
@@ -44,15 +44,9 @@ public function testExecutionOfEnabledBlock()
->method('getValues')
->will($this->returnValue(array($simpleBlock1, $simpleBlock2)));
- $containerBlockMock = $this->getMockBuilder('Symfony\Cmf\Bundle\BlockBundle\Document\ContainerBlock')
- ->disableOriginalConstructor()
- ->getMock();
- $containerBlockMock->expects($this->once())
- ->method('getEnabled')
- ->will($this->returnValue(true));
- $containerBlockMock->expects($this->once())
- ->method('getChildren')
- ->will($this->returnValue($childrenCollectionMock));
+ $containerBlock = new ContainerBlock('foo');
+ $containerBlock->setEnabled(true);
+ $containerBlock->setChildren($childrenCollectionMock);
$responseContent1 = 'Rendered Simple Block 1.';
$responseContent2 = 'Rendered Simple Block 2.';
@@ -80,6 +74,7 @@ public function testExecutionOfEnabledBlock()
->method('renderResponse')
->with('SymfonyCmfBlockBundle:Block:block_container.html.twig',
array(
+ 'block' => $containerBlock,
'childBlocks' => array($responseContent1, $responseContent2),
'settings' => array('divisibleBy' => false,'divisibleClass' => '','childClass' => '')
),
@@ -89,7 +84,7 @@ public function testExecutionOfEnabledBlock()
;
$containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock);
- $response = $containerBlockService->execute($containerBlockMock);
+ $response = $containerBlockService->execute($containerBlock);
$this->assertInstanceof('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals(($responseContent1 . $responseContent2), $response->getContent());
}
@@ -103,15 +98,9 @@ public function testExecutionOfBlockWithNoChildren()
->method('getValues')
->will($this->returnValue(array()));
- $containerBlockMock = $this->getMockBuilder('Symfony\Cmf\Bundle\BlockBundle\Document\ContainerBlock')
- ->disableOriginalConstructor()
- ->getMock();
- $containerBlockMock->expects($this->once())
- ->method('getEnabled')
- ->will($this->returnValue(true));
- $containerBlockMock->expects($this->once())
- ->method('getChildren')
- ->will($this->returnValue($childrenCollectionMock));
+ $containerBlock = new ContainerBlock('foo');
+ $containerBlock->setEnabled(true);
+ $containerBlock->setChildren($childrenCollectionMock);
$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
@@ -124,20 +113,19 @@ public function testExecutionOfBlockWithNoChildren()
$templatingMock
->expects($this->once())
->method('renderResponse')
-
->with('SymfonyCmfBlockBundle:Block:block_container.html.twig',
array(
+ 'block' => $containerBlock,
'childBlocks' => array(),
'settings' => array('divisibleBy' => false,'divisibleClass' => '','childClass' => '')
),
$this->isInstanceOf('Symfony\Component\HttpFoundation\Response')
)
-
->will($this->returnValue(new Response('')))
;
$containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock);
- $response = $containerBlockService->execute($containerBlockMock);
+ $response = $containerBlockService->execute($containerBlock);
$this->assertInstanceof('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('', $response->getContent());
}
View
2  composer.json
@@ -17,7 +17,7 @@
"symfony/framework-bundle": ">=2.1,<2.3-dev",
"doctrine/phpcr-bundle" :"1.0.*",
"doctrine/phpcr-odm": "1.0.*",
- "sonata-project/block-bundle": "2.1.1"
+ "sonata-project/block-bundle": ">=2.1,<2.3-dev"
},
"require-dev": {
"sonata-project/cache-bundle": "dev-master"
Please sign in to comment.
Something went wrong with that request. Please try again.