public function testRenderEventWithListeners() { $blockService = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceInterface'); $blockService->expects($this->once())->method('getJavascripts')->will($this->returnValue(array())); $blockService->expects($this->once())->method('getStylesheets')->will($this->returnValue(array())); $blockServiceManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceManagerInterface'); $blockServiceManager->expects($this->any())->method('get')->will($this->returnValue($blockService)); $blockRenderer = $this->getMock('Sonata\\BlockBundle\\Block\\BlockRendererInterface'); $blockRenderer->expects($this->once())->method('render')->will($this->returnValue(new Response('<span>test</span>'))); $blockContextManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockContextManagerInterface'); $blockContextManager->expects($this->once())->method('get')->will($this->returnCallback(function (BlockInterface $block) { $context = new BlockContext($block, $block->getSettings()); return $context; })); $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $eventDispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, BlockEvent $event) { $block = new Block(); $block->setId(1); $block->setSettings(array('use_cache' => false)); $block->setType('test'); $event->addBlock($block); return $event; })); $helper = new BlockHelper($blockServiceManager, array(), $blockRenderer, $blockContextManager, $eventDispatcher); $this->assertEquals('<span>test</span>', $helper->renderEvent('my.event')); }
/** * @param BlockEvent $event * * @return BlockInterface */ public function onBlock(BlockEvent $event) { $block = new Block(); $block->setSettings($event->getSettings()); $block->setType($this->getName()); $event->addBlock($block); }
public function testService() { if (!$this->checkBlockBundle()) { $this->markTestSkipped('Sonata BlockBundle is not installed.'); return; } $templating = new FakeTemplating(); $service = new FacebookLikeBoxBlockService('sonata.block.service.facebook.like_box', $templating); $block = new Block(); $block->setType('core.text'); $block->setSettings(array('url' => 'url_setting', 'width' => 'width_setting', 'height' => 'height_setting', 'colorscheme' => 'colorscheme_setting', 'show_faces' => 'show_faces_setting', 'show_header' => 'show_header_setting', 'show_posts' => 'show_posts_setting', 'show_border' => 'show_border_setting')); $optionResolver = new OptionsResolver(); $service->setDefaultSettings($optionResolver); $blockContext = new BlockContext($block, $optionResolver->resolve($block->getSettings())); $formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false); $formMapper->expects($this->exactly(2))->method('add'); $service->buildCreateForm($formMapper, $block); $service->buildEditForm($formMapper, $block); $service->execute($blockContext); $this->assertEquals('url_setting', $templating->parameters['settings']['url']); $this->assertEquals('width_setting', $templating->parameters['settings']['width']); $this->assertEquals('height_setting', $templating->parameters['settings']['height']); $this->assertEquals('colorscheme_setting', $templating->parameters['settings']['colorscheme']); $this->assertEquals('show_faces_setting', $templating->parameters['settings']['show_faces']); $this->assertEquals('show_header_setting', $templating->parameters['settings']['show_header']); $this->assertEquals('show_posts_setting', $templating->parameters['settings']['show_posts']); $this->assertEquals('show_border_setting', $templating->parameters['settings']['show_border']); }
public function testSetting() { $block = new Block(); $block->setSetting('foo', 'bar'); $this->assertEquals('void', $block->getSetting('fake', 'void')); $this->assertNull($block->getSetting('fake')); $this->assertEquals('bar', $block->getSetting('foo')); }
/** * @param BlockEvent */ public function onBlock(BlockEvent $event) { $block = new Block(); $block->setSettings($event->getSettings()); $block->setName('sonata_translation.block.locale_switcher'); $block->setType('sonata_translation.block.locale_switcher'); $event->addBlock($block); }
public function onBlock(BlockEvent $blockEvent) { $block = new Block(); $block->setId(uniqid()); // set a fake id $block->setSettings($blockEvent->getSettings()); $block->setType('admin.form_javascripts.block'); $blockEvent->addBlock($block); }
/** * @param BlockEvent $event */ public function onBlock(BlockEvent $event, $eventName) { $settings = $event->getSettings(); if ($eventName == 'sonata.block.event.sonata.admin.show.top') { $settings['locale_switcher_route'] = 'show'; } $block = new Block(); $block->setSettings($settings); $block->setName('sonata_translation.block.locale_switcher'); $block->setType('sonata_translation.block.locale_switcher'); $event->addBlock($block); }
/** * Add blocks services to event. * * @param BlockEvent $event */ public function onBlock(BlockEvent $event) { $identifier = $event->getSetting('id', null); if ($identifier == null) { return; } $block = new Block(); $block->setId(uniqid()); $block->setSettings($event->getSettings()); $block->setType($this->blockService->getName()); $event->addBlock($block); }
/** * test the block's form builders. */ public function testFormBuilder() { $templating = new FakeTemplating(); $service = new ContainerBlockService('core.container', $templating); $block = new Block(); $block->setName('block.name'); $block->setType('core.container'); $block->setSettings(array('name' => 'block.code')); $formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false); $formMapper->expects($this->exactly(6))->method('add'); $service->buildCreateForm($formMapper, $block); $service->buildEditForm($formMapper, $block); }
public function testService() { $templating = new FakeTemplating(); $service = new RssBlockService('sonata.page.block.rss', $templating); $block = new Block(); $block->setType('core.text'); $block->setSettings(array('content' => 'my text')); $formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false); $formMapper->expects($this->exactly(2))->method('add'); $service->buildCreateForm($formMapper, $block); $service->buildEditForm($formMapper, $block); $service->execute($block); }
/** * @param BlockEvent $event */ public function onBlock(BlockEvent $event) { if (!$this->optionService->get('twomartens.core', 'showSystemStats')->getValue()) { return; } $variables = ['systemData' => [['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.os', [], 'TwoMartensCoreBundle'), 'value' => PHP_OS], ['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.webserver', [], 'TwoMartensCoreBundle'), 'value' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''], ['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.php', [], 'TwoMartensCoreBundle'), 'value' => PHP_VERSION]]]; $content = $this->templating->render('TwoMartensCoreBundle:blocks:systemStatsBlock.html.twig', $variables); $block = new Block(); $block->setId(uniqid()); $block->setSetting('content', $content); $block->setType('sonata.block.service.text'); $event->addBlock($block); }
/** * @param BlockEvent $event */ public function onBlock(BlockEvent $event) { $content = 'This block is coming from inline event from the template'; if ($event->getSetting('admin') instanceof AdminInterface && $event->getSetting('action') == 'edit') { $admin = $event->getSetting('admin'); $content = sprintf("<p class='well'>The admin subject is <strong>%s</strong></p>", $admin->toString($admin->getSubject())); } $block = new Block(); $block->setId(uniqid()); $block->setSettings(array('content' => $event->getSetting('content', $content))); $block->setType('sonata.block.service.text'); $event->addBlock($block); }
public function findTranslation(Block $block, $locale) { $source = null; // We are checking if the node is the translation provider or translated // from an other node if ($block->getTranslationSource() !== null) { $source = $block->getTranslationSource(); if ($source->getLocale() == $locale) { return $source; } } else { $source = $block; } return $this->createQueryBuilder('n')->addSelect('n')->andWhere('n.translationSource = :source')->andWhere('n.locale = :locale')->setParameters(['source' => $source, 'locale' => $locale])->getQuery()->getOneOrNullResult(); }
public function testService() { $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface', array('render', 'handle')); $kernel->expects($this->exactly(1))->method('render'); $templating = new FakeTemplating(); $service = new ActionBlockService('sonata.page.block.action', $templating, $kernel); $block = new Block(); $block->setType('core.action'); $block->setSettings(array('action' => 'SonataBlockBundle:Page:blockPreview')); $formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false); $formMapper->expects($this->exactly(2))->method('add'); $service->buildCreateForm($formMapper, $block); $service->buildEditForm($formMapper, $block); $service->execute($block); $this->assertEquals('SonataBlockBundle:Page:blockPreview', $templating->parameters['block']->getSetting('action')); }
public function testService() { $templating = new FakeTemplating(); $service = new TextBlockService('sonata.page.block.text', $templating); $block = new Block(); $block->setType('core.text'); $block->setSettings(array('content' => 'my text')); $optionResolver = new OptionsResolver(); $service->setDefaultSettings($optionResolver); $blockContext = new BlockContext($block, $optionResolver->resolve($block->getSettings())); $formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false); $formMapper->expects($this->exactly(2))->method('add'); $service->buildCreateForm($formMapper, $block); $service->buildEditForm($formMapper, $block); $response = $service->execute($blockContext); $this->assertEquals('my text', $templating->parameters['settings']['content']); }
/** * Add context related BlockService, if found. * * @param BlockEvent $event */ public function onBlock(BlockEvent $event) { $context = $event->getSetting('context', null); if ($context == null) { return; } foreach ($this->blockServices as $type => $blockService) { if ($blockService->handleContext($context)) { $block = new Block(); $block->setId(uniqid()); $block->setSettings($event->getSettings()); $block->setType($type); $event->addBlock($block); return; } } }
/** * {@inheritdoc} */ public function load($configuration) { $block = new Block(); $block->setId(uniqid()); $block->setType($configuration['type']); $block->setSettings($this->getSettings($configuration)); $block->setEnabled(true); $block->setCreatedAt(new \DateTime()); $block->setUpdatedAt(new \DateTime()); return $block; }
public function testRenderEventWithListeners() { $blockService = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceInterface'); $blockService->expects($this->once())->method('getJavascripts')->will($this->returnValue(array('/js/base.js'))); $blockService->expects($this->once())->method('getStylesheets')->will($this->returnValue(array('/css/base.css'))); $blockServiceManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceManagerInterface'); $blockServiceManager->expects($this->any())->method('get')->will($this->returnValue($blockService)); $blockRenderer = $this->getMock('Sonata\\BlockBundle\\Block\\BlockRendererInterface'); $blockRenderer->expects($this->once())->method('render')->will($this->returnValue(new Response('<span>test</span>'))); $blockContextManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockContextManagerInterface'); $blockContextManager->expects($this->once())->method('get')->will($this->returnCallback(function (BlockInterface $block) { $context = new BlockContext($block, $block->getSettings()); return $context; })); $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $eventDispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, BlockEvent $event) { $block = new Block(); $block->setId(1); $block->setSettings(array('use_cache' => false)); $block->setType('test'); $event->addBlock($block); return $event; })); $helper = new BlockHelper($blockServiceManager, array(), $blockRenderer, $blockContextManager, $eventDispatcher); $this->assertEquals('<span>test</span>', $helper->renderEvent('my.event')); $this->assertEquals(trim($helper->includeJavascripts('screen', '/application')), '<script src="/application/js/base.js" type="text/javascript"></script>'); $this->assertEquals(trim($helper->includeJavascripts('screen', '')), '<script src="/js/base.js" type="text/javascript"></script>'); $this->assertEquals($helper->includeStylesheets('screen', '/application'), <<<EXPECTED <style type='text/css' media='screen'> @import url(/application/css/base.css); </style> EXPECTED ); $this->assertEquals($helper->includeStylesheets('screen', ''), <<<EXPECTED <style type='text/css' media='screen'> @import url(/css/base.css); </style> EXPECTED ); }
/** * {@inheritdoc} */ public function load($configuration) { if (!in_array($configuration['type'], $this->types)) { throw new \RuntimeException(sprintf('The block type "%s" does not exist', $configuration['type'])); } $block = new Block(); $block->setId(uniqid()); $block->setType($configuration['type']); $block->setEnabled(true); $block->setCreatedAt(new \DateTime()); $block->setUpdatedAt(new \DateTime()); $block->setSettings(isset($configuration['settings']) ? $configuration['settings'] : array()); return $block; }