Source of file ParseXMLCommandTest.php
Size: 17,773 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/tests/ParseXMLCommandTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 | <?php /** * @package geocatalog * @subpackage tests */ class ParseXMLCommandTest extends SapphireTest { /** * Also uses SimpleNzctFixture in setUp() */ public static $fixture_file = 'geocatalogue/tests/GetRecordsCommandTest.yml'; public static $ISO19139response='<?xml version="1.0" encoding="UTF-8"?> <csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd"> <csw:SearchStatus timestamp="2009-08-27T08:37:38" /> <csw:SearchResults numberOfRecordsMatched="1" numberOfRecordsReturned="1" elementSet="summary" nextRecord="0"> <gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork"> <gmd:fileIdentifier> <gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">0587e442-eaee-470d-a0d1-3e3a54cc983b</gco:CharacterString> </gmd:fileIdentifier> <gmd:language> <gco:CharacterString>eng</gco:CharacterString> </gmd:language> <gmd:characterSet> <gmd:MD_CharacterSetCode codeListValue="utf8" codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_CharacterSetCode" /> </gmd:characterSet> <gmd:dateStamp> <gco:DateTime xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">2007-07-19T14:45:07</gco:DateTime> </gmd:dateStamp> <gmd:metadataStandardName> <gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">ISO 19115:2003/19139</gco:CharacterString> </gmd:metadataStandardName> <gmd:metadataStandardVersion> <gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">1.0</gco:CharacterString> </gmd:metadataStandardVersion> <gmd:referenceSystemInfo> <gmd:MD_ReferenceSystem> <gmd:referenceSystemIdentifier> <gmd:RS_Identifier> <gmd:code> <gco:CharacterString>WGS 1984</gco:CharacterString> </gmd:code> </gmd:RS_Identifier> </gmd:referenceSystemIdentifier> </gmd:MD_ReferenceSystem> </gmd:referenceSystemInfo> <gmd:identificationInfo> <gmd:MD_DataIdentification> <gmd:citation> <gmd:CI_Citation> <gmd:title> <gco:CharacterString>Hydrological Basins in Africa (Sample record, please remove!)</gco:CharacterString> </gmd:title> </gmd:CI_Citation> </gmd:citation> <gmd:abstract> <gco:CharacterString>Major hydrological basins and their sub-basins. This dataset divides the African continent according to its hydrological characteristics. The dataset consists of the following information:- numerical code and name of the major basin (MAJ_BAS and MAJ_NAME); - area of the major basin in square km (MAJ_AREA); - numerical code and name of the sub-basin (SUB_BAS and SUB_NAME); - area of the sub-basin in square km (SUB_AREA); - numerical code of the sub-basin towards which the sub-basin flows (TO_SUBBAS) (the codes -888 and -999 have been assigned respectively to internal sub-basins and to sub-basins draining into the sea)</gco:CharacterString> </gmd:abstract> <gmd:graphicOverview> <gmd:MD_BrowseGraphic> <gmd:fileName> <gco:CharacterString>thumbnail_s.gif</gco:CharacterString> </gmd:fileName> </gmd:MD_BrowseGraphic> </gmd:graphicOverview> <gmd:graphicOverview> <gmd:MD_BrowseGraphic> <gmd:fileName> <gco:CharacterString>thumbnail.gif</gco:CharacterString> </gmd:fileName> </gmd:MD_BrowseGraphic> </gmd:graphicOverview> <gmd:resourceConstraints> <gmd:MD_Constraints> <gmd:useLimitation gco:nilReason="missing"> <gco:CharacterString /> </gmd:useLimitation> </gmd:MD_Constraints> </gmd:resourceConstraints> <gmd:spatialRepresentationType> <gmd:MD_SpatialRepresentationTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_SpatialRepresentationTypeCode" codeListValue="vector" /> </gmd:spatialRepresentationType> <gmd:spatialResolution> <gmd:MD_Resolution> <gmd:equivalentScale> <gmd:MD_RepresentativeFraction> <gmd:denominator> <gco:Integer>5000000</gco:Integer> </gmd:denominator> </gmd:MD_RepresentativeFraction> </gmd:equivalentScale> </gmd:MD_Resolution> </gmd:spatialResolution> <gmd:language> <gco:CharacterString>eng</gco:CharacterString> </gmd:language> <gmd:characterSet> <gmd:MD_CharacterSetCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_CharacterSetCode" codeListValue="utf8" /> </gmd:characterSet> <gmd:topicCategory> <gmd:MD_TopicCategoryCode>inlandWaters</gmd:MD_TopicCategoryCode> </gmd:topicCategory> <gmd:extent> <gmd:EX_Extent> <gmd:geographicElement> <gmd:EX_GeographicBoundingBox> <gmd:westBoundLongitude> <gco:Decimal>-17.3</gco:Decimal> </gmd:westBoundLongitude> <gmd:southBoundLatitude> <gco:Decimal>-34.6</gco:Decimal> </gmd:southBoundLatitude> <gmd:eastBoundLongitude> <gco:Decimal>51.1</gco:Decimal> </gmd:eastBoundLongitude> <gmd:northBoundLatitude> <gco:Decimal>38.2</gco:Decimal> </gmd:northBoundLatitude> </gmd:EX_GeographicBoundingBox> </gmd:geographicElement> </gmd:EX_Extent> </gmd:extent> </gmd:MD_DataIdentification> </gmd:identificationInfo> <gmd:distributionInfo> <gmd:MD_Distribution> <gmd:distributionFormat> <gmd:MD_Format> <gmd:name> <gco:CharacterString>ShapeFile</gco:CharacterString> </gmd:name> <gmd:version> <gco:CharacterString>Grass Version 6.1</gco:CharacterString> </gmd:version> </gmd:MD_Format> </gmd:distributionFormat> <gmd:transferOptions> <gmd:MD_DigitalTransferOptions> <gmd:onLine> <gmd:CI_OnlineResource> <gmd:linkage> <gmd:URL>http://www.fao.org/ag/AGL/aglw/aquastat/watresafrica/index.stm</gmd:URL> </gmd:linkage> </gmd:CI_OnlineResource> </gmd:onLine> <gmd:onLine> <gmd:CI_OnlineResource> <gmd:linkage xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx"> <gmd:URL>http://localhost:8080/geonetwork/srv/en/resources.get?id=11&fname=basins.zip&access=private</gmd:URL> </gmd:linkage> </gmd:CI_OnlineResource> </gmd:onLine> <gmd:onLine> <gmd:CI_OnlineResource> <gmd:linkage> <gmd:URL>http://geonetwork3.fao.org/ows/296</gmd:URL> </gmd:linkage> </gmd:CI_OnlineResource> </gmd:onLine> </gmd:MD_DigitalTransferOptions> </gmd:transferOptions> </gmd:MD_Distribution> </gmd:distributionInfo> <gmd:dataQualityInfo> <gmd:DQ_DataQuality> <gmd:lineage> <gmd:LI_Lineage> <gmd:statement> <gco:CharacterString>The linework of the map is obtained by delineating drainage basin boundaries from an hydrologically corrected digital elevation model with a resolution of 1 * 1 km.</gco:CharacterString> </gmd:statement> </gmd:LI_Lineage> </gmd:lineage> </gmd:DQ_DataQuality> </gmd:dataQualityInfo> </gmd:MD_Metadata> </csw:SearchResults> </csw:GetRecordsResponse> '; public static $HTMLResponseNoDocType='<html> <head> <base href="http://www.silverstripe.com/" > <title>SilverStripe.com - Open Source CMS / Framework</title> </head> <body> <h1>SilverStripe</h1> </body> </html>'; public static $EmptyXMLResponse='<?xml version="1.0" encoding="UTF-8"?><nothing></nothing>'; protected $controller = null; protected $directory_prefix = '../geocatalogue/xslt/'; /** * Initiate the controller and page classes and configure GeoNetwork service * to use the mockup-controller for testing. */ public function setUp() { parent::setUp(); $url = Director::absoluteBaseURL() . 'GetRecordsCommandTest_Controller'; $page = $this->objFromFixture('CataloguePage', 'catalogue'); $page->GeonetworkBaseURL = $url; $this->controller = new CataloguePage_Controller($page); $this->controller->pushCurrent(); GetRecordsCommand::set_catalogue_url("/getrecords?usetestmanifest=1&flush=1"); // check from where the test is executed (important when running the // tests via a CI environment. if (in_array('cli-script.php', scandir('.'))) { // system is in sapphire directory $this->directory_prefix = '../geocatalogue/xslt/'; } elseif (in_array('geocatalog', scandir('.'))) { $this->directory_prefix = 'geocatalogue/xslt/'; } } /** * Remove test controller from global controller-stack. */ public function tearDown() { $this->controller->popCurrent(); parent::tearDown(); } /** * testParseXMLCommand * * Using the standard Response translating it into PHP-Code to set up the * the structure for MDMetadataObject * */ public function testParseXMLCommand() { //setting up the environment $data = array( 'xml' => self::$ISO19139response, 'xsl' => $this->directory_prefix.'ISO19139/iso19139_to_silverstripe.xsl', ); $cmd = $this->controller->getCommand("ParseXML", $data); $result = $cmd->execute(); $SearchRecord = $result->__get('Items'); $this->assertEquals($SearchRecord->TotalItems(), 1, 'We should have exact one object here'); $metadata = $SearchRecord->First(); $uuid = $metadata->fileIdentifier; $this->assertEquals($uuid, '0587e442-eaee-470d-a0d1-3e3a54cc983b', 'UUID not found after parsing'); } /** * testParseXMLCommandWithHTMLResponseNoDoctype * * Using a valid HTML-Response without a DocType is the way of the geonetwork server to * indicate that an error has occured * */ public function testParseXMLCommandWithHTMLResponseNoDoctype() { //seting up the environment $data = array( 'xml' => self::$HTMLResponseNoDocType , 'xsl' => '../geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { return; } $this->assertTrue(false, 'ParseXML should throw an error on html-content starting with <html>'); } /** * testParseXMLCommandWithEmptyXMLResponse * * Using a valid XML-Response with just an empty * should result in an empty string * */ public function testParseXMLCommandWithEmptyXMLResponse() { //seting up the environment $data = array( 'xml' => self::$EmptyXMLResponse , 'xsl' => Director::baseFolder().'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { $this->assertTrue(false, 'ParseXML should NOT throw an error on valid xml-content'); } $this->assertTrue(is_a($result, 'ViewableData'), 'We should get a ViewableData'); $SearchRecord = $result->__get('Items'); $this->assertEquals($SearchRecord->TotalItems(), 0, 'We should have an empty DataObjectSet'); } /** * testParseXMLCommandWithEmptyResponse * * Using an empty Response should result in an empty string * */ public function testParseXMLCommandWithEmptyResponse() { //seting up the environment $data = array( 'xml' => '' , 'xsl' => Director::baseFolder().'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { $this->assertTrue(false, 'ParseXML should NOT throw an error on empty Response '); } $this->assertTrue(is_a($result, 'ViewableData'), 'We should get a ViewableData'); $SearchRecord = $result->__get('Items'); $this->assertEquals($SearchRecord->TotalItems(), 0, 'We should have an empty DataObjectSet'); } /** * testParseXMLCommandWithNullResponse * * Using a null Response should result in an empty string * */ public function testParseXMLCommandWithNullResponse() { //seting up the environment $data = array( 'xml' => null, 'xsl' => Director::baseFolder().'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { return;// ok, we got an exception } $this->assertTrue(false, 'ParseXML should throw an error on null Request'); } /** * testParseXMLCommandWithEmptyStylesheet * * Using an empty stylesheet should result in an exception * */ public function testParseXMLCommandWithEmptyStylesheet() { //seting up the environment $data = array( 'xml' => self::$EmptyXMLResponse , 'xsl' => '', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { return; //ok we got an excetion } $this->assertTrue(false, 'ParseXML should throw an exception on an empty stylesheet'); } /** * testParseXMLCommandWithNullStylesheet * * Using NO stylesheet should result in an exception * */ public function testParseXMLCommandWithNullStylesheet() { //seting up the environment $data = array( 'xml' => self::$EmptyXMLResponse , 'xsl' => null, ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { return; //ok we got an excetion } $this->assertTrue(false, 'ParseXML should throw an exception if there is NO stylesheet'); } /** * testParseXMLCommandWithInvalidStylesheet * * Using an invalid stylesheet should result in an exception * */ public function testParseXMLCommandWithInvalidStylesheet() { //seting up the environment $data = array( 'xml' => self::$EmptyXMLResponse , 'xsl' => '../NoStylesheetFound', ); $cmd = $this->controller->getCommand("ParseXML", $data); //execute has not to throw an error try { $result = $cmd->execute(); } catch (ParseXMLCommand_Exception $e) { return; //ok we got an excetion } $this->assertTrue(false, 'ParseXML should throw an exception if the stylesheet could not be found'); } } |