예제 #1
0
 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());
 }
예제 #2
0
 /**
  * @param SubBlockConfig $config
  * @return $this
  */
 public function addSubBlock(SubBlockConfig $config)
 {
     $this->subBlocks[$config->getCode()] = $config;
     $this->sortSubBlocks();
     return $this;
 }
예제 #3
0
 /**
  * @param $code
  * @param $config
  * @return SubBlockConfig
  */
 protected function createSubBlock($code, $config)
 {
     $subBlock = new SubBlockConfig($code);
     $subBlock->setTitle($this->accessor->getValue($config, '[title]'));
     $subBlock->setPriority($this->accessor->getValue($config, '[priority]'));
     $subBlock->setDescription($this->accessor->getValue($config, '[description]'));
     return $subBlock;
 }
예제 #4
0
 /**
  * @param BlockConfig $block
  * @param string      $code
  * @param array       $config
  *
  * @return SubBlockConfig
  */
 protected function addSubBlock(BlockConfig $block, $code, $config = [])
 {
     if ($block->hasSubBlock($code)) {
         $subBlock = $block->getSubBlock($code);
     } else {
         $subBlock = new SubBlockConfig($code);
     }
     if ($this->hasValue($config, 'title')) {
         $subBlock->setTitle($config['title']);
     }
     if ($this->hasValue($config, 'description')) {
         $subBlock->setDescription($config['description']);
     }
     if ($this->hasValue($config, 'priority')) {
         $subBlock->setPriority($config['priority']);
     }
     if ($this->hasValue($config, 'useSpan')) {
         $subBlock->setUseSpan($config['useSpan']);
     }
     $block->addSubBlock($subBlock);
     return $subBlock;
 }
 public function testProperties()
 {
     /** test getCode */
     $this->assertEquals($this->blockCode, $this->blockConfig->getCode());
     /** test setCode */
     $this->blockConfig->setCode($this->testCode);
     $this->assertEquals($this->testCode, $this->blockConfig->getCode());
     /** test getTitle */
     $this->assertNull($this->blockConfig->getTitle());
     /** test setTitle */
     $this->blockConfig->setTitle($this->testTitle);
     $this->assertEquals($this->testTitle, $this->blockConfig->getTitle());
     /** test getPriority */
     $this->assertNull($this->blockConfig->getPriority());
     /** test setPriority */
     $this->blockConfig->setPriority(10);
     $this->assertEquals(10, $this->blockConfig->getPriority());
     /** test getClass */
     $this->assertNull($this->blockConfig->getClass());
     /** test setClass */
     $this->blockConfig->setClass($this->testClass);
     $this->assertEquals($this->testClass, $this->blockConfig->getClass());
     /** test getSubBlock */
     $this->assertEquals(array(), $this->blockConfig->getSubBlocks());
     /** test setSubBlocks */
     $this->blockConfig->setSubBlocks($this->testSubBlocks);
     $this->assertEquals($this->testSubBlocks, $this->blockConfig->getSubBlocks());
     /** test setDescription */
     $this->blockConfig->setDescription($this->testDescription);
     $this->assertEquals($this->testDescription, $this->blockConfig->getDescription());
     /** test hasSubBlock */
     $this->assertFalse($this->blockConfig->hasSubBlock('testSubBlock'));
     /** test setSubBlock */
     $subblocks = array();
     foreach ($this->testSubBlocksConfig as $code => $data) {
         $blockDescription = !empty($data['description']) ? $data['description'] : null;
         $subblocks[] = array('code' => $code, 'title' => $data['title'], 'data' => array('some_data'), 'description' => $blockDescription, 'useSpan' => true);
         $subBlock = new SubBlockConfig($code);
         /** test SubBlockConfig set/get Title/Priority/Code */
         $subBlock->setTitle($data['title']);
         $this->assertEquals($data['title'], $subBlock->getTitle());
         $subBlock->setPriority($data['priority']);
         $this->assertEquals($data['priority'], $subBlock->getPriority());
         $subBlock->setCode($code);
         $this->assertEquals($code, $subBlock->getCode());
         $subBlock->setData(array('some_data'));
         $this->assertEquals(array('some_data'), $subBlock->getData());
         $subBlock->setUseSpan(true);
         $this->assertTrue($subBlock->getUseSpan());
         $subBlock->setDescription($blockDescription);
         $this->assertEquals($blockDescription, $subBlock->getDescription());
         /** test SubBlockConfig addSubBlock */
         $this->blockConfig->addSubBlock($subBlock);
         $this->assertEquals($subBlock, $this->blockConfig->getSubBlock($code));
         $this->testSubBlocks[] = $subBlock;
     }
     $this->blockConfig->setSubBlocks($this->testSubBlocks);
     $this->assertEquals($this->testSubBlocks, $this->blockConfig->getSubBlocks());
     $this->assertEquals(array('title' => $this->testTitle, 'class' => $this->testClass, 'subblocks' => $subblocks, 'description' => $this->testDescription), $this->blockConfig->toArray());
 }