/**
  * testGnCreateInsertCommand
  *
  * Using the standard Response translating it into PHP-Code to set up the 
  * the structure for MDMetadataObject 
  *
  */
 function testGnCreateInsertCommand()
 {
     //seting up the environment
     $metadata = new MDMetadata();
     $metadata->loadData(self::$MDMetaDataItem);
     $data = array('MDMetadata' => $metadata);
     $cmd = $this->controller->getCommand("GnCreateInsert", $data);
     $result = '&' . $cmd->execute();
     // the & is neccessary for the stringpos below to match the first key
     // now $result should be a string of the type key=valye&otherkey=othervalue...
     if (strpos($result, '&data=') === false) {
         $this->assertEquals(1, 0, "Created command should include the data=");
     }
     if (strpos($result, '&group=') === false) {
         $this->assertEquals(1, 0, "Created command should include the group=");
     }
     if (strpos($result, '&template=') === false) {
         $this->assertEquals(1, 0, "Created command should include the template=");
     }
     if (strpos($result, '&title=') === false) {
         $this->assertEquals(1, 0, "Created command should include the title=");
     }
     if (strpos($result, '&category=') === false) {
         $this->assertEquals(1, 0, "Created command should include the category=");
     }
     if (strpos($result, '&styleSheet=') === false) {
         $this->assertEquals(1, 0, "Created command should include the styleSheet=");
     }
     if (strpos($result, '&validation=') === false) {
         $this->assertEquals(1, 0, "Created command should include the validation=");
     }
 }
 /**
  * This method parses a given XML string and returns a DataObjectSet.
  * This implementation parses a xml schema (i.e. dublin core, iso19139)
  * and retrieves just the title and all subjects of each result entry.
  *
  * The dublin-core metadata schema is embedded into a CSW-metadata
  * envelope (@link http://www.opengis.net/cat/csw/2.0.2).
  *
  * @param string $responseXML valid OGC XML response string
  * @param string $xsl SilverStripe XSLT to transform the XML response into the internal data structure.
  *
  * @return ViewableData
  */
 public function parseXML($responseXML)
 {
     $responseXML = str_replace("'", "\\'", $responseXML);
     // parsing
     $doc = new DOMDocument();
     $doc->loadXML($responseXML);
     list($numberOfRecordsMatched, $numberOfRecordsReturned, $nextRecord, $mdArray) = $this->parseDocument($doc);
     $result = new ViewableData();
     $resultItems = new ArrayList();
     foreach ($mdArray as $item) {
         $metadata = new MDMetadata();
         if (isset($item['dateTimeStamp']) && $item['dateTimeStamp']) {
             $item['dateStamp'] = $item['dateTimeStamp'];
         }
         $metadata->update($item);
         $metadata->loadData($item);
         // print_r($metadata);die();
         $resultItems->push($metadata);
     }
     //To avoid unset variables due the xslt
     if (!isset($nextRecord)) {
         $nextRecord = 1;
     }
     if (!isset($timestamp)) {
         $timestamp = null;
     }
     if (!isset($numberOfRecordsMatched)) {
         $numberOfRecordsMatched = 1;
     }
     if (!isset($numberOfRecordsReturned)) {
         $numberOfRecordsReturned = 1;
     }
     $result = $result->customise(array('Items' => $resultItems, 'timestamp' => $timestamp, 'nextRecord' => $nextRecord, 'numberOfRecordsMatched' => $numberOfRecordsMatched, 'numberOfRecordsReturned' => $numberOfRecordsReturned));
     return $result;
 }
 /**
  * testGenerateISO19139XMLCommand
  *
  * Using the standard Response translating it into PHP-Code to set up the 
  * the structure for MDMetadataObject 
  *
  */
 function testGenerateISO19139XMLCommand()
 {
     //seting up the environment
     $metadata = new MDMetadata();
     $metadata->loadData(self::$MDMetaDataItem);
     $data = array('MDMetadata' => $metadata);
     $cmd = $this->controller->getCommand("GenerateISO19139XML", $data);
     $result = $cmd->execute();
     // now we should have an xml in $result
     $result = preg_replace('/\\<!\\-\\-.*\\-\\-\\>\\n/', '', $result);
     //remove any comment line from the file
     $position = strpos($result, '<gmd:MD_Metadata');
     if ($position === false) {
         $this->assertEquals(1, 0, "Invalid XML! No Starting tag '<gmd:MD_Metadata' found");
     }
     if ($position > 0) {
         $this->assertEquals(1, 0, "returned value should start with '<gmd:MD_Metadata' at the very first beginning not at {$position}");
     }
     $position = strpos($result, '>0587e442-eaee-470d-a0d1-3e3a54cc983b<');
     if ($position === false) {
         $this->assertEquals(1, 0, "Missing fileIdentifier '0587e442-eaee-470d-a0d1-3e3a54cc983b'! should be in there");
     }
 }
 /**
  * Sets the whiltelist array for online web urls protocol. 
  * This array will be used to remove online-resources 
  * from the metadata-detail page.
  *
  * @param $value Array of protocol values, such as array('WWW:LINK-1.0-http--downloaddata', 'WWW:LINK-1.0-http--link')
  */
 static function set_online_resource_web_url_filter($value)
 {
     self::$online_resource_web_url_filter = $value;
 }
 /**
  *  check getPlaceName
  */
 function testgetPlaceName()
 {
     $metadata = new MDMetadata();
     $item = $this->getTestItem();
     $metadata->loadData($item);
     //check initial value
     $this->assertEquals($metadata->MDWestBound, -180, 'initial value MDWestBound');
     $this->assertEquals($metadata->MDEastBound, 180, 'initial value MDEastBound');
     $this->assertEquals($metadata->MDSouthBound, -90, 'initial valueMDSouthBound');
     $this->assertEquals($metadata->MDNorthBound, 90, 'initial valueMDNorthBound');
     // What is it
     $it = $metadata->getPlaceName();
     $this->assertEquals($it, 'World', 'on initial values');
     // checking other value
     $metadata->MDWestBound = 0;
     $metadata->MDEastBound = 0;
     $metadata->MDSouthBound = 0;
     $metadata->MDNorthBound = 0;
     $it = $metadata->getPlaceName();
     $this->assertEquals($it, 'Custom Location', 'on 0;0;0;0');
     //null-Value should return ''
     $metadata->MDWestBound = null;
     $metadata->MDEastBound = null;
     $metadata->MDSouthBound = null;
     $metadata->MDNorthBound = null;
     $it = $metadata->getPlaceName();
     $this->assertEquals($it, '', 'on null;null;null;null');
     //checking an invalid value
     $metadata->MDWestBound = 'what';
     $metadata->MDEastBound = 'is';
     $metadata->MDSouthBound = 'wrong';
     $metadata->MDNorthBound = 'here';
     $it = $metadata->getPlaceName();
     $this->assertEquals($it, '', 'on invalid value');
 }