HosipLan

Untitled

Jan 5th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1.     public function testSettingItemsControlMapper_RelatedPairsUsingDao()
  2.     {
  3.         $doctrine = $this->getMockBuilder('Kdyby\Doctrine\Registry')
  4.             ->disableOriginalConstructor()
  5.             ->getMock();
  6.  
  7.         // metadata
  8.         $doctrine->expects($this->at(0))
  9.             ->method('getClassMetadata')
  10.             ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RootEntity'))
  11.             ->will($this->returnValue($this->getMetadata(__NAMESPACE__ . '\Fixtures\RootEntity')));
  12.         $doctrine->expects($this->at(1))
  13.             ->method('getClassMetadata')
  14.             ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RelatedEntity'))
  15.             ->will($this->returnValue($this->getMetadata(__NAMESPACE__ . '\Fixtures\RelatedEntity')));
  16.  
  17.         // tested control dependencies
  18.         $entity = new Fixtures\RootEntity("Chuck Norris");
  19.         $container = new EntityContainer($entity);
  20.         $container['children'] = $select = new Nette\Forms\Controls\SelectBox;
  21.  
  22.         // control mapper will require DAO
  23.         $relatedDao = $this->getMockBuilder('Kdyby\Doctrine\Dao')
  24.             ->disableOriginalConstructor()
  25.             ->getMock();
  26.         $doctrine->expects($this->once())
  27.             ->method('getDao')
  28.             ->with($this->equalTo(__NAMESPACE__ . '\Fixtures\RelatedEntity'))
  29.             ->will($this->returnValue($relatedDao));
  30.  
  31.         // assign & create mapper
  32.         $entityMapper = new EntityMapper($doctrine);
  33.         $entityMapper->assign($entity, $container);
  34.  
  35.         // by default, there is no mapper
  36.         $this->assertNull($entityMapper->getControlMapper($select));
  37.         $entityMapper->setControlMapper($select, 'name', 'id');
  38.  
  39.         // mapper should be closure
  40.         $mapper = $entityMapper->getControlMapper($select);
  41.         $this->assertInstanceOf('Closure', $mapper);
  42.  
  43.         $relatedDao->expects($this->atLeastOnce())
  44.             ->method('fetchPairs')
  45.             ->with($this->isInstanceOf('Kdyby\Doctrine\Forms\ItemPairsQuery'))
  46.             ->will($this->returnValue($items = array(1 => 'Lorem')));
  47.  
  48.         // map to control
  49.         $entityMapper->loadControlItems();
  50.         $this->assertEquals($items, $select->getItems());
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment