Loading src/Feeds/Parser/SyndicationParser.php +5 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ class SyndicationParser extends ParserBase implements ParserInterface { if ($media_content = $entry->getMediaContent()) { $item->set('mediarss_content', $media_content['url']); $item->set('mediarss_description', $media_content['description']); } if ($media_thumbnail = $entry->getMediaThumbnail()) { Loading Loading @@ -190,6 +191,10 @@ class SyndicationParser extends ParserBase implements ParserInterface { 'label' => $this->t('Media content'), 'description' => $this->t('Available if the feed supports the Media RSS specification. Can contain audio, video or other media.'), ], 'mediarss_description' => [ 'label' => $this->t('Media description'), 'description' => $this->t('Available if the feed supports the Media RSS specification. Text that describes the media object.'), ], 'mediarss_thumbnail' => [ 'label' => $this->t('Media thumbnail'), 'description' => $this->t('Available if the feed supports the Media RSS specification. An image that is representative for the media object.'), Loading src/Laminas/Extension/Mediarss/Entry.php +6 −0 Original line number Diff line number Diff line Loading @@ -48,7 +48,13 @@ class Entry extends AbstractEntry { 'url' => $media->getAttribute('url'), 'width' => $media->getAttribute('width'), 'height' => $media->getAttribute('height'), 'description' => '', ]; $media_description = $this->getMediaElement('description'); if (!empty($media_description) && is_object($media_description)) { $this->data[$media_key]['description'] = $media_description->textContent; } } return $this->data[$media_key]; Loading tests/resources/rss/media-rss.rss2 +17 −0 Original line number Diff line number Diff line Loading @@ -38,5 +38,22 @@ <guid isPermaLink="true">https://www.example.com/thumbnail-only</guid> <media:thumbnail url="https://www.example.com/thumbnail3.png" width="80" height="53" /> </item> <item> <title>Media content and description</title> <link>https://www.example.com/media-content-description</link> <description></description> <pubDate>Sun, 21 Apr 2019 19:48:50 +0200</pubDate> <guid isPermaLink="true">https://www.example.com/media-content-description</guid> <media:content url="https://www.example.com/image3.png" medium="image" width="640" height="424" /> <media:description>Example media description</media:description> </item> <item> <title>Media description only</title> <link>https://www.example.com/media-content-description-only</link> <description></description> <pubDate>Sun, 21 Apr 2019 19:48:50 +0200</pubDate> <guid isPermaLink="true">https://www.example.com/media-content-description-only</guid> <media:description>Example media description</media:description> </item> </channel> </rss> No newline at end of file tests/src/Unit/Feeds/Parser/SyndicationParserTest.php +7 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\feeds\Feeds\Parser\SyndicationParser; use Drupal\feeds\Result\RawFetcherResult; use Drupal\feeds\State; use Drupal\Tests\feeds\Unit\FeedsUnitTestCase; use RuntimeException; use Laminas\Feed\Reader\StandaloneExtensionManager; /** Loading Loading @@ -127,19 +126,24 @@ class SyndicationParserTest extends FeedsUnitTestCase { $fetcher_result = new RawFetcherResult(file_get_contents($file), $this->getMockFileSystem()); $result = $this->parser->parse($this->feed, $fetcher_result, $this->state); $this->assertSame(count($result), 4); $this->assertSame(count($result), 6); $expected = [ 1 => [ 'mediarss_content' => 'https://www.example.com/image1.png', 'mediarss_description' => '', 'mediarss_thumbnail' => 'https://www.example.com/thumbnail1.png', ], 2 => [ 'mediarss_content' => 'https://www.example.com/image2.png', 'mediarss_description' => '', ], 3 => [ 'mediarss_thumbnail' => 'https://www.example.com/thumbnail3.png', ], 4 => [ 'mediarss_description' => 'Example media description', ], ]; foreach ($expected as $index => $expected_values) { foreach ($expected_values as $key => $value) { Loading Loading @@ -177,7 +181,7 @@ class SyndicationParserTest extends FeedsUnitTestCase { public function testInvalidFeed() { $fetcher_result = new RawFetcherResult('beep boop', $this->getMockFileSystem()); $this->expectException(RuntimeException::class); $this->expectException(\RuntimeException::class); $result = $this->parser->parse($this->feed, $fetcher_result, $this->state); } Loading Loading
src/Feeds/Parser/SyndicationParser.php +5 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ class SyndicationParser extends ParserBase implements ParserInterface { if ($media_content = $entry->getMediaContent()) { $item->set('mediarss_content', $media_content['url']); $item->set('mediarss_description', $media_content['description']); } if ($media_thumbnail = $entry->getMediaThumbnail()) { Loading Loading @@ -190,6 +191,10 @@ class SyndicationParser extends ParserBase implements ParserInterface { 'label' => $this->t('Media content'), 'description' => $this->t('Available if the feed supports the Media RSS specification. Can contain audio, video or other media.'), ], 'mediarss_description' => [ 'label' => $this->t('Media description'), 'description' => $this->t('Available if the feed supports the Media RSS specification. Text that describes the media object.'), ], 'mediarss_thumbnail' => [ 'label' => $this->t('Media thumbnail'), 'description' => $this->t('Available if the feed supports the Media RSS specification. An image that is representative for the media object.'), Loading
src/Laminas/Extension/Mediarss/Entry.php +6 −0 Original line number Diff line number Diff line Loading @@ -48,7 +48,13 @@ class Entry extends AbstractEntry { 'url' => $media->getAttribute('url'), 'width' => $media->getAttribute('width'), 'height' => $media->getAttribute('height'), 'description' => '', ]; $media_description = $this->getMediaElement('description'); if (!empty($media_description) && is_object($media_description)) { $this->data[$media_key]['description'] = $media_description->textContent; } } return $this->data[$media_key]; Loading
tests/resources/rss/media-rss.rss2 +17 −0 Original line number Diff line number Diff line Loading @@ -38,5 +38,22 @@ <guid isPermaLink="true">https://www.example.com/thumbnail-only</guid> <media:thumbnail url="https://www.example.com/thumbnail3.png" width="80" height="53" /> </item> <item> <title>Media content and description</title> <link>https://www.example.com/media-content-description</link> <description></description> <pubDate>Sun, 21 Apr 2019 19:48:50 +0200</pubDate> <guid isPermaLink="true">https://www.example.com/media-content-description</guid> <media:content url="https://www.example.com/image3.png" medium="image" width="640" height="424" /> <media:description>Example media description</media:description> </item> <item> <title>Media description only</title> <link>https://www.example.com/media-content-description-only</link> <description></description> <pubDate>Sun, 21 Apr 2019 19:48:50 +0200</pubDate> <guid isPermaLink="true">https://www.example.com/media-content-description-only</guid> <media:description>Example media description</media:description> </item> </channel> </rss> No newline at end of file
tests/src/Unit/Feeds/Parser/SyndicationParserTest.php +7 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\feeds\Feeds\Parser\SyndicationParser; use Drupal\feeds\Result\RawFetcherResult; use Drupal\feeds\State; use Drupal\Tests\feeds\Unit\FeedsUnitTestCase; use RuntimeException; use Laminas\Feed\Reader\StandaloneExtensionManager; /** Loading Loading @@ -127,19 +126,24 @@ class SyndicationParserTest extends FeedsUnitTestCase { $fetcher_result = new RawFetcherResult(file_get_contents($file), $this->getMockFileSystem()); $result = $this->parser->parse($this->feed, $fetcher_result, $this->state); $this->assertSame(count($result), 4); $this->assertSame(count($result), 6); $expected = [ 1 => [ 'mediarss_content' => 'https://www.example.com/image1.png', 'mediarss_description' => '', 'mediarss_thumbnail' => 'https://www.example.com/thumbnail1.png', ], 2 => [ 'mediarss_content' => 'https://www.example.com/image2.png', 'mediarss_description' => '', ], 3 => [ 'mediarss_thumbnail' => 'https://www.example.com/thumbnail3.png', ], 4 => [ 'mediarss_description' => 'Example media description', ], ]; foreach ($expected as $index => $expected_values) { foreach ($expected_values as $key => $value) { Loading Loading @@ -177,7 +181,7 @@ class SyndicationParserTest extends FeedsUnitTestCase { public function testInvalidFeed() { $fetcher_result = new RawFetcherResult('beep boop', $this->getMockFileSystem()); $this->expectException(RuntimeException::class); $this->expectException(\RuntimeException::class); $result = $this->parser->parse($this->feed, $fetcher_result, $this->state); } Loading