示例#1
0
 public function testGetWidgetOptionsShouldReturnOptionsOfWidgetSpecifiedAsArgument()
 {
     $request = new Request(['_widgetId' => 1]);
     $this->widgetConfigs->setRequest($request);
     $widget = new Widget();
     $this->widgetRepository->expects($this->once())->method('find')->with(2)->will($this->returnValue($widget));
     $options = ['k' => 'v', 'k2' => 'v2'];
     $widget->setOptions($options);
     $this->configProvider->expects($this->once())->method('getWidgetConfig')->willReturn(['configuration' => ['k' => ['type' => 'test'], 'k2' => ['type' => 'test']]]);
     $this->assertEquals(new WidgetOptionBag($options), $this->widgetConfigs->getWidgetOptions(2));
 }
 /**
  * @param FormEvent $event
  */
 public function preSet(FormEvent $event)
 {
     $widgetName = $event->getForm()->getConfig()->getOption('widget_name');
     $attributes = $this->widgetConfigs->getWidgetAttributesForTwig($widgetName);
     $dataItems = $attributes['widgetDataItems'];
     $originalData = $this->getIndexedData($event->getData());
     $data = [];
     $order = 1;
     foreach ($dataItems as $id => $item) {
         $oldItem = isset($originalData[$id]) ? $originalData[$id] : null;
         $data[$id] = ['id' => $id, 'label' => $this->translator->trans($item['label']), 'show' => $oldItem ? $oldItem['show'] : !$originalData, 'order' => $oldItem ? $oldItem['order'] : $order];
         $order++;
     }
     usort($data, function ($a, $b) {
         return $a['order'] - $b['order'];
     });
     $event->setData(['items' => array_values($data)]);
 }
 public function testGetWidgetConfigs()
 {
     $notAllowedAcl = 'invalid_acl';
     $allowedAcl = 'valid_acl';
     $expectedItem = 'expected_item';
     $expectedValue = ['label' => 'test label', 'acl' => $allowedAcl, 'enabled' => true];
     $notGrantedItem = 'not_granted_item';
     $notGrantedValue = ['label' => 'not granted label', 'acl' => $notAllowedAcl, 'enabled' => true];
     $applicableItem = 'applicable_item';
     $applicable = ['label' => 'applicable is set and resolved to true', 'applicable' => '@true', 'enabled' => true];
     $notApplicableItem = 'not_applicable_item';
     $notApplicable = ['label' => 'applicable is set and resolved to false', 'applicable' => '@false', 'enabled' => true];
     $configs = [$expectedItem => $expectedValue, $notGrantedItem => $notGrantedValue, $applicableItem => $applicable, $notApplicableItem => $notApplicable];
     $this->configProvider->expects($this->once())->method('getWidgetConfigs')->will($this->returnValue($configs));
     $this->securityFacade->expects($this->exactly(2))->method('isGranted')->will($this->returnValueMap([[['@true'], [], true], [$allowedAcl, null, true]]));
     $this->resolver->expects($this->exactly(2))->method('resolve')->will($this->returnValueMap([[['@false'], [], [false]], [['@true'], [], [true]]]));
     $result = $this->target->getWidgetConfigs();
     $this->assertArrayHasKey($applicableItem, $result);
     $this->assertArrayHasKey($expectedItem, $result);
 }