/** 
  * @covers WindowsAzure\Common\Internal\Atom\Source::writeXml
  * @covers WindowsAzure\Common\Internal\Atom\Source::writeInnerXml
  */
 public function testSourceWriteXmlAllPropertiesWorks()
 {
     // Setup
     $expected = '<atom:source xmlns:atom="http://www.w3.org/2005/Atom"><atom:author xmlns:atom="http://www.w3.org/2005/Atom"><atom:name xmlns:atom="http://www.w3.org/2005/Atom"></atom:name></atom:author><atom:category xmlns:atom="http://www.w3.org/2005/Atom"/><atom:contributor xmlns:atom="http://www.w3.org/2005/Atom"><atom:name xmlns:atom="http://www.w3.org/2005/Atom"></atom:name></atom:contributor><atom:category xmlns:atom="http://www.w3.org/2005/Atom"></atom:category><atom:icon xmlns:atom="http://www.w3.org/2005/Atom">testIcon</atom:icon><atom:logo xmlns:atom="http://www.w3.org/2005/Atom">testLogo</atom:logo><atom:id xmlns:atom="http://www.w3.org/2005/Atom">testId</atom:id><atom:link xmlns:atom="http://www.w3.org/2005/Atom"/><atom:rights xmlns:atom="http://www.w3.org/2005/Atom">testRights</atom:rights><atom:subtitle xmlns:atom="http://www.w3.org/2005/Atom">testSubtitle</atom:subtitle><atom:title xmlns:atom="http://www.w3.org/2005/Atom">testTitle</atom:title><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2012-06-17T20:53:36-07:00</atom:updated></atom:source>';
     $source = new Source();
     $author = array();
     $authorInstance = new Person();
     $author[] = $authorInstance;
     $category = array();
     $categoryInstance = new Category();
     $category[] = $categoryInstance;
     $contributor = array();
     $contributorInstance = new Person();
     $contributor[] = $contributorInstance;
     $link = array();
     $linkInstance = new AtomLink();
     $link[] = $linkInstance;
     $source->setAuthor($author);
     $source->setCategory($category);
     $source->setContributor($contributor);
     $source->setGenerator(new Generator());
     $source->setIcon('testIcon');
     $source->setId('testId');
     $source->setLink($link);
     $source->setLogo('testLogo');
     $source->setRights('testRights');
     $source->setSubtitle('testSubtitle');
     $source->setTitle('testTitle');
     $source->setUpdated(\DateTime::createFromFormat(\DateTime::ATOM, '2012-06-17T20:53:36-07:00'));
     // Test
     $xmlWriter = new \XMLWriter();
     $xmlWriter->openMemory();
     $source->writeXml($xmlWriter);
     $actual = $xmlWriter->outputMemory();
     // Assert
     $this->assertEquals($expected, $actual);
 }
Example #2
0
 /**
  * Creates an ATOM ENTRY instance with specified simpleXML object
  *
  * @param \SimpleXMLElement $entryXml xml element of ATOM ENTRY
  *
  * @return none
  */
 public function fromXml($entryXml)
 {
     Validate::notNull($entryXml, 'entryXml');
     Validate::isA($entryXml, '\\SimpleXMLElement', 'entryXml');
     $this->attributes = (array) $entryXml->attributes();
     $entryArray = (array) $entryXml;
     if (array_key_exists(Resources::AUTHOR, $entryArray)) {
         $this->author = $this->processAuthorNode($entryArray);
     }
     if (array_key_exists(Resources::CATEGORY, $entryArray)) {
         $this->category = $this->processCategoryNode($entryArray);
     }
     if (array_key_exists('content', $entryArray)) {
         $content = new Content();
         $content->fromXml($entryArray['content']);
         $this->content = $content;
     }
     if (array_key_exists(Resources::CONTRIBUTOR, $entryArray)) {
         $this->contributor = $this->processContributorNode($entryArray);
     }
     if (array_key_exists('id', $entryArray)) {
         $this->id = (string) $entryArray['id'];
     }
     if (array_key_exists(Resources::LINK, $entryArray)) {
         $this->link = $this->processLinkNode($entryArray);
     }
     if (array_key_exists('published', $entryArray)) {
         $this->published = $entryArray['published'];
     }
     if (array_key_exists('rights', $entryArray)) {
         $this->rights = $entryArray['rights'];
     }
     if (array_key_exists('source', $entryArray)) {
         $source = new Source();
         $source->parseXml($entryArray['source']->asXML());
         $this->source = $source;
     }
     if (array_key_exists('title', $entryArray)) {
         $this->title = $entryArray['title'];
     }
     if (array_key_exists('updated', $entryArray)) {
         $this->updated = \DateTime::createFromFormat(\DateTime::ATOM, (string) $entryArray['updated']);
     }
 }