Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'test/feed-entry-type-detection' of https://github.com/f…
Browse files Browse the repository at this point in the history
…ritz-gerneth/zf2 into feature/feed-autodetect
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Reader/Entry/AbstractEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ public function __construct(DOMElement $entry, $entryKey, $type = null)
$this->_domDocument = $entry->ownerDocument;
if ($type !== null) {
$this->_data['type'] = $type;
} else if ($this->_domDocument !== null) {
$this->_data['type'] = Reader\Reader::detectType($this->_domDocument);
} else {
$this->_data['type'] = Reader\Reader::detectType($feed);
$this->_data['type'] = Reader\Reader::TYPE_ANY;
}
$this->_loadExtensions();
}
Expand Down
33 changes: 32 additions & 1 deletion test/Reader/Entry/CommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,36 @@ public function testReturnsEncodingOfFeedAsUtf8IfUndefined()
$this->assertEquals('UTF-8', $entry->getEncoding());
}


/**
* When not passing the optional argument type
*/
public function testFeedEntryCanDetectFeedType()
{
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath.'/atom.xml')
);
$entry = $feed->current();
$stub = $this->getMockForAbstractClass(
'Zend\Feed\Reader\Entry\AbstractEntry',
array($entry->getElement(), $entry->getId())
);
$this->assertEquals($entry->getType(), $stub->getType());
}

/**
* When passing a newly created DOMElement without any DOMDocument assigned
*/
public function testFeedEntryCanSetAnyType()
{
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath.'/atom.xml')
);
$entry = $feed->current();
$domElement = new \DOMElement($entry->getElement()->tagName);
$stub = $this->getMockForAbstractClass(
'Zend\Feed\Reader\Entry\AbstractEntry',
array($domElement, $entry->getId())
);
$this->assertEquals($stub->getType(), Reader\Reader::TYPE_ANY);
}
}

0 comments on commit 508b344

Please sign in to comment.