/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException */ public function testEmbedLocationThrowsUnauthorizedException() { $dom = new \DOMDocument(); $dom->loadXML('<?xml version="1.0" encoding="utf-8"?><section xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"><embed view="embed" node_id="42"/></paragraph></section>'); $viewManager = $this->getMockViewManager(); $locationService = $this->getMockLocationService(); $contentInfo = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo'); $location = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Location'); $location->expects($this->exactly(2))->method("getContentInfo")->will($this->returnValue($contentInfo)); $locationService->expects($this->once())->method('loadLocation')->with($this->equalTo(42))->will($this->returnValue($location)); $repository = $this->getMockRepository(null, $locationService); $repository->expects($this->at(1))->method("canUser")->with("content", "read", $contentInfo, $location)->will($this->returnValue(false)); $repository->expects($this->at(2))->method("canUser")->with("content", "view_embed", $contentInfo, $location)->will($this->returnValue(false)); $converter = new EmbedToHtml5($viewManager, $repository, array('view', 'class', 'node_id', 'object_id')); $converter->convert($dom); }
/** * @param string $input * @param string $output * * @dataProvider dataProviderForTestEmbedLocationNotFound */ public function testEmbedLocationNotFound($input, $output) { $fragmentHandler = $this->getMockFragmentHandler(); $locationService = $this->getMockLocationService(); $repository = $this->getMockRepository(null, $locationService); $logger = $this->getLoggerMock(); $locationService->expects($this->once())->method('loadLocation')->with($this->equalTo(42))->will($this->throwException($this->getMock('eZ\\Publish\\API\\Repository\\Exceptions\\NotFoundException'))); $logger->expects($this->at(0))->method('error')->with('Could not resolve XmlText embed link resource type and ID'); $logger->expects($this->at(1))->method('error')->with('While generating embed for xmltext, could not locate Location with ID 42'); $converter = new EmbedToHtml5($fragmentHandler, $repository, array('view', 'class', 'node_id', 'object_id'), $logger); $document = new DOMDocument(); $document->loadXML($input); $converter->convert($document); $outputDocument = new DOMDocument(); $outputDocument->loadXML($output); $this->assertEquals($outputDocument, $document); }
/** * @param string $input * @param string $output * * @dataProvider dataProviderForTestEmbedLocationNotFound */ public function testEmbedLocationNotFound($input, $output) { $fragmentHandler = $this->getMockFragmentHandler(); $locationService = $this->getMockLocationService(); $repository = $this->getMockRepository(null, $locationService); $logger = $this->getLoggerMock(); $locationService->expects($this->once())->method("loadLocation")->with($this->equalTo(42))->will($this->throwException($this->getMock("eZ\\Publish\\API\\Repository\\Exceptions\\NotFoundException"))); $logger->expects($this->once())->method("error")->with("While generating embed for xmltext, could not locate Location with ID 42"); $converter = new EmbedToHtml5($fragmentHandler, $repository, array("view", "class", "node_id", "object_id"), $logger); $document = new DOMDocument(); $document->loadXML($input); $converter->convert($document); $outputDocument = new DOMDocument(); $outputDocument->loadXML($output); $this->assertEquals($outputDocument, $document); }