Skip to content

Commit

Permalink
Allow overriding of basic properties which an RSS_File_Item will infe…
Browse files Browse the repository at this point in the history
…r if not set.

This allows us to construct the test cases hierarchically as well.
  • Loading branch information
ben-xo committed Feb 11, 2021
1 parent a4adf1f commit 6a49c8d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
18 changes: 18 additions & 0 deletions dir2cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,23 @@ protected function stripBasePath($filename)
*/
public function getTitle()
{
$overridden_title = parent::getTitle();
if($overridden_title)
{
return $overridden_title;
}

return basename($this->getFilename());
}

public function getType()
{
$overridden_type = parent::getType();
if($overridden_type)
{
return $overridden_type;
}

return 'application/octet-stream';
}

Expand Down Expand Up @@ -683,6 +695,12 @@ protected function getImageFilename($type) {
*/
public function getImage()
{
$overridden_image = parent::getImage();
if($overridden_image)
{
return $overridden_image;
}

$image_file_name = $this->getImageFilename('png');
if(file_exists( $image_file_name ))
return $this->filenameToUrl($image_file_name);
Expand Down
23 changes: 23 additions & 0 deletions test/RSS_File_ItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class RSS_File_ItemTest extends RSS_ItemTest
{
public static function setUpBeforeClass(): void
{
define('MP3_URL', 'http://www.example.com/mp3/');
define('MP3_DIR', getcwd());
}

public function newRSSItem()
{
return new RSS_File_Item('example.mp3');
}

public function getDefaultTitle()
{
return 'example.mp3';
}

}
19 changes: 12 additions & 7 deletions test/RSS_ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

use PHPUnit\Framework\TestCase;

final class RSS_ItemTest extends TestCase
class RSS_ItemTest extends TestCase
{
public function newRSSItem()
{
return new RSS_Item();
}

public static function setUpBeforeClass(): void
public function getDefaultTitle()
{
return '(untitled)';
}

public function test_rss_item_added_to_podcast_channel()
{
$mp = new MyPodcast();

$item = new RSS_Item();
$item = $this->newRSSItem();
$item->setTitle('item title');
$item->setLink('link.mp3');
$item->setPubDate('today');
Expand Down Expand Up @@ -56,7 +61,7 @@ public function test_html_description_with_DESCRIPTION_HTML_set()
define('DESCRIPTION_HTML', true);
$mp = new MyPodcast();

$item = new RSS_Item();
$item = $this->newRSSItem();
$item->setDescription("<h1>test</h1>");
$mp->addRssItem($item);

Expand All @@ -73,19 +78,19 @@ public function test_html_description_with_DESCRIPTION_HTML_set()
public function test_rss_item_default_title()
{
$mp = new MyPodcast();
$item = new RSS_Item();
$item = $this->newRSSItem();
$mp->addRssItem($item);

$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);

$this->assertEquals('(untitled)', $data->channel->item[0]->title);
$this->assertEquals($this->getDefaultTitle(), $data->channel->item[0]->title);
}

public function test_adds_image_to_item_if_set()
{
$mp = new MyPodcast();
$item = new RSS_Item();
$item = $this->newRSSItem();
$item->setImage('visuals.jpg');
$mp->addRssItem($item);

Expand Down

0 comments on commit 6a49c8d

Please sign in to comment.