/** * Test finding an non-existing container in a page does NOT create a new block */ public function testFindNonExistingContainerCreatesNoNewBlock() { $page = new Page(); $container = $this->manager->findContainer('newcontainer', $page); $this->assertNull($container, 'should not create a new container block'); }
public function testGetPageWithId() { $cBlock = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface'); $cBlock->expects($this->any())->method('hasChildren')->will($this->returnValue(false)); $cBlock->expects($this->any())->method('getId')->will($this->returnValue(2)); $pBlock = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface'); $pBlock->expects($this->any())->method('getChildren')->will($this->returnValue(array($cBlock))); $pBlock->expects($this->any())->method('hasChildren')->will($this->returnValue(true)); $pBlock->expects($this->any())->method('getId')->will($this->returnValue(1)); $page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface'); $page->expects($this->any())->method('getBlocks')->will($this->returnCallback(function () use($pBlock) { static $count; ++$count; if ($count == 1) { return array(); } return array($pBlock); })); $snapshot = $this->getMock('Sonata\\PageBundle\\Model\\SnapshotInterface'); $snapshot->expects($this->once())->method('getContent')->will($this->returnValue(array('blocks' => array()))); $this->snapshotManager->expects($this->once())->method('findEnableSnapshot')->will($this->returnValue($snapshot)); $this->transformer->expects($this->once())->method('load')->will($this->returnValue($page)); $site = $this->getMock('Sonata\\PageBundle\\Model\\SiteInterface'); $snapshotManager = new CmsSnapshotManager($this->snapshotManager, $this->transformer); $page = $snapshotManager->getPage($site, 1); $this->assertInstanceOf('Sonata\\PageBundle\\Model\\SnapshotPageProxy', $page); $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $snapshotManager->getBlock(1)); $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $snapshotManager->getBlock(2)); }