Skip to content

Commit

Permalink
Add saveImage() basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Feb 14, 2021
1 parent 2be4a8e commit 4dcd121
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/RSS_File_ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static function setUpBeforeClass(): void
}

protected $filename;
protected $filename_base;
protected $default_title_from_file;

public function newRSSItem()
Expand All @@ -32,6 +33,7 @@ public function setUp(): void
{
// most common case for tests in this file.
$this->filename = 'example.mp3';
$this->filename_base = 'example';
$this->default_title_from_file = 'example.mp3';
parent::setUp();
}
Expand Down Expand Up @@ -213,6 +215,35 @@ public function test_subtitle_from_filesystem_dot_only() {
unlink('example_subtitle.txt');
}

public function test_saveImage_jpg()
{
$item = $this->newRSSItem();
$expected_image_filename = $this->filename_base . '.jpg';
$this->assertFalse(file_exists($expected_image_filename));
$item->saveImage('image/jpeg', 'JFIF content');
$this->assertTrue(file_exists($expected_image_filename));
$this->assertEquals('JFIF content', file_get_contents($expected_image_filename));
}

public function test_saveImage_png()
{
$item = $this->newRSSItem();
$expected_image_filename = $this->filename_base . '.png';
$this->assertFalse(file_exists($expected_image_filename));
$item->saveImage('image/png', 'PNG content');
$this->assertTrue(file_exists($expected_image_filename));
$this->assertEquals('PNG content', file_get_contents($expected_image_filename));
}

public function test_saveImage_anything_else()
{
$item = $this->newRSSItem();
$file_count_before = count(glob($this->filename_base . '*'));
$item->saveImage('application/octet-stream', 'random data');
$file_count_after = count(glob($this->filename_base . '*'));
$this->assertEquals($file_count_before, $file_count_after);
}

public function tearDown(): void
{
file_exists('example.jpg') && unlink('example.jpg');
Expand Down

0 comments on commit 4dcd121

Please sign in to comment.