public function testGetOutputTwoResourceSets() { $fakeResourceSet1 = Phockito::mock('POData\\Providers\\Metadata\\ResourceSetWrapper'); Phockito::when($fakeResourceSet1->getName())->return("Name 1"); $fakeResourceSet2 = Phockito::mock('POData\\Providers\\Metadata\\ResourceSetWrapper'); //TODO: this certainly doesn't seem right...see #73 Phockito::when($fakeResourceSet2->getName())->return("XML escaped stuff \" ' <> & ?"); $fakeResourceSets = array($fakeResourceSet1, $fakeResourceSet2); Phockito::when($this->mockProvider->getResourceSets())->return($fakeResourceSets); $writer = new JsonLightODataWriter(JsonLightMetadataLevel::FULL(), $this->serviceBase); $actual = $writer->writeServiceDocument($this->mockProvider)->getOutput(); $expected = '{ "d":{ "EntitySet":[ "Name 1","XML escaped stuff \\" \' <> & ?" ] } }'; $this->assertEquals($expected, $actual); }
/** * Gets resource sets which are visible * * @return ResourceSetWrapper[] */ public function getResourceSets() { return $this->providersWrapper->getResourceSets(); }
/** * @param ProvidersWrapper $providers * @return IODataWriter */ public function writeServiceDocument(ProvidersWrapper $providers) { $writer = $this->_writer; $writer->startObjectScope()->writeName("d")->startObjectScope()->writeName(ODataConstants::ENTITY_SET)->startArrayScope(); foreach ($providers->getResourceSets() as $resourceSetWrapper) { $writer->writeValue($resourceSetWrapper->getName()); } $writer->endScope()->endScope()->endScope(); return $this; }
/** * @param ProvidersWrapper $providers * @return IODataWriter */ public function writeServiceDocument(ProvidersWrapper $providers) { $writer = $this->xmlWriter; $writer->startElementNs(null, ODataConstants::ATOM_PUBLISHING_SERVICE_ELEMENT_NAME, ODataConstants::APP_NAMESPACE); $writer->writeAttributeNs(ODataConstants::XML_NAMESPACE_PREFIX, ODataConstants::XML_BASE_ATTRIBUTE_NAME, null, $this->baseUri); $writer->writeAttributeNs(ODataConstants::XMLNS_NAMESPACE_PREFIX, self::ATOM_NAMESPACE_PREFIX, null, ODataConstants::ATOM_NAMESPACE); $writer->writeAttributeNs(ODataConstants::XMLNS_NAMESPACE_PREFIX, self::APP_NAMESPACE_PREFIX, null, ODataConstants::APP_NAMESPACE); $writer->startElement(ODataConstants::ATOM_PUBLISHING_WORKSPACE_ELEMNT_NAME); $writer->startElementNs(self::ATOM_NAMESPACE_PREFIX, ODataConstants::ATOM_TITLE_ELELMET_NAME, null); $writer->text(ODataConstants::ATOM_PUBLISHING_WORKSPACE_DEFAULT_VALUE); $writer->endElement(); foreach ($providers->getResourceSets() as $resourceSetWrapper) { //start collection node $writer->startElement(ODataConstants::ATOM_PUBLISHING_COLLECTION_ELEMENT_NAME); $writer->writeAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME, $resourceSetWrapper->getName()); //start title node $writer->startElementNs(self::ATOM_NAMESPACE_PREFIX, ODataConstants::ATOM_TITLE_ELELMET_NAME, null); $writer->text($resourceSetWrapper->getName()); //end title node $writer->endElement(); //end collection node $writer->endElement(); } //End workspace and service nodes $writer->endElement(); $writer->endElement(); return $this; }
public function testGetOutputTwoResourceSets() { $fakeResourceSet1 = Phockito::mock('POData\\Providers\\Metadata\\ResourceSetWrapper'); Phockito::when($fakeResourceSet1->getName())->return("Name 1"); $fakeResourceSet2 = Phockito::mock('POData\\Providers\\Metadata\\ResourceSetWrapper'); //TODO: this certainly doesn't seem right...see #73 Phockito::when($fakeResourceSet2->getName())->return("XML escaped stuff \" ' <> & ?"); $fakeResourceSets = array($fakeResourceSet1, $fakeResourceSet2); Phockito::when($this->mockProvider->getResourceSets())->return($fakeResourceSets); $fakeBaseURL = "http://some/place/some/where/" . uniqid(); $writer = new AtomODataWriter($fakeBaseURL); $actual = $writer->writeServiceDocument($this->mockProvider)->getOutput(); $expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <service xml:base="' . $fakeBaseURL . '" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app"> <workspace> <atom:title>Default</atom:title> <collection href="Name 1"> <atom:title>Name 1</atom:title> </collection> <collection href="XML escaped stuff " \' <> & ?"> <atom:title>XML escaped stuff " \' <> & ?</atom:title> </collection> </workspace> </service> '; $this->assertEquals($expected, $actual); }