示例#1
0
 /**
  * Validates the xml data against Gnip schema.
  * 
  * @param string $xml
  * @return string xml you passed in
  */
 private function validate($xml)
 {
     $doc = new GnipDOMDocument();
     $doc->loadXML($xml);
     $doc->schemaValidate(dirname(__FILE__) . '/gnip.xsd');
     return $xml;
 }
示例#2
0
 function testValidatePayloadSchema()
 {
     $a = new Services_Gnip_Activity($this->at, $this->action, $this->activityID, $this->URL, $this->source, $this->keyword, null, $this->actor, $this->destinationURL, $this->tag, $this->to, $this->regardingURL, array($this->payload, $this->payloadArray));
     $d = new GnipDOMDocument();
     $d->loadXML($a->toXML());
     $status = $d->schemaValidate(dirname(__FILE__) . '../../../src/Services/Gnip/gnip.xsd');
     $this->assertEquals($status, true);
 }
示例#3
0
 function testToXmlNullElements()
 {
     $doc = new GnipDOMDocument();
     $root = $doc->createElement('activity');
     $doc->appendChild($root);
     $expected_xml = "<activity/>";
     $place = new Services_Gnip_Place();
     $place->toXML($doc, $root);
     $this->assertEquals($expected_xml, $doc->asXML());
 }
示例#4
0
 function xtestToXmlUnbound()
 {
     $mediaURLS = array(array("mediaURL" => "http://gnipcentral.com", "type" => "image"), array("mediaURL" => "http://flickr.com/tour", "type" => "video"));
     $doc = new GnipDOMDocument();
     $root = $doc->createElement('activity');
     $doc->appendChild($root);
     $expected_xml = '<activity><payload><title>title</title><body>body</body>' . '<mediaURL type="image">http://gnipcentral.com</mediaURL>' . '<mediaURL type="video">http://flickr.com/tour</mediaURL>' . '<raw>H4sIAAAAAAAAAytKLAcAVduzGgMAAAA=</raw></payload></activity>';
     $payload = new Services_Gnip_Payload("raw", "title", "body", $mediaURLS);
     $payload->toXML($doc, $root);
     $this->assertEquals($expected_xml, $doc->asXML());
 }
示例#5
0
 /**
  * Converts the activity to properly formatted XML.     
  * 
  * @return XML formatted activity data
  */
 public function toXML()
 {
     $doc = new GnipDOMDocument();
     $root = $doc->createElement('activity');
     $doc->appendChild($root);
     $root->appendChild($doc->createElement('at', $this->at->format(DATE_ATOM)));
     $root->appendChild($doc->createElement('action', $this->action));
     if ($this->activityID != null) {
         $root->appendChild($doc->createElement('activityID', $this->activityID));
     }
     if ($this->URL != null) {
         $root->appendChild($doc->createElement('URL', $this->URL));
     }
     if ($this->source != null) {
         $doc->appendChildren($doc, $root, "source", $this->source);
     }
     if ($this->keyword != null) {
         $doc->appendChildren($doc, $root, "keyword", $this->keyword);
     }
     if ($this->place != null) {
         foreach ($this->place as $key => $val) {
             $val->toXML($doc, $root);
         }
     }
     if ($this->actor != null) {
         $doc->appendChildren($doc, $root, "actor", $this->actor);
     }
     if ($this->destinationURL != null) {
         $doc->appendChildren($doc, $root, "destinationURL", $this->destinationURL);
     }
     if ($this->tag != null) {
         $doc->appendChildren($doc, $root, "tag", $this->tag);
     }
     if ($this->to != null) {
         $doc->appendChildren($doc, $root, "to", $this->to);
     }
     if ($this->regardingURL != null) {
         $doc->appendChildren($doc, $root, "regardingURL", $this->regardingURL);
     }
     if ($this->payload != null) {
         if (@property_exists($this->payload, "raw")) {
             $this->payload->toXML($doc, $root);
         }
     }
     return $doc->asXML();
 }
示例#6
0
 /**
  * Converts the rules to properly formatted XML.
  * 
  * @return XML formatted rule data
  */
 public function toXML()
 {
     $doc = new GnipDOMDocument();
     $ruleRoot = $doc->createElement('rule', $this->value);
     $doc->appendChild($ruleRoot);
     $attrName = $doc->createAttribute('type');
     $ruleRoot->appendChild($attrName);
     $attrVal = $doc->createTextNode($this->type);
     $attrName->appendChild($attrVal);
     return trim($doc->asXML());
 }