aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--actions/DisplayAction.php19
-rw-r--r--lib/FeedItem.php9
-rw-r--r--lib/FeedParser.php3
-rw-r--r--tests/FeedParserTest.php19
5 files changed, 39 insertions, 20 deletions
diff --git a/README.md b/README.md
index 6124a4ea..982cd63b 100644
--- a/README.md
+++ b/README.md
@@ -418,7 +418,16 @@ See `formats/PlaintextFormat.php` for an example.
These commands require that you have installed the dev dependencies in `composer.json`.
+Run all tests:
+
./vendor/bin/phpunit
+
+Run a single test class:
+
+ ./vendor/bin/phpunit --filter UrlTest
+
+Run linter:
+
./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./
https://github.com/squizlabs/PHP_CodeSniffer/wiki
diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php
index 93813004..54782edc 100644
--- a/actions/DisplayAction.php
+++ b/actions/DisplayAction.php
@@ -112,15 +112,6 @@ class DisplayAction implements ActionInterface
$input = array_diff_key($requestArray, array_fill_keys($remove, ''));
$bridge->setInput($input);
$bridge->collectData();
- $items = $bridge->getItems();
- if (isset($items[0]) && is_array($items[0])) {
- $feedItems = [];
- foreach ($items as $item) {
- $feedItems[] = FeedItem::fromArray($item);
- }
- $items = $feedItems;
- }
- $feed = $bridge->getFeed();
} catch (\Exception $e) {
// Probably an exception inside a bridge
if ($e instanceof HttpException) {
@@ -154,6 +145,16 @@ class DisplayAction implements ActionInterface
}
}
+ $items = $bridge->getItems();
+ if (isset($items[0]) && is_array($items[0])) {
+ $feedItems = [];
+ foreach ($items as $item) {
+ $feedItems[] = FeedItem::fromArray($item);
+ }
+ $items = $feedItems;
+ }
+ $feed = $bridge->getFeed();
+
$formatFactory = new FormatFactory();
$format = $formatFactory->create($format);
diff --git a/lib/FeedItem.php b/lib/FeedItem.php
index fc4549a7..dfb954a0 100644
--- a/lib/FeedItem.php
+++ b/lib/FeedItem.php
@@ -186,21 +186,26 @@ class FeedItem
}
/**
- * @param string|object $content The item content as text or simple_html_dom object.
+ * @param string|array|\simple_html_dom|\simple_html_dom_node $content The item content
*/
public function setContent($content)
{
$this->content = null;
+
if (
$content instanceof simple_html_dom
|| $content instanceof simple_html_dom_node
) {
$content = (string) $content;
+ } elseif (is_array($content)) {
+ // Assuming this is the rss2.0 content module
+ $content = $content['encoded'] ?? '';
}
+
if (is_string($content)) {
$this->content = $content;
} else {
- Debug::log(sprintf('Feed content must be a string but got %s', gettype($content)));
+ Debug::log(sprintf('Unable to convert feed content to string: %s', gettype($content)));
}
}
diff --git a/lib/FeedParser.php b/lib/FeedParser.php
index b774cc14..3a2f15d4 100644
--- a/lib/FeedParser.php
+++ b/lib/FeedParser.php
@@ -167,8 +167,9 @@ final class FeedParser
if (isset($namespaces['media'])) {
$media = $feedItem->children($namespaces['media']);
}
+
foreach ($namespaces as $namespaceName => $namespaceUrl) {
- if (in_array($namespaceName, ['', 'content', 'media'])) {
+ if (in_array($namespaceName, ['', 'media'])) {
continue;
}
$item[$namespaceName] = $this->parseModule($feedItem, $namespaceName, $namespaceUrl);
diff --git a/tests/FeedParserTest.php b/tests/FeedParserTest.php
index 05d5ef69..45dc1234 100644
--- a/tests/FeedParserTest.php
+++ b/tests/FeedParserTest.php
@@ -8,6 +8,13 @@ use PHPUnit\Framework\TestCase;
class FeedParserTest extends TestCase
{
+ private \FeedParser $sut;
+
+ public function setUp(): void
+ {
+ $this->sut = new \FeedParser();
+ }
+
public function testRss1()
{
$xml = <<<XML
@@ -37,8 +44,7 @@ class FeedParserTest extends TestCase
</rdf:RDF>
XML;
- $sut = new \FeedParser();
- $feed = $sut->parseFeed($xml);
+ $feed = $this->sut->parseFeed($xml);
$this->assertSame('hello feed', $feed['title']);
$this->assertSame('http://meerkat.oreillynet.com', $feed['uri']);
@@ -74,8 +80,7 @@ class FeedParserTest extends TestCase
</rss>
XML;
- $sut = new \FeedParser();
- $feed = $sut->parseFeed($xml);
+ $feed = $this->sut->parseFeed($xml);
$this->assertSame('hello feed', $feed['title']);
$this->assertSame('https://example.com/', $feed['uri']);
@@ -111,8 +116,7 @@ class FeedParserTest extends TestCase
</feed>
XML;
- $sut = new \FeedParser();
- $feed = $sut->parseFeed($xml);
+ $feed = $this->sut->parseFeed($xml);
$this->assertSame('hello feed', $feed['title']);
$this->assertSame('https://example.com/1', $feed['uri']);
@@ -151,8 +155,7 @@ class FeedParserTest extends TestCase
</rss>
XML;
- $sut = new \FeedParser();
- $feed = $sut->parseFeed($xml);
+ $feed = $this->sut->parseFeed($xml);
$expected = [
'title' => '',
'uri' => '',