public function let(ParameterBag $attributes, Request $request, GetResponseEvent $event, ParameterStack $stack)
 {
     $event->getRequest()->willReturn($request);
     $request->attributes = $attributes;
     $attributes->get('_route_params', Argument::any())->willReturn(['foo' => 'bar', 'baz' => 2]);
     $this->beConstructedWith($stack);
 }
 /**
  * @param \FSi\Bundle\AdminBundle\Admin\Context\Request\HandlerInterface $handler
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Symfony\Component\HttpFoundation\ParameterBag $requestParameterBag
  */
 function it_return_response_from_handler($handler, $request, $requestParameterBag)
 {
     $handler->handleRequest(Argument::type('FSi\\Bundle\\AdminBundle\\Event\\FormEvent'), $request)->willReturn(new Response());
     $request->request = $requestParameterBag;
     $requestParameterBag->get('indexes', array())->willReturn(array());
     $this->handleRequest($request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response');
 }
 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;
     });
 }
 /**
  * @param ParameterBag $params
  *
  * @return boolean
  */
 public function update($params)
 {
     /** @var ClientDirection $entity */
     $entity = $this->rGet($params->get('id'));
     $entity->setName($params->get('name'));
     $this->merge($entity);
 }
Exemplo n.º 5
0
 public function testUpdateResponsePage()
 {
     $this->page->getCacheLifeTime()->willReturn('300');
     $this->page->getUuid()->willReturn('1234');
     $this->handler->updateResponse($this->response->reveal(), $this->page->reveal());
     $this->assertEquals('300', $this->parameterBag->get(DebugHandler::HEADER_STRUCTURE_TTL));
 }
 public function configureActionsVars(ParameterBag $actionsVars)
 {
     if ($this->container->isScopeActive('request')) {
         $adminSession = new AdminSession($this->container->get('request'), $this->container->get('session'), $this->getOption('sessionParameter'));
         $actionsVars->set('admin_session', $adminSession);
     }
 }
 public function let(ActionFactory $actionFactory, ActionEventManager $eventManager, ManagerRegistry $managerRegistry, ManagerInterface $manager, RouterInterface $router, TranslatorInterface $translator, ConfigurationInterface $configuration, Request $request, ParameterBag $attributes, EngineInterface $templating, FormFactoryInterface $formFactory, FormInterface $form, FormView $formView, Entity $object, ActionInterface $indexAction)
 {
     $this->beConstructedWith($actionFactory, $eventManager, $managerRegistry, $router, $translator, $templating, $formFactory);
     // 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 form
     $formFactory->create('form_type', $object, ['data_class' => 'entity_class'])->willReturn($form);
     $form->createView()->willReturn($formView);
     $form->getData()->willReturn($object);
     // initialize request
     $request->attributes = $attributes;
     $attributes->get('id')->willReturn('id');
     // initialize configuration for form
     $actionFactory->getAction('entity', 'index')->willReturn($indexAction);
     $configuration->hasAction('index')->willReturn(true);
     $indexAction->getRoute()->willReturn('index');
     $indexAction->getRouteParameters(null)->willReturn(['ir_param1' => 'value1']);
 }
Exemplo n.º 8
0
 private function update(Note $note, ParameterBag $parameters)
 {
     $note->setTitle($parameters->get('title'));
     $note->setColor($parameters->get('color'));
     $note->setContent($parameters->get('content'));
     return $note;
 }
Exemplo n.º 9
0
 private final function buildTopNavMenu(ParameterBag $parameterBag)
 {
     static $tabDataContent = null;
     if (null === $tabDataContent) {
         $yamlParser = new Parser();
         $yamlNavigationPath = __DIR__ . '/../Resources/config/admin/navigation.yml';
         $tabConfiguration = $yamlParser->parse(file_get_contents($yamlNavigationPath));
         $explodedControllerInfo = explode('::', $parameterBag->get('_controller'));
         $explodedControllerName = explode('\\', $explodedControllerInfo[0]);
         $controllerNameIndex = count($explodedControllerName) - 1;
         $controllerName = $explodedControllerName[$controllerNameIndex];
         if (isset($tabConfiguration[$controllerName])) {
             // Construct tabs and inject into twig tpl
             $tabDataContent = array();
             // Get current route name to know when to put "current" class on HTML dom
             $currentRouteName = $parameterBag->get('_route');
             foreach ($tabConfiguration[$controllerName] as $tabName => $tabData) {
                 $tabData['isCurrent'] = false;
                 if ($currentRouteName === $tabData['route']) {
                     $tabData['isCurrent'] = true;
                 }
                 $tabDataContent[] = $this->environment->render('PrestaShopBundle:Admin/Common/_partials:_header_tab.html.twig', array('tabData' => $tabData));
             }
             // Inject them to templating system as global to be able to pass it to the legacy afterwards and once
             // controller has given a response
         }
     }
     return $tabDataContent;
 }
 /**
  * @param ParameterBag $params
  *
  * @return boolean
  */
 public function update($params)
 {
     $entity = $this->rGet($params->get('id'));
     $entity->setName($params->get('name'));
     $entity->setGeneral($params->get('general'));
     $this->merge($entity);
 }
 public function it_do_not_authenticate_channel_when_cookie_name_is_missing(Session $session, ParameterBag $cookies)
 {
     $session->getName()->shouldBeCalled()->willReturn('session');
     $cookies->get('session')->shouldBeCalled()->willReturn('invalid_channel');
     $session->set('socketId', 1)->shouldNotBeCalled();
     $session->set('channelName', 'new_channel')->shouldNotBeCalled();
     $this->authenticate(1, 'new_channel')->shouldReturn(false);
 }
 function it_sets_request($localeSettings, Request $request, ParameterBag $parameterBag)
 {
     $parameterBag->get('_locale')->willReturn(true);
     $request->attributes = $parameterBag;
     $localeSettings->getLanguage()->shouldNotBeCalled();
     $localeSettings->getLocale()->willReturn('fr_FR');
     $this->setRequest($request);
 }
Exemplo n.º 13
0
 function it_checks_if_an_item_is_in_the_includes(Request $request, ParameterBag $parameterBag)
 {
     $includes = 'product,image';
     $entity = 'image';
     $request->query = $parameterBag;
     $parameterBag->get('include')->shouldBeCalledTimes(1)->willReturn($includes);
     $this->inIncludes($entity)->shouldReturn(true);
 }
Exemplo n.º 14
0
 /**
  * Adds a parameter
  *
  * @param string $name
  * @param mixed  $value
  *
  * @return $this
  *
  * @throws \Thuata\ComponentBundle\Exception\InvalidParameterTypeException
  */
 public function addParameter(string $name, $value)
 {
     if (!is_scalar($value)) {
         throw new InvalidParameterTypeException(__CLASS__, __METHOD__, 1, 'scalar', gettype($value));
     }
     $this->parameters->set($name, $value);
     return $this;
 }
Exemplo n.º 15
0
 public function getValueFromRequest(\Symfony\Component\HttpFoundation\ParameterBag $request)
 {
     $size = $request->get($this->getVariable());
     $sv = new SizeValue($this->getVariable());
     $sv->setSize($size['size']);
     $sv->setUnit($size['unit']);
     return $sv;
 }
 public function __construct(ParameterBag $parameters = null)
 {
     if (is_null($parameters)) {
         $parameters = new ParameterBag();
     }
     $parameters->set('Session_Type', self::SESSION_TYPE_RUNTIME)->set('Function', $this->getFunction());
     parent::__construct($parameters);
 }
Exemplo n.º 17
0
 /**
  * @param ParameterBag $params
  *
  * @return boolean
  */
 public function update($params)
 {
     /** @var Office $entity */
     $entity = $this->rGet($params->get('id'));
     $entity->setCity($params->get('city'));
     $entity->setName($params->get('name'));
     $this->merge($entity);
 }
Exemplo n.º 18
0
 function it_returns_null_channel_code_if_no_fake_channel_code_was_found(Request $request, ParameterBag $queryBag, ParameterBag $cookiesBag)
 {
     $queryBag->get('_channel_code')->willReturn(null);
     $request->query = $queryBag;
     $cookiesBag->get('_channel_code')->willReturn(null);
     $request->cookies = $cookiesBag;
     $this->getCode($request)->shouldReturn(null);
 }
 /**
  * @param ParameterBag $params
  *
  * @return boolean
  */
 public function update($params)
 {
     /** @var Diagnosis $entity */
     $entity = $this->rGet($params->get('id'));
     $entity->setDescription($params->get('description'));
     $entity->setPerson($params->get('person'));
     $this->merge($entity);
 }
Exemplo n.º 20
0
 public function generateDiscountCode(ParameterBag $options)
 {
     $length = $options->get('length');
     if (0 > $length || self::MAX_LENGTH < $length) {
         throw new InvalidArgumentException("Wrong number of codes");
     }
     return $this->engine->getCode($length);
 }
 /**
  * @inheritdoc
  */
 public function transform(ParameterBag $item)
 {
     foreach ($item->keys() as $key) {
         if (!in_array($key, $this->fields)) {
             $item->remove($key);
         }
     }
 }
Exemplo n.º 22
0
 public function it_throws_an_exception_for_an_invalid_request(Request $request, ParameterBag $post, ParameterBag $get)
 {
     $request->request = $post;
     $request->query = $get;
     $post->all()->willReturn([]);
     $get->all()->willReturn(['text' => 'Hello!']);
     $this->shouldThrow()->during('convert', [$request]);
 }
 function it_throws_an_exception_when_a_required_object_is_not_found(FilterControllerEvent $event, Request $request, ParameterBag $attributes)
 {
     $event->getRequest()->willReturn($request);
     $request->attributes = $attributes;
     $attributes->get('_security', array())->willReturn(array(array('roles' => array('IS_OWNER'), 'subject' => 'group')));
     $attributes->has('group')->willReturn(false);
     $this->shouldThrow('RuntimeException')->during('checkIfUserIsGranted', array($event));
 }
Exemplo n.º 24
0
 protected function createColumnMapping(ParameterBag $query)
 {
     $mapping = [];
     for ($i = 0; $i < $query->get('iColumns'); $i++) {
         $mapping[$i] = $query->get("mDataProp_{$i}");
     }
     return $mapping;
 }
 /**
  * @return ParameterBag|PHPUnit_Framework_MockObject_MockObject
  */
 protected function getRequestAttributesMock()
 {
     if (!isset($this->requestAttributesMock)) {
         $this->requestAttributesMock = $this->getMock('Symfony\\Component\\HttpFoundation\\ParameterBag');
         $this->requestAttributesMock->expects($this->once())->method('get')->with('is_rest_request')->will($this->returnValue($this->isRestRequest));
     }
     return $this->requestAttributesMock;
 }
 private function addRequestParamForEvent(Notifications $notifications, $eventName, ParameterBag $params)
 {
     $event = $notifications->getNotificationEvent($eventName);
     if ($event->isActive()) {
         $params->set('events[' . $eventName . ']', 'true');
     } else {
         $params->set('events[' . $eventName . ']', 'false');
     }
 }
 function it_throws_an_exception_if_no_repository_can_be_found($doctrine, Request $request, ParameterBag $query, \stdClass $repository)
 {
     $request->query = $query;
     $query->get('search')->willReturn('hello');
     $query->get('referenceDataName')->willReturn(null);
     $query->get('class')->willReturn('Foo\\Bar');
     $doctrine->getRepository('Foo\\Bar')->willReturn($repository);
     $this->shouldThrow(new \LogicException('The repository of the class "Foo\\Bar" can not retrieve options via Ajax.'))->during('listAction', [$request]);
 }
Exemplo n.º 28
0
 /**
  * @param ParameterBag $query
  */
 private function initializeData($query)
 {
     $this->start = $query->get('start', 0);
     $this->perPage = $query->get('length', 0);
     $this->draw = $query->get('draw', 0);
     $this->filters = $query->get('where', []);
     $this->order = $query->get('order', []);
     $this->columns = $query->get('columns', []);
 }
Exemplo n.º 29
-10
 /**
  * Copies billing address to shipping address
  *
  * @param ParameterBag $parameters
  */
 protected function checkCopyAddress(ParameterBag $parameters)
 {
     if (1 === (int) $parameters->get('copyAddress')) {
         $billingAddress = $parameters->get('billingAddress');
         $parameters->set('shippingAddress', ['shippingAddress.firstName' => $billingAddress['billingAddress.firstName'], 'shippingAddress.lastName' => $billingAddress['billingAddress.lastName'], 'shippingAddress.street' => $billingAddress['billingAddress.street'], 'shippingAddress.streetNo' => $billingAddress['billingAddress.streetNo'], 'shippingAddress.flatNo' => $billingAddress['billingAddress.flatNo'], 'shippingAddress.city' => $billingAddress['billingAddress.city'], 'shippingAddress.postCode' => $billingAddress['billingAddress.postCode'], 'shippingAddress.country' => $billingAddress['billingAddress.country']]);
     }
 }
 /**
  * @test
  */
 public function it_should_change_controller_attribute_to_use_service()
 {
     $this->attributes->set('_controller', 'stdClass::method');
     $this->given_controller_is_annotated_by_injectable_annotation();
     $this->listener->onKernelController($this->getEvent());
     $this->assertEquals('stdClass:method', $this->attributes->get('_controller'));
 }