Пример #1
0
 public function testHtmlRenderingForFormStartByPhpRenderer()
 {
     if (!$this->getContainer()->hasParameter('oro_layout.twig.resources')) {
         $this->markTestSkipped('TWIG renderer is not enabled.');
     }
     $context = new LayoutContext();
     $context->getResolver()->setOptional(['form']);
     $form = $this->getTestForm();
     $context->set('form', new FormAccessor($form, FormAction::createByPath('test.php'), 'patch'));
     // revert TWIG form renderer to Symfony's default theme
     $this->getContainer()->get('twig.form.renderer')->setTheme($context->get('form')->getView(), 'form_div_layout.html.twig');
     $layoutManager = $this->getContainer()->get('oro_layout.layout_manager');
     $result = $layoutManager->getLayoutBuilder()->add('form:start', null, 'form_start')->getLayout($context)->setRenderer('php')->render();
     $expected = $this->getFormStartTestLayoutResult();
     $this->assertHtmlEquals($expected, $result);
 }
Пример #2
0
 public function testBuildView()
 {
     $formName = 'test_form';
     $formActionPath = 'test_form_action_path';
     $formMethod = 'GET';
     $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::createByPath($formActionPath)));
     $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->assertSame($formActionPath, $view->vars['action_path']);
     $this->assertArrayNotHasKey('action_route_name', $view->vars);
     $this->assertArrayNotHasKey('action_route_parameters', $view->vars);
     $this->assertSame($formMethod, $view->vars['method']);
     $this->assertSame($formEnctype, $view->vars['enctype']);
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * Makes sure that the action, method and enctype are initialized.
  */
 protected function ensureParamsInitialized()
 {
     if ($this->paramsInitialized) {
         return;
     }
     if (null === $this->action) {
         $action = $this->getForm()->getConfig()->getAction();
         $this->action = $action ? FormAction::createByPath($action) : FormAction::createEmpty();
     }
     if (null === $this->method) {
         $this->method = $this->getForm()->getConfig()->getMethod();
     }
     if (null !== $this->method) {
         $this->method = strtoupper($this->method);
     }
     if (null === $this->enctype && $this->getFormView()->vars['multipart']) {
         $this->enctype = 'multipart/form-data';
     }
     $this->paramsInitialized = true;
 }
Пример #5
0
 /**
  * @expectedException \BadMethodCallException
  * @expectedExceptionMessage Not supported
  */
 public function testArrayAccessUnsetDenied()
 {
     $formAction = FormAction::createByPath('test');
     unset($formAction[FormAction::PATH]);
 }