public function testLoad() { $category = $this->getMockBuilder('Sonata\\ClassificationBundle\\Model\\CategoryInterfacer')->setMethods(array('getId'))->disableOriginalConstructor()->getMock(); $category->expects($this->any())->method('getId')->will($this->returnValue(23)); $this->categoryManager->expects($this->any())->method('find')->with($this->equalTo('23'))->will($this->returnValue($category)); $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface'); $block->expects($this->any())->method('getSetting')->with($this->equalTo('categoryId'))->will($this->returnValue(23)); $block->expects($this->once())->method('setSetting')->with($this->equalTo('categoryId'), $this->equalTo($category)); $blockService = $this->getMockForAbstractClass('Sonata\\ClassificationBundle\\Block\\Service\\AbstractCategoriesBlockService', array('block.service', $this->templating, $this->contextManager, $this->categoryManager, $this->categoryAdmin)); $blockService->load($block); }
public function testExecuteWithNew() { $context = array('providers' => array(), 'formats' => array(), 'download' => array()); $this->pool->expects($this->any())->method('getContexts')->will($this->returnValue(array('foo' => $context))); $contextModel = $this->getMock('Sonata\\ClassificationBundle\\Model\\ContextInterface'); $this->contextManger->expects($this->once())->method('findOneBy')->with($this->equalTo(array('id' => 'foo')))->will($this->returnValue(null)); $this->contextManger->expects($this->once())->method('create')->will($this->returnValue($contextModel)); $this->contextManger->expects($this->once())->method('save')->with($this->equalTo($contextModel)); $category = $this->getMock('Sonata\\ClassificationBundle\\Model\\CategoryInterface'); $this->categoryManger->expects($this->once())->method('getRootCategory')->with($this->equalTo($contextModel))->will($this->returnValue(null)); $this->categoryManger->expects($this->once())->method('create')->will($this->returnValue($category)); $this->categoryManger->expects($this->once())->method('save')->with($this->equalTo($category)); $output = $this->tester->execute(array()); $this->assertRegExp('@ > default category for \'foo\' is missing, creating one\\s+Done!@', $this->tester->getDisplay()); $this->assertSame(0, $output); }