Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify block cache #1853

Merged
merged 1 commit into from Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ApiBundle/Resources/config/transformer.yml
Expand Up @@ -90,6 +90,7 @@ services:
arguments:
- '%open_orchestra_api.facade.block.class%'
- '@open_orchestra_backoffice.display_block_manager'
- '@open_orchestra_display.display_block_manager'
- '@open_orchestra_backoffice.display_icon_manager'
- '%open_orchestra_model.document.block.class%'
- '@open_orchestra_backoffice.block_parameter_manager'
Expand Down
22 changes: 13 additions & 9 deletions ApiBundle/Tests/Transformer/BlockTransformerTest.php
Expand Up @@ -60,6 +60,7 @@ public function setUp()
$this->blockTransformer = new BlockTransformer(
$this->facadeClass,
$this->displayBlockManager,
$this->displayBlockManager,
$this->displayIconManager,
$this->blockClass,
$this->blockParameterManager,
Expand Down Expand Up @@ -209,6 +210,7 @@ public function testReverseTransformToArray($nodeId, $result, $facadeNodeId, $bl
$this->blockFacade->nodeId = $facadeNodeId;
$this->blockFacade->blockId = $blockId;

Phake::when($this->displayBlockManager)->isPublic(Phake::anyParameters())->thenReturn(false);
$nodeTransverse = Phake::mock('OpenOrchestra\ModelInterface\Model\NodeInterface');
Phake::when($this->node)->getNodeId()->thenReturn($nodeId);
$block = Phake::mock('OpenOrchestra\ModelInterface\Model\BlockInterface');
Expand All @@ -229,10 +231,10 @@ public function testReverseTransformToArray($nodeId, $result, $facadeNodeId, $bl
public function blockReverseTransformProvider()
{
return array(
array('fixture_full', array('blockParameter' => array(), 'blockId' => 5, 'nodeId' => 0), 'fixture_full', 5),
array('fixture_full', array('blockParameter' => array(), 'blockId' => 0, 'nodeId' => 0), 'fixture_full', 0),
array('fixture_about_us', array('blockParameter' => array(), 'blockId' => 3, 'nodeId' => 'fixture_full'), 'fixture_full', 3),
array('fixture_about_us', array('blockParameter' => array('newsId'), 'blockId' => 3, 'nodeId' => 'fixture_full'), 'fixture_full', 3, array('newsId')),
array('fixture_full', array('blockParameter' => array(), 'blockId' => 5, 'nodeId' => 0, 'blockPrivate' => true), 'fixture_full', 5),
array('fixture_full', array('blockParameter' => array(), 'blockId' => 0, 'nodeId' => 0, 'blockPrivate' => true), 'fixture_full', 0),
array('fixture_about_us', array('blockParameter' => array(), 'blockId' => 3, 'nodeId' => 'fixture_full', 'blockPrivate' => true), 'fixture_full', 3),
array('fixture_about_us', array('blockParameter' => array('newsId'), 'blockId' => 3, 'nodeId' => 'fixture_full', 'blockPrivate' => true), 'fixture_full', 3, array('newsId')),
);
}

Expand All @@ -249,6 +251,7 @@ public function testReverseTransformToArrayComponent($result, $component, $block
$this->blockFacade->component = $component;
Phake::when($this->node)->getBlockIndex(Phake::anyParameters())->thenReturn($blockId);
Phake::when($this->blockParameterManager)->getBlockParameter(Phake::anyParameters())->thenReturn($blockParameter);
Phake::when($this->displayBlockManager)->isPublic(Phake::anyParameters())->thenReturn(false);

$expected = $this->blockTransformer->reverseTransformToArray($this->blockFacade, $this->node);

Expand All @@ -264,9 +267,9 @@ public function testReverseTransformToArrayComponent($result, $component, $block
public function blockReverseTransformProvider2()
{
return array(
array(array('blockParameter' => array(), 'blockId' => 2, 'nodeId' => 0), 'sample', 2),
array(array('blockParameter' => array(), 'blockId' => 3, 'nodeId' => 0), 'menu', 3),
array(array('blockParameter' => array('newsId'), 'blockId' => 3, 'nodeId' => 0), 'news', 3, array('newsId')),
array(array('blockParameter' => array(), 'blockId' => 2, 'nodeId' => 0, 'blockPrivate' => true), 'sample', 2),
array(array('blockParameter' => array(), 'blockId' => 3, 'nodeId' => 0, 'blockPrivate' => true), 'menu', 3),
array(array('blockParameter' => array('newsId'), 'blockId' => 3, 'nodeId' => 0, 'blockPrivate' => true), 'news', 3, array('newsId')),
);
}

Expand Down Expand Up @@ -310,10 +313,11 @@ public function testReverseTransformWithComponent($component, $blockIndex, array
$this->blockFacade->component = $component;
Phake::when($this->node)->getBlockIndex(Phake::anyParameters())->thenReturn($blockIndex);
Phake::when($this->blockParameterManager)->getBlockParameter(Phake::anyParameters())->thenReturn($blockParameter);
Phake::when($this->displayBlockManager)->isPublic(Phake::anyParameters())->thenReturn(true);

$result = $this->blockTransformer->reverseTransformToArray($this->blockFacade, $this->node);

$this->assertSame(array('blockParameter' => $blockParameter, 'blockId' => $blockIndex, 'nodeId' => 0), $result);
$this->assertSame(array('blockParameter' => $blockParameter, 'blockId' => $blockIndex, 'nodeId' => 0, 'blockPrivate' => false), $result);
Phake::verify($this->node)->addBlock(Phake::anyParameters());
Phake::verify($this->node)->getBlockIndex(Phake::anyParameters());
Phake::verify($this->generateFormManager)->getDefaultConfiguration(Phake::anyParameters());
Expand All @@ -340,7 +344,7 @@ public function provideComponentAndBlockIndex()
*/
public function testExceptionTransform()
{
$this->setExpectedException('OpenOrchestra\BaseApi\Exceptions\TransformerParameterTypeException');
$this->expectException('OpenOrchestra\BaseApi\Exceptions\TransformerParameterTypeException');
$this->blockTransformer->transform(Phake::mock('stdClass'));
}
}
6 changes: 6 additions & 0 deletions ApiBundle/Transformer/BlockTransformer.php
Expand Up @@ -27,6 +27,8 @@ class BlockTransformer extends AbstractTransformer
protected $blockParameterManager;
protected $generateFormManager;
protected $displayBlockManager;
protected $displayBlockFrontManager;
protected $displayIconManager;
protected $currentSiteManager;
protected $eventDispatcher;
protected $nodeRepository;
Expand All @@ -37,6 +39,7 @@ class BlockTransformer extends AbstractTransformer
/**
* @param string $facadeClass
* @param DisplayBlockManager $displayBlockManager
* @param DisplayBlockManager $displayBlockFrontManager
* @param DisplayManager $displayManager
* @param string $blockClass
* @param BlockParameterManager $blockParameterManager
Expand All @@ -49,6 +52,7 @@ class BlockTransformer extends AbstractTransformer
public function __construct(
$facadeClass,
DisplayBlockManager $displayBlockManager,
DisplayBlockManager $displayBlockFrontManager,
DisplayManager $displayManager,
$blockClass,
BlockParameterManager $blockParameterManager,
Expand All @@ -63,6 +67,7 @@ public function __construct(
$this->blockParameterManager = $blockParameterManager;
$this->generateFormManager = $generateFormManager;
$this->displayBlockManager = $displayBlockManager;
$this->displayBlockFrontManager = $displayBlockFrontManager;
$this->displayIconManager = $displayManager;
$this->nodeRepository = $nodeRepository;
$this->blockClass = $blockClass;
Expand Down Expand Up @@ -186,6 +191,7 @@ public function reverseTransformToArray(FacadeInterface $facade, NodeInterface $

if ($blockElement) {
$block['blockParameter'] = $this->blockParameterManager->getBlockParameter($blockElement);
$block['blockPrivate'] = !$this->displayBlockFrontManager->isPublic($blockElement);
}

return $block;
Expand Down