示例#1
0
 public function testArrayAccessGetFromContextData()
 {
     $name = 'foo';
     $expectedData = new \stdClass();
     $expectedDataId = 'foo_id';
     $this->context[$name] = 'other';
     $this->context->getResolver()->setOptional([$name]);
     $this->context->data()->set($name, $expectedDataId, $expectedData);
     $this->context->resolve();
     $this->registry->expects($this->once())->method('findDataProvider')->with($name)->will($this->returnValue(null));
     $this->assertSame($expectedData, $this->dataAccessor[$name]);
     // test data provider identifier
     $this->assertEquals($expectedDataId, $this->dataAccessor->getIdentifier($name));
     // test that context data provider is cached
     $this->assertSame($expectedData, $this->dataAccessor[$name]);
 }
示例#2
0
 /**
  * @expectedException \Oro\Component\Layout\Exception\LogicException
  * @expectedExceptionMessage The item "test" cannot be removed because the context variables are already resolved.
  */
 public function testRemoveExistingValueThrowsExceptionWhenDataAlreadyResolved()
 {
     $this->context->getResolver()->setOptional(['test']);
     $this->context->set('test', 'val');
     $this->context->resolve();
     $this->context->remove('test');
 }
 /**
  * @param EmbeddedForm  $formEntity
  * @param FormInterface $form
  *
  * @return Layout
  */
 public function getLayout(EmbeddedForm $formEntity, FormInterface $form = null)
 {
     $formTypeName = $formEntity->getFormType();
     $customLayout = $this->formManager->getCustomFormLayoutByFormType($formTypeName);
     $layoutContext = new LayoutContext();
     $layoutContext->getResolver()->setRequired(['embedded_form_type'])->setOptional(['embedded_form', 'embedded_form_custom_layout']);
     $layoutContext->set('theme', 'embedded_default');
     $layoutContext->set('embedded_form', null === $form ? null : new FormAccessor($form));
     $layoutContext->set('embedded_form_type', $formTypeName);
     $layoutContext->set('embedded_form_custom_layout', $customLayout);
     $layoutContext->data()->set('embedded_form_entity', '', $formEntity);
     $layoutBuilder = $this->layoutManager->getLayoutBuilder();
     // TODO discuss adding root automatically
     $layoutBuilder->add('root', null, 'root');
     return $layoutBuilder->getLayout($layoutContext);
 }
示例#4
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);
 }
示例#5
0
 public function testShouldThrowExceptionForNotHavingRequiredVarsWhenContextReturned()
 {
     $this->setupLayoutExpectations();
     $attributes = ['_layout' => new LayoutAnnotation(['vars' => ['required1', 'required2']])];
     $context = new LayoutContext();
     $context->getResolver()->setRequired(['required2']);
     $context['required2'] = 'value1';
     $responseEvent = $this->createResponseForControllerResultEvent($attributes, $context);
     $this->listener->onKernelView($responseEvent);
 }