Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testSettingItemsControlMapper_RelatedPairsUsingDao()
- {
- $doctrine = $this->getMockBuilder('Kdyby\Doctrine\Registry')
- ->disableOriginalConstructor()
- ->getMock();
- // metadata
- $doctrine->expects($this->at(0))
- ->method('getClassMetadata')
- ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RootEntity'))
- ->will($this->returnValue($this->getMetadata(__NAMESPACE__ . '\Fixtures\RootEntity')));
- $doctrine->expects($this->at(1))
- ->method('getClassMetadata')
- ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RelatedEntity'))
- ->will($this->returnValue($this->getMetadata(__NAMESPACE__ . '\Fixtures\RelatedEntity')));
- // tested control dependencies
- $entity = new Fixtures\RootEntity("Chuck Norris");
- $container = new EntityContainer($entity);
- $container['children'] = $select = new Nette\Forms\Controls\SelectBox;
- // control mapper will require DAO
- $relatedDao = $this->getMockBuilder('Kdyby\Doctrine\Dao')
- ->disableOriginalConstructor()
- ->getMock();
- $doctrine->expects($this->once())
- ->method('getDao')
- ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RelatedEntity'))
- ->will($this->returnValue($relatedDao));
- // assign & create mapper
- $entityMapper = new EntityMapper($doctrine);
- $entityMapper->assign($entity, $container);
- // by default, there is no mapper
- $this->assertNull($entityMapper->getControlMapper($select));
- $entityMapper->setControlMapper($select, 'name', 'id');
- // mapper should be closure
- $mapper = $entityMapper->getControlMapper($select);
- $this->assertInstanceOf('Closure', $mapper);
- $relatedDao->expects($this->atLeastOnce())
- ->method('fetchPairs')
- ->with($this->isInstanceOf('Kdyby\Doctrine\Forms\ItemPairsQuery'))
- ->will($this->returnValue($items = array(1 => 'Lorem')));
- // map to control
- $entityMapper->loadControlItems();
- $this->assertEquals($items, $select->getItems());
- }
Advertisement
Add Comment
Please, Sign In to add comment