public function testAddBlock() { /** test getBlocks without any adjusted block(s) */ $this->assertEquals(array(), $this->formConfig->getBlocks()); /** test hasBlock without any adjusted block(s) */ $this->assertFalse($this->formConfig->hasBlock('testBlock')); /** @var BlockConfig $blockConfig */ $blockConfig = new BlockConfig('testBlock'); $blockConfig->setTitle('Test Block')->setClass('Oro\\Bundle\\UserBundle\\Entity\\User')->setPriority(1); $subblocks = array(); $subblocksArray = array(); foreach ($this->testSubBlocksConfig as $code => $data) { $subBlock = new SubBlockConfig($code); $subBlock->setTitle($data['title'])->setPriority($data['priority']); $blockConfig->addSubBlock($subBlock); $subblocks[] = $subBlock; $subblocksArray[] = $subBlock->toArray(); } $this->formConfig->addBlock($blockConfig); $this->blocks[] = $blockConfig; /** test hasBlock */ $this->assertTrue($this->formConfig->hasBlock('testBlock')); /** test getBlock */ $this->assertEquals($blockConfig, $this->formConfig->getBlock('testBlock')); /** test getSubBlock */ $this->assertEquals($subblocks[0], $this->formConfig->getSubBlocks('testBlock', 'common')); /** test toArray() */ $this->assertEquals(array(array('title' => 'Test Block', 'class' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'subblocks' => $subblocksArray, 'description' => null)), $this->formConfig->toArray()); /** test getBlocks */ $this->formConfig->setBlocks($this->blocks); $this->assertEquals($this->blocks, $this->formConfig->getBlocks()); }
/** * @param \Twig_Environment $env * @param $context * @param FormView $form * @param string $formVariableName * @return array */ public function render(\Twig_Environment $env, $context, FormView $form, $formVariableName = 'form') { $this->formVariableName = $formVariableName; $this->formConfig = new FormConfig(); $this->context = $context; $this->env = $env; $tmpLoader = $env->getLoader(); $env->setLoader(new \Twig_Loader_Chain([$tmpLoader, new \Twig_Loader_String()])); $this->renderBlock($form); $env->setLoader($tmpLoader); return $this->formConfig->toArray(); }