public function let(ActionFactory $actionFactory, ActionEventManager $eventManager, ManagerRegistry $managerRegistry, ManagerInterface $manager, RouterInterface $router, TranslatorInterface $translator, MassActionDispatcher $massActionDispatcher, JobInstanceRepository $jobInstanceRepository, JobLauncherInterface $jobLauncher, TokenStorageInterface $tokenStorage, Request $request, ParameterBag $attributes, ConfigurationInterface $configuration, Session $session, FlashBag $flashBag) { $this->beConstructedWith($actionFactory, $eventManager, $managerRegistry, $router, $translator, $massActionDispatcher, $jobInstanceRepository, $jobLauncher, $tokenStorage); // initialize configuration $configuration->getEntityClass()->willReturn('entity_class'); $configuration->getName()->willReturn('entity'); // initialize manager $managerRegistry->getFromConfiguration($configuration)->willReturn($manager); // initialize router $router->generate(Argument::type('string'), Argument::type('array'), Argument::any())->will(function ($arguments) { $path = $arguments[0] . '?'; foreach ($arguments[1] as $key => $value) { $path .= '&' . $key . '=' . $value; } return $path; }); // initialize request $request->attributes = $attributes; $attributes->get('id')->willReturn('id'); // initialize flashbag $request->getSession()->willReturn($session); $session->getFlashBag()->willReturn($flashBag); // initialize translator $translator->trans(Argument::type('string'), Argument::any())->will(function ($arguments) { if (!isset($arguments[1])) { $arguments[1] = array(); } $translated = sprintf('<%s>', $arguments[0]); foreach ($arguments[1] as $key => $value) { $translated .= sprintf('%s=%s;', $key, $value); } return $translated; }); }
public function initializeConfigurationForForm(ActionFactory $actionFactory, ConfigurationInterface $configuration, ActionInterface $indexAction) { $actionFactory->getAction('entity', 'index')->willReturn($indexAction); $configuration->hasAction('index')->willReturn(true); $indexAction->getRoute()->willReturn('index'); $indexAction->getRouteParameters(null)->willReturn(['ir_param1' => 'value1']); }
public function it_displays_forms(ManagerInterface $manager, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, Entity $object, EngineInterface $templating, FormView $formView, Response $response) { $request->isMethod('post')->willReturn(false); $manager->find('entity_class', 'id', [])->willReturn($object); $object->getId()->willReturn('id'); $configuration->getActionOptions('edit')->willReturn(['form_type' => 'form_type']); $configuration->hasAction('delete')->willReturn(false); $templating->renderResponse('PimCustomEntityBundle:CustomEntity:form.html.twig', ['form' => $formView, 'formAction' => 'pim_customentity_edit?&customEntityName=entity&id=id', 'customEntityName' => 'entity', 'baseTemplate' => 'PimCustomEntityBundle::layout.html.twig', 'indexUrl' => 'index?&ir_param1=value1', 'pre_render' => true])->willReturn($response); $this->initializeEventManager($eventManager); $this->setConfiguration($configuration); $this->execute($request)->shouldReturn($response); }
public function testObjectRemoval(ManagerInterface $manager, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, $options, $findOptions) { $object = new \stdClass(); $configuration->getActionOptions('delete')->willReturn($options); $this->setConfiguration($configuration); $manager->find('entity_class', 'id', $findOptions)->willReturn($object); $manager->remove($object)->shouldBeCalled(); $this->initializeEventManager($eventManager); $response = $this->execute($request, $configuration); $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\Response'); $response->getStatusCode()->shouldReturn(204); }
public function it_supports_options(ActionFactory $actionFactory, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, EngineInterface $templating, ActionInterface $createAction, Response $response) { $configuration->getActionOptions('index')->willReturn(['quick_create' => true, 'template' => 'template', 'base_template' => 'base_template']); $configuration->hasAction('create')->willReturn(true); $actionFactory->getAction('entity', 'create')->willReturn($createAction); $createAction->getRoute()->willReturn('create_route'); $createAction->getRouteParameters(null)->willReturn(['cr_param1' => 'value1']); $templating->renderResponse('template', ['createUrl' => 'create_route?&cr_param1=value1', 'quickCreate' => true, 'customEntityName' => 'entity', 'baseTemplate' => 'base_template', 'indexUrl' => 'pim_customentity_index?&customEntityName=entity', 'pre_render' => true])->willReturn($response); $this->initializeEventManager($eventManager); $this->setConfiguration($configuration); $this->execute($request)->shouldReturn($response); }
public function it_accepts_a_limit(ActionFactory $actionFactory, AbstractAction $indexAction, Request $request, ConfigurationInterface $configuration, ActionEventManager $eventManager, FlashBag $flashBag) { $actionFactory->getAction('entity', 'index')->willReturn($indexAction); $indexAction->getRoute()->willReturn('index_route'); $indexAction->getRouteParameters(null)->willReturn([]); $this->initializeEventManager($eventManager); $configuration->getActionOptions('quick_export')->willReturn(['limit' => 2]); $this->setConfiguration($configuration); $response = $this->execute($request); $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse'); $response->getTargetUrl()->shouldReturn('index_route?'); $flashBag->add('error', '<pim_custom_entity.export.limit_exceeded>%limit%=2;')->shouldBeCalled(); }
/** * Returns the entity of the request * * @param Request $request * * @throws NotFoundHttpException * @return object */ protected function findEntity(Request $request) { $entity = $this->getManager()->find($this->configuration->getEntityClass(), $request->attributes->get('id'), $this->options['find_options']); if (!$entity) { throw new NotFoundHttpException(); } return $entity; }
public function it_accepts_redirection_options(ManagerInterface $manager, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, Entity $object, FormFactoryInterface $formFactory, FormInterface $form, FlashBagInterface $flashBag) { $request->isMethod('post')->willReturn(true); $form->submit($request)->shouldBeCalled(); $form->isValid()->willReturn(true); $manager->create('entity_class', [], [])->willReturn($object); $manager->save($object, [])->shouldBeCalled(); $object->getId()->willReturn(null); $formFactory->create('form_type', $object, ['f_param1' => 'value1', 'data_class' => 'entity_class'])->shouldBeCalled()->willReturn($form); $configuration->getActionOptions('create')->willReturn(['form_type' => 'form_type', 'form_options' => ['f_param1' => 'value1'], 'redirect_route' => 'redirect_route', 'redirect_route_parameters' => ['c_r_param1' => 'value1'], 'success_message' => 'success_message']); $configuration->hasAction('delete')->willReturn(false); $flashBag->add('success', '<success_message>')->shouldBeCalled(); $this->initializeEventManager($eventManager); $this->setConfiguration($configuration); $response = $this->execute($request); $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse'); $response->getTargetUrl()->shouldReturn('redirect_route?&c_r_param1=value1'); }
public function initializeConfiguration(ConfigurationInterface $configuration) { $configuration->getEntityClass()->willReturn('entity_class'); $configuration->getName()->willReturn('entity'); }
/** * Returns a manager for a configuration * * @param ConfigurationInterface $configuration * * @return ManagerInterface */ public function getFromConfiguration(ConfigurationInterface $configuration) { $options = $configuration->getOptions(); return $this->get($options['manager']); }