Skip to content

Commit

Permalink
Add more tests for file/tag based Media RSS Items
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Feb 13, 2021
1 parent 6e327c2 commit 9218eda
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions test/Media_RSS_ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Media_RSS_ItemTest extends RSS_File_ItemTest
{
private $mtime;
protected $mtime;

public static function setUpBeforeClass(): void
{
Expand All @@ -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');
Expand Down

0 comments on commit 9218eda

Please sign in to comment.