Skip to content

Commit

Permalink
Fix #131
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdebril committed Aug 2, 2017
1 parent 9c7d7d9 commit a63de6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/FeedIo/Rule/Atom/LinkNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace FeedIo\Rule\Atom;

use FeedIo\Feed\ItemInterface;
use FeedIo\Feed\NodeInterface;
use FeedIo\RuleAbstract;
use FeedIo\RuleSet;
use FeedIo\Rule\Media;

class LinkNode extends RuleAbstract
{
Expand All @@ -33,7 +33,7 @@ public function __construct($nodeName = null)
$mediaRule = new Media();
$mediaRule->setUrlAttributeName('href');
$this->ruleSet = new RuleSet(new Link('related'));
$this->ruleSet->add($mediaRule);
$this->ruleSet->add($mediaRule, ['media', 'enclosure']);
}

/**
Expand Down Expand Up @@ -61,6 +61,14 @@ public function setProperty(NodeInterface $node, \DOMElement $element)
*/
public function createElement(\DomDocument $document, NodeInterface $node)
{
return $this->ruleSet->getDefault()->createElement($document, $node);
$output = new \ArrayIterator();
if ($node instanceof ItemInterface) {
foreach ($node->getMedias() as $media) {
$output->append($this->ruleSet->get('media')->createElement($document, $node));
}
}
$output->append($this->ruleSet->getDefault()->createElement($document, $node));

return $output;
}
}
15 changes: 11 additions & 4 deletions tests/FeedIo/Rule/Atom/LinkNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public function testCreateElement()
$item = new Item();
$item->setLink(self::LINK);

$element = $this->object->createElement(new \DOMDocument(), $item);
$this->assertInstanceOf('\DomElement', $element);
$this->assertEquals(self::LINK, $element->getAttribute('href'));
$this->assertEquals('link', $element->nodeName);
$elements = $this->object->createElement(new \DOMDocument(), $item);

$count = 0;
foreach ($elements as $element) {
$count++;
$this->assertInstanceOf('\DomElement', $element);
$this->assertEquals(self::LINK, $element->getAttribute('href'));
$this->assertEquals('link', $element->nodeName);
}

$this->assertEquals(1, $count);
}
}

0 comments on commit a63de6e

Please sign in to comment.