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); }
/** * @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; }
public function testBuildViewWithEmptyFormParams() { $formName = 'test_form'; $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::createEmpty())); $formAccessor->expects($this->once())->method('getMethod')->will($this->returnValue(null)); $formAccessor->expects($this->once())->method('getEnctype')->will($this->returnValue(null)); $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->assertArrayNotHasKey('action_route_name', $view->vars); $this->assertArrayNotHasKey('action_route_parameters', $view->vars); $this->assertArrayNotHasKey('method', $view->vars); $this->assertArrayNotHasKey('enctype', $view->vars); }
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()); }
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()); }
/** * 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; }
/** * @expectedException \BadMethodCallException * @expectedExceptionMessage Not supported */ public function testArrayAccessUnsetDenied() { $formAction = FormAction::createByPath('test'); unset($formAction[FormAction::PATH]); }
public function testCreateFormAccessorByFormActionObject() { $context = new LayoutContext(); $form = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $formAction = FormAction::createEmpty(); $context['form'] = $form; $context['form_action'] = $formAction; $context['form_method'] = 'method'; $context['form_enctype'] = 'enctype'; $this->contextConfigurator->configureContext($context); $context->resolve(); $this->assertInstanceOf('Oro\\Bundle\\LayoutBundle\\Layout\\Form\\FormAccessor', $context['form']); /** @var FormAccessor $formAccessor */ $formAccessor = $context['form']; $this->assertSame($form, $formAccessor->getForm()); $this->assertSame($formAction, $formAccessor->getAction()); $this->assertEquals('METHOD', $formAccessor->getMethod()); $this->assertEquals('enctype', $formAccessor->getEnctype()); }
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()); }