コード例 #1
0
 /**
  * @param ContextInterface $context
  *
  * @return FormAction|null
  */
 protected function extractFormAction(ContextInterface $context)
 {
     $formAction = null;
     if ($context->has('form_action')) {
         $formAction = $context->get('form_action');
         if (is_string($formAction)) {
             $formAction = FormAction::createByPath($formAction);
         } elseif (!$formAction instanceof FormAction) {
             throw new \InvalidArgumentException(sprintf('The "form_action" must be a string or instance of "%s", but "%s" given.', 'Oro\\Bundle\\LayoutBundle\\Layout\\Form\\FormAction', $this->getTypeName($formAction)));
         }
         $context->remove('form_action');
     } elseif ($context->has('form_route_name')) {
         $routeName = $context->get('form_route_name');
         if (!is_string($routeName)) {
             throw new \InvalidArgumentException(sprintf('The "form_route_name" must be a string, but "%s" given.', $this->getTypeName($routeName)));
         }
         $routeParams = $context->has('form_route_parameters') ? $context->get('form_route_parameters') : [];
         $formAction = FormAction::createByRoute($routeName, $routeParams);
         $context->remove('form_route_name');
         $context->remove('form_route_parameters');
     }
     return $formAction;
 }
コード例 #2
0
 public function testBuildViewWithRouteWithoutParams()
 {
     $formName = 'test_form';
     $formActionRoute = 'test_form_action_route';
     $formMethod = 'POST';
     $formEnctype = 'test_enctype';
     $formView = new FormView();
     $formAccessor = $this->getMock('Oro\\Bundle\\LayoutBundle\\Layout\\Form\\FormAccessorInterface');
     $formAccessor->expects($this->never())->method('getForm');
     $formAccessor->expects($this->once())->method('getView')->with(null)->will($this->returnValue($formView));
     $formAccessor->expects($this->once())->method('getAction')->will($this->returnValue(FormAction::createByRoute($formActionRoute)));
     $formAccessor->expects($this->once())->method('getMethod')->will($this->returnValue($formMethod));
     $formAccessor->expects($this->once())->method('getEnctype')->will($this->returnValue($formEnctype));
     $this->context->getResolver()->setOptional([$formName]);
     $this->context->set($formName, $formAccessor);
     $view = $this->getBlockView(FormStartType::NAME, ['form_name' => $formName]);
     $this->assertSame($formView, $view->vars['form']);
     $this->assertArrayNotHasKey('action_path', $view->vars);
     $this->assertSame($formActionRoute, $view->vars['action_route_name']);
     $this->assertSame([], $view->vars['action_route_parameters']);
     $this->assertSame($formMethod, $view->vars['method']);
     $this->assertSame($formEnctype, $view->vars['enctype']);
 }
コード例 #3
0
 public function testSetters()
 {
     $formConfig = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $formView = new FormView();
     $formView->vars['multipart'] = true;
     $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface');
     $form->expects($this->any())->method('getConfig')->will($this->returnValue($formConfig));
     $form->expects($this->once())->method('createView')->will($this->returnValue($formView));
     $this->container->expects($this->once())->method('get')->with(self::FORM_SERVICE_ID)->will($this->returnValue($form));
     $formAccessor = new DependencyInjectionFormAccessor($this->container, self::FORM_SERVICE_ID);
     $action = FormAction::createByRoute('test_route', ['foo' => 'bar']);
     $formAccessor->setAction($action);
     $this->assertEquals($action, $formAccessor->getAction());
     $formAccessor->setActionRoute('test_route', []);
     $this->assertEquals(FormAction::createByRoute('test_route', []), $formAccessor->getAction());
     $formAccessor->setMethod('post');
     $this->assertEquals('post', $formAccessor->getMethod());
     $formAccessor->setEnctype('multipart/form-data');
     $this->assertEquals('multipart/form-data', $formAccessor->getEnctype());
 }
コード例 #4
0
 public function testToStringWithAllParams()
 {
     $formAccessor = new FormAccessor($this->form, FormAction::createByRoute('test_route', ['foo' => 'bar']), 'post', 'multipart/form-data');
     $this->assertEquals(self::FORM_NAME . ';action_route:test_route;method:post;enctype:multipart/form-data', $formAccessor->toString());
 }
コード例 #5
0
ファイル: FormActionTest.php プロジェクト: Maksold/platform
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The route name must be a string, but "NULL" given.
  */
 public function testCreateByRouteShouldNotAcceptNull()
 {
     FormAction::createByRoute(null);
 }
コード例 #6
0
 public function testToStringWithAllParams()
 {
     $formAccessor = new DependencyInjectionFormAccessor($this->container, self::FORM_SERVICE_ID, FormAction::createByRoute('test_route', ['foo' => 'bar']), 'post', 'multipart/form-data');
     $this->assertEquals(self::FORM_SERVICE_ID . ';action_route:test_route;method:post;enctype:multipart/form-data', $formAccessor->toString());
 }
コード例 #7
0
 /**
  * @param string $route
  * @param array $routeParams
  */
 public function setActionRoute($route, array $routeParams = [])
 {
     $this->action = FormAction::createByRoute($route, $routeParams);
 }