29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-07-03 02:23:53 +00:00

[4.2 RC1] Feed display module not working (#38312)

This commit is contained in:
conseilgouz 2022-08-19 14:22:12 +02:00 committed by GitHub
parent 6fde173e78
commit aa1f62a006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 11 deletions

View File

@ -190,10 +190,9 @@ class AtomParser extends FeedParser
*/
protected function initialise()
{
// We want to move forward to the first XML Element after the xml doc type declaration
$this->moveToNextElement();
// We are on the first XML Element after the xml doc type declaration
$this->version = ($this->stream->getAttribute('version') == '0.3') ? '0.3' : '1.0';
$this->moveToNextElement();
}
/**

View File

@ -347,10 +347,7 @@ class RssParser extends FeedParser
*/
protected function initialise()
{
// We want to move forward to the first XML Element after the xml doc type declaration
$this->moveToNextElement();
// Read the version attribute.
// We are on the first XML Element after the xml doc type declaration
$this->version = $this->stream->getAttribute('version');
// We want to move forward to the first element after the <channel> element.

View File

@ -351,9 +351,26 @@ class AtomParserTest extends UnitTestCase
*/
public function testInitialiseSetsDefaultVersion()
{
$dummyXml = '<feed xmlns="http://www.w3.org/2005/Atom" />';
$dummyXml = '<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! Unit Test" -->
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Joomla! Unit test</title>
</feed>';
$reader = \XMLReader::XML($dummyXml);
$atomParser = new AtomParser($reader);
// same logic as FeedFactory.php : skip head record
try {
// Skip ahead to the root node.
while ($reader->read()) {
if ($reader->nodeType == \XMLReader::ELEMENT) {
break;
}
}
} catch (\Exception $e) {
throw new \RuntimeException('Error reading feed.', $e->getCode(), $e);
}
$atomParser->parse();
// Use reflection to check the value
@ -373,9 +390,26 @@ class AtomParserTest extends UnitTestCase
*/
public function testInitialiseSetsOldVersion()
{
$dummyXml = '<feed version="0.3" xmlns="http://www.w3.org/2005/Atom" />';
$dummyXml = '<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! Unit Test" -->
<feed version="0.3" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Joomla! Unit test</title>
</feed>';
$reader = \XMLReader::XML($dummyXml);
$atomParser = new AtomParser($reader);
// same logic as FeedFactory.php : skip head record
try {
// Skip ahead to the root node.
while ($reader->read()) {
if ($reader->nodeType == \XMLReader::ELEMENT) {
break;
}
}
} catch (\Exception $e) {
throw new \RuntimeException('Error reading feed.', $e->getCode(), $e);
}
$atomParser->parse();
// Use reflection to check the value

View File

@ -582,7 +582,8 @@ class RssParserTest extends UnitTestCase
*/
public function testParseSetsVersion()
{
$dummyXml = '<?xml version="1.0" encoding="utf-8" ?>
$dummyXml = '<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! Unit Test" -->
<rss version="2.0">
<channel>
<title>Test Channel</title>
@ -590,13 +591,26 @@ class RssParserTest extends UnitTestCase
</rss>';
$reader = \XMLReader::XML($dummyXml);
$rssParser = new RssParser($reader);
// same logic as FeedFactory.php : skip head record
try {
// Skip ahead to the root node.
while ($reader->read()) {
if ($reader->nodeType == \XMLReader::ELEMENT) {
break;
}
}
} catch (\Exception $e) {
throw new \RuntimeException('Error reading feed.', $e->getCode(), $e);
}
$rssParser->parse();
// Use reflection to check the value
$reflectionClass = new ReflectionClass($rssParser);
$attribute = $reflectionClass->getProperty('version');
$attribute->setAccessible(true);
$attribute->setAccessible(true);
$this->assertEquals('2.0', $attribute->getValue($rssParser));
}