/**
  * @dataProvider configurationDataProvider
  * @param array $definitions
  * @param string $placement
  * @param array $expected
  */
 public function testGetWidgetDefinitionsByPlacement(array $definitions, $placement, array $expected)
 {
     $registry = new WidgetDefinitionRegistry($definitions);
     $actual = $registry->getWidgetDefinitionsByPlacement($placement);
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $actual);
     $this->assertEquals($expected, $actual->toArray());
 }
Beispiel #2
0
 /**
  * Get available widgets for placement.
  *
  * @param string $placement
  * @return array
  */
 public function getWidgetDefinitions($placement)
 {
     $definitions = $this->widgetDefinitionsRegistry->getWidgetDefinitionsByPlacement($placement)->toArray();
     foreach ($definitions as &$definition) {
         $definition['title'] = $this->translator->trans($definition['title']);
     }
     return $definitions;
 }
 /**
  * @dataProvider configurationDataProvider
  * @param array $definitions
  * @param string $placement
  * @param array $expected
  */
 public function testGetWidgetDefinitionsByPlacement(array $definitions, $placement, array $expected)
 {
     $registry = new WidgetDefinitionRegistry($definitions);
     $actual = $registry->getWidgetDefinitionsByPlacement($placement);
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $actual);
     $this->assertEquals($expected, $actual->toArray());
     $additionalDefinition = ['last' => ['icon' => 'icon.png']];
     $registry->setWidgetDefinitions($additionalDefinition);
     $this->assertEquals(array_merge($definitions, $additionalDefinition), $registry->getWidgetDefinitions()->toArray());
 }
 /**
  * @param array $definitions
  * @param bool $expects
  *
  * @dataProvider definitionDataProvider
  */
 public function testOnKernelRequest(array $definitions, $expects)
 {
     /** @var GetResponseEvent $event */
     $event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock();
     $this->widgetDefinitionsRegistry->expects($this->once())->method('getWidgetDefinitions')->will($this->returnValue(new ArrayCollection($definitions)));
     if ($expects) {
         $this->assetHelper->expects($this->exactly($expects))->method('getUrl')->with($this->isType('string'));
     }
     $this->handler->onKernelRequest($event);
 }
Beispiel #5
0
 /**
  * Get available widgets for placement.
  *
  * @param string $placement
  * @return array
  */
 public function getWidgetDefinitions($placement)
 {
     /** @var PackageInterface $assetHelper */
     $assetHelper = $this->container->get('templating.helper.assets');
     $definitions = $this->widgetDefinitionsRegistry->getWidgetDefinitionsByPlacement($placement)->toArray();
     foreach ($definitions as &$definition) {
         $definition['icon'] = $assetHelper->getUrl($definition['icon']);
     }
     return $definitions;
 }
 public function testGetWidgetDefinitions()
 {
     $placement = 'left';
     $title = 'Foo';
     $definitions = new ArrayCollection();
     $definitions->set('test', array('title' => $title, 'icon' => 'test.ico', 'module' => 'widget/foo', 'placement' => 'left'));
     $this->widgetDefinitionsRegistry->expects($this->once())->method('getWidgetDefinitionsByPlacement')->with($placement)->will($this->returnValue($definitions));
     $this->translator->expects($this->once())->method('trans')->with($title)->will($this->returnValue('trans' . $title));
     $expected = array('test' => array('title' => 'transFoo', 'icon' => 'test.ico', 'module' => 'widget/foo', 'placement' => 'left'));
     $this->assertEquals($expected, $this->extension->getWidgetDefinitions($placement));
 }
Beispiel #7
0
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $definitions = $this->widgetDefinitionsRegistry->getWidgetDefinitions();
     if ($definitions->isEmpty()) {
         return;
     }
     $definitions = $definitions->toArray();
     foreach ($definitions as &$definition) {
         if (!empty($definition['icon'])) {
             $definition['icon'] = $this->assetHelper->getUrl($definition['icon']);
         }
     }
     $this->widgetDefinitionsRegistry->setWidgetDefinitions($definitions);
 }