From 9218edaa218bdd4726ccfbf5654ee8bc9b9b5dd8 Mon Sep 17 00:00:00 2001 From: Ben Isaacs Date: Sat, 13 Feb 2021 14:59:43 +0000 Subject: [PATCH] Add more tests for file/tag based Media RSS Items --- test/Media_RSS_ItemTest.php | 60 ++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/test/Media_RSS_ItemTest.php b/test/Media_RSS_ItemTest.php index cdaf5ea..fe8e988 100644 --- a/test/Media_RSS_ItemTest.php +++ b/test/Media_RSS_ItemTest.php @@ -4,7 +4,7 @@ class Media_RSS_ItemTest extends RSS_File_ItemTest { - private $mtime; + protected $mtime; public static function setUpBeforeClass(): void { @@ -13,25 +13,77 @@ public static function setUpBeforeClass(): void defined('DESCRIPTION_SOURCE') || define('DESCRIPTION_SOURCE', 'comment'); } + public function getMediaFileContent() + { + return 'x'; + } + + public function getMediaFileLength() + { + return 1; + } + + // ID3 / tag data is typically set by getID3_Podcast_Helper, which is not under test here. + + public function getID3Artist() + { + return ''; + } + + public function getID3Album() + { + return ''; + } + + public function getID3Title() + { + return ''; + } + + public function getID3Comment() + { + return ''; + } + public function newRSSItem() { // default tests are conducted with an empty file (which, therefore, has no ID3 tags to read) - file_put_contents('example.mp3', 'x'); + file_put_contents('example.mp3', $this->getMediaFileContent()); // ensure that tests do not fail when getting unlucky with when the clock ticks. $this->mtime = time(); touch('example.mp3', $this->mtime); - return new Media_RSS_Item('example.mp3'); + $item = new Media_RSS_Item('example.mp3'); + $item->setID3Album($this->getID3Album()); + $item->setID3Title($this->getID3Title()); + $item->setID3Artist($this->getID3Artist()); + $item->setID3Comment($this->getID3Comment()); + return $item; } public function test_constructor_sets_default_properties_from_file_metadata() { $item = $this->newRSSItem(); - $this->assertEquals('1', $item->getLength()); + $this->assertEquals($this->getMediaFileLength(), $item->getLength()); $this->assertEquals(date('r', $this->mtime), $item->getPubDate()); } + public function test_description_from_comment_tag() + { + $item = $this->newRSSItem(); + $this->assertEquals($this->getID3Comment(), $item->getDescription()); + } + + /** + * For Media RSS files, the default summary is ID3 the description, which is in turn the ID3 comment + * @override + */ + public function test_summary_default() { + $item = $this->newRSSItem(); + $this->assertEquals($this->getID3Comment(), $item->getSummary()); + } + public function tearDown(): void { file_exists('example.mp3') && unlink('example.mp3');