diff --git a/src/FeedIo/Rule/Atom/Author.php b/src/FeedIo/Rule/Atom/Author.php index 9e4193e2..92b5d4d3 100644 --- a/src/FeedIo/Rule/Atom/Author.php +++ b/src/FeedIo/Rule/Atom/Author.php @@ -28,9 +28,9 @@ public function setProperty(NodeInterface $node, \DOMElement $element) { if ($node instanceof ItemInterface) { $author = $node->newAuthor(); - $author->setName($this->getAttributeValue($element, 'name')); - $author->setUri($this->getAttributeValue($element, 'uri')); - $author->setEmail($this->getAttributeValue($element, 'email')); + $author->setName($this->getChildValue($element, 'name')); + $author->setUri($this->getChildValue($element, 'uri')); + $author->setEmail($this->getChildValue($element, 'email')); $node->setAuthor($author); } @@ -48,13 +48,14 @@ public function createElement(\DomDocument $document, NodeInterface $node) { if ($node instanceof ItemInterface && !is_null($node->getAuthor())) { $element = $document->createElement(static::NODE_NAME); - $element->setAttribute('name', $node->getAuthor()->getName()); - $element->setAttribute('uri', $node->getAuthor()->getUri()); - $element->setAttribute('email', $node->getAuthor()->getEmail()); + $element->appendChild($document->createElement('name', $node->getAuthor()->getName())); + $element->appendChild($document->createElement('uri', $node->getAuthor()->getUri())); + $element->appendChild($document->createElement('email', $node->getAuthor()->getEmail())); return $element; } return; } + } diff --git a/src/FeedIo/RuleAbstract.php b/src/FeedIo/RuleAbstract.php index d6252ee8..c46cd735 100644 --- a/src/FeedIo/RuleAbstract.php +++ b/src/FeedIo/RuleAbstract.php @@ -51,6 +51,21 @@ public function getAttributeValue(\DOMElement $element, $name) return; } + /** + * @param \DOMElement $element + * @param string $name + * @return string|null + */ + public function getChildValue(\DOMElement $element, $name) + { + $list = $element->getElementsByTagName($name); + if ( $list->length > 0 ) { + return $list->item(0)->nodeValue; + } + + return; + } + /** * Sets the accurate $item property according to the DomElement content * diff --git a/tests/FeedIo/Rule/Atom/AuthorTest.php b/tests/FeedIo/Rule/Atom/AuthorTest.php index bacc1dd9..a6b438ad 100644 --- a/tests/FeedIo/Rule/Atom/AuthorTest.php +++ b/tests/FeedIo/Rule/Atom/AuthorTest.php @@ -32,9 +32,10 @@ public function testSet() $document = new \DOMDocument(); $author = $document->createElement('author'); - $author->setAttribute('name', 'John Doe'); - $author->setAttribute('uri', 'http://localhost'); - $author->setAttribute('email', 'john@localhost'); + + $author->appendChild($document->createElement('name', 'John Doe')); + $author->appendChild($document->createElement('uri', 'http://localhost')); + $author->appendChild($document->createElement('email', 'john@localhost')); $this->object->setProperty($item, $author); $this->assertEquals('John Doe', $item->getAuthor()->getName()); @@ -42,6 +43,16 @@ public function testSet() $this->assertEquals('john@localhost', $item->getAuthor()->getEmail()); } + public function testGetChildValue() + { + $document = new \DOMDocument(); + + $author = $document->createElement('author'); + $author->appendChild($document->createElement('name', 'John Doe')); + + $this->assertEquals('John Doe', $this->object->getChildValue($author, 'name')); + } + public function testCreateElement() { $item = new Item(); @@ -51,11 +62,14 @@ public function testCreateElement() $author->setEmail('john@localhost'); $item->setAuthor($author); - $element = $this->object->createElement(new \DOMDocument(), $item); + $document = new \DOMDocument(); + $element = $this->object->createElement($document, $item); + $document->appendChild($element); $this->assertInstanceOf('\DomElement', $element); $this->assertEquals('author', $element->nodeName); - $this->assertEquals('John Doe', $element->getAttribute('name')); - $this->assertEquals('http://localhost', $element->getAttribute('uri')); - $this->assertEquals('john@localhost', $element->getAttribute('email')); + + $this->assertXmlStringEqualsXmlString( + 'John Doehttp://localhostjohn@localhost', + $document->saveXML()); } }