/** * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * @param \FSi\Bundle\AdminBundle\Admin\Manager $adminManager * @param \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $authorizationChecker * @param \FSi\Bundle\AdminSecurityBundle\spec\fixtures\SecuredElement $securedElement * @param \FSi\Bundle\AdminBundle\Admin\Element $element */ function it_remove_element_from_admin_manager_when_its_secured_from_user($event, $adminManager, $authorizationChecker, $securedElement, $element) { $adminManager->getElements()->shouldBeCalled()->willReturn(array($securedElement, $element)); $securedElement->isAllowed($authorizationChecker)->willReturn(false); $securedElement->getId()->shouldBeCalled()->willReturn('secured'); $adminManager->removeElement('secured')->shouldBeCalled(); $this->onKernelRequest($event); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration * @return bool */ public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); $id = $request->attributes->get($param, ''); if (!$this->manager->hasElement($id)) { throw new NotFoundHttpException(sprintf('Admin element with id %s does not exist.', $id)); } $request->attributes->set($param, $this->manager->getElement($id)); return true; }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager * @param \FSi\Bundle\AdminBundle\Admin\Element $element * @param \FSi\Bundle\DataGridBundle\DataGrid\Extension\Symfony\ColumnType\Action $column * @throws \FSi\Component\DataGrid\Exception\UnknownOptionException */ function it_initializes_action_route_and_parameters_based_on_element_id($manager, $element, $column) { $actionOptions = array('element' => 'some_element_id', 'additional_parameters' => array('additional_action_parameter' => 'action_parameter_value'), 'other_action_option' => 'other_option_value'); $otherAction = array('any_action_option' => 'any_option_value'); $column->getOption('actions')->willReturn(array('some_action' => $actionOptions, 'other_action' => $otherAction)); $manager->hasElement('some_element_id')->willReturn(true); $manager->getElement('some_element_id')->willReturn($element); $element->getId()->willReturn('some_element_id'); $element->getRoute()->willReturn('admin_element_route'); $element->getRouteParameters()->willReturn(array('additional_element_parameter' => 'element_parameter_value')); $column->setOption('actions', array('some_action' => array('route_name' => 'admin_element_route', 'additional_parameters' => array('element' => 'some_element_id', 'additional_element_parameter' => 'element_parameter_value', 'additional_action_parameter' => 'action_parameter_value'), 'parameters_field_mapping' => array('id' => 'id'), 'other_action_option' => 'other_option_value'), 'other_action' => array('any_action_option' => 'any_option_value')))->shouldBeCalled(); $this->filterValue($column, 'whatever')->shouldReturn('whatever'); }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager */ function let($manager) { $prophet = new Prophet(); $manager->getElement(Argument::type('string'))->will(function ($args) use($prophet) { if ($args[0] == 'non_existing') { throw new \Exception(sprintf('Element %s does not exist', $args[0])); } $element = $prophet->prophesize('FSi\\Bundle\\AdminBundle\\Admin\\Element'); $element->getId()->willReturn($args[0]); return $element; }); $manager->hasElement(Argument::type('string'))->will(function ($args) { return $args[0] != 'non_existing'; }); $this->beConstructedWith($manager, __DIR__ . '/admin_menu.yml'); }
/** * @param \Symfony\Component\OptionsResolver\Options $options * @return \FSi\Bundle\AdminBundle\Admin\Element */ private function getElementFromOption(Options $options) { return $this->manager->getElement($options['element']); }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager * @param \FSi\Bundle\AdminBundle\Factory\ProductionLine $productionLine * @param \FSi\Bundle\AdminBundle\Admin\Element $adminElement */ function it_visit_manager_and_add_into_it_elements($manager, $productionLine, $adminElement) { $productionLine->workOn($adminElement)->shouldBeCalled(); $manager->addElement($adminElement)->shouldBeCalled(); $this->visitManager($manager); }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager * @param \FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement $batchElement * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\ParameterBag $queryAttributes * @param \Symfony\Component\Routing\RouterInterface $router * @param \Symfony\Component\Form\Test\FormBuilderInterface $formBuilder * @param \Symfony\Component\Form\FormView $formView * @param \FSi\Component\DataGrid\Column\ColumnTypeInterface $column * @param \FSi\Component\DataGrid\Column\HeaderViewInterface $view */ function it_adds_redirect_uri_to_actions_when_no_redirect_uri_is_defined($manager, $batchElement, $request, $queryAttributes, $router, $formBuilder, $formView, $column, $view) { $column->getOption('actions')->willReturn(array(array('element' => 'some_batch_element_id', 'additional_parameters' => array('some_additional_parameter' => 'some_value'), 'label' => 'batch_action_label'))); $column->getOption('translation_domain')->willReturn('FSiAdminBundle'); $manager->hasElement('some_batch_element_id')->willReturn(true); $manager->getElement('some_batch_element_id')->willReturn($batchElement); $batchElement->getId()->willReturn('some_batch_element_id'); $batchElement->getRoute()->willReturn('fsi_admin_batch'); $batchElement->getRouteParameters()->willReturn(array('element' => 'some_batch_element_id')); $queryAttributes->has('redirect_uri')->willReturn(false); $request->getRequestUri()->willReturn('current_request_uri'); $router->generate('fsi_admin_batch', array('element' => 'some_batch_element_id', 'some_additional_parameter' => 'some_value', 'redirect_uri' => 'current_request_uri'))->willReturn('path_to_batch_action'); $formBuilder->add('action', 'choice', array('choices' => array(0 => 'crud.list.batch.empty_choice', 'path_to_batch_action' => 'batch_action_label'), 'translation_domain' => 'FSiAdminBundle'))->willReturn(); $formBuilder->add('submit', 'submit', array('label' => 'crud.list.batch.confirm', 'translation_domain' => 'FSiAdminBundle'))->willReturn(); $view->setAttribute('batch_form', $formView)->shouldBeCalled(); $this->buildHeaderView($column, $view); }
/** * @param array $actionOptions * @return array */ private function generateActionOptions(array $actionOptions) { $element = $this->manager->getElement($actionOptions['element']); $additionalParameters = array_merge(array('element' => $element->getId()), $element->getRouteParameters(), isset($actionOptions['additional_parameters']) ? $actionOptions['additional_parameters'] : array()); return array('route_name' => $element->getRoute(), 'additional_parameters' => $additionalParameters, 'parameters_field_mapping' => array('id' => 'id')); }