Skip to content

Commit

Permalink
Add unit tests for m4b
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Jul 28, 2022
1 parent 41b0d0b commit c4f23c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/Dir_PodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public function createTestItems()
file_put_contents('test2.mp4', 'content');
file_put_contents('test3.m4a', 'content');
file_put_contents('test4.other', 'content');
file_put_contents('test5.m4b', 'content');

$filemtime = time();
touch('test1.mp3', $filemtime+50);
touch('test2.mp4', $filemtime);
touch('test3.m4a', $filemtime-50);
touch('test4.other', $filemtime-100);
touch('test5.m4b', $filemtime-75);

return $filemtime;
}
Expand All @@ -47,12 +49,14 @@ public function createEmptyTestItems()
file_put_contents('test2.mp4', '');
file_put_contents('test3.m4a', '');
file_put_contents('test4.other', '');
file_put_contents('test5.m4b', '');

$filemtime = time();
touch('test1.mp3', $filemtime+50);
touch('test2.mp4', $filemtime);
touch('test3.m4a', $filemtime-50);
touch('test4.other', $filemtime-100);
touch('test5.m4b', $filemtime-75);

return $filemtime;
}
Expand All @@ -65,7 +69,7 @@ public function test_empty_dir_leads_to_empty_podcast()
$this->assertEquals(0, $mp->getMaxMtime());
}

public function test_three_supported_files_of_zero_length_not_added_to_podcast()
public function test_four_supported_files_of_zero_length_not_added_to_podcast()
{
$filemtime = $this->createEmptyTestItems();

Expand All @@ -75,17 +79,18 @@ public function test_three_supported_files_of_zero_length_not_added_to_podcast()
$this->assertEquals(0, $mp->getMaxMtime());
}

public function test_three_supported_files_added_to_podcast()
public function test_four_supported_files_added_to_podcast()
{
$filemtime = $this->createTestItems();
$mp = $this->newPodcast();
$content = $mp->generate();
$this->assertCount(3, $mp->getItems());
$this->assertCount(4, $mp->getItems());

$items = $mp->getItems();
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($filemtime+50, $mp->getMaxMtime());
}

Expand All @@ -100,12 +105,13 @@ public function test_generating_twice_doesnt_rescan()

$content = $mp->generate(); // generate again

$this->assertCount(3, $mp->getItems());
$this->assertCount(4, $mp->getItems());

$items = $mp->getItems();
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($filemtime+50, $mp->getMaxMtime());
}

Expand All @@ -122,6 +128,7 @@ public function test_regenerates_if_metadata_files_added()
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($filemtime+50 - 200, $mp->getMaxMtime());

unset($mp); // releases locks
Expand All @@ -144,6 +151,7 @@ public function test_regenerates_if_metadata_files_added()
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($now-500, $mp->getMaxMtime());
$this->assertEquals('party123', $items[1]->getSummary());

Expand All @@ -157,10 +165,10 @@ public function test_helpers_added_to_found_items()
$mp = $this->newPodcast();

$helper = $this->createMock(Podcast_Helper::class);
$helper->expects($this->exactly(3))->method('appendToItem');
$helper->expects($this->exactly(4))->method('appendToItem');

$helper2 = $this->createMock(Podcast_Helper::class);
$helper2->expects($this->exactly(3))->method('appendToItem');
$helper2->expects($this->exactly(4))->method('appendToItem');

$mp->addHelper($helper);
$mp->addHelper($helper2);
Expand Down Expand Up @@ -200,6 +208,7 @@ protected function delete_test_files()
file_exists('test3.m4a') && unlink('test3.m4a');
file_exists('test4.other') && unlink('test4.other');
file_exists('test2.txt') && unlink('test2.txt');
file_exists('test5.m4b') && unlink('test5.m4b');
}

public function tearDown(): void
Expand Down
10 changes: 10 additions & 0 deletions test/Dir_Podcast_RecursiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ public function createTestItems()
mkdir('test2');
mkdir('test3');
mkdir('test4');
mkdir('test5');
file_put_contents('test1/test1.mp3', 'content');
file_put_contents('test2/test2.mp4', 'content');
file_put_contents('test3/test3.m4a', 'content');
file_put_contents('test4/test4.other', 'content');
file_put_contents('test5/test5.m4b', 'content');

$filemtime = time();
touch('test1/test1.mp3', $filemtime+50);
touch('test2/test2.mp4', $filemtime);
touch('test3/test3.m4a', $filemtime-50);
touch('test4/test4.other', $filemtime-100);
touch('test5/test5.m4b', $filemtime-75);

return $filemtime;
}
Expand All @@ -42,16 +45,19 @@ public function createEmptyTestItems()
mkdir('test2');
mkdir('test3');
mkdir('test4');
mkdir('test5');
file_put_contents('test1/test1.mp3', '');
file_put_contents('test2/test2.mp4', '');
file_put_contents('test3/test3.m4a', '');
file_put_contents('test4/test4.other', '');
file_put_contents('test5/test5.m4b', '');

$filemtime = time();
touch('test1/test1.mp3', $filemtime+50);
touch('test2/test2.mp4', $filemtime);
touch('test3/test3.m4a', $filemtime-50);
touch('test4/test4.other', $filemtime-100);
touch('test5/test5.m4b', $filemtime-75);

return $filemtime;
}
Expand All @@ -69,10 +75,12 @@ protected function delete_test_files()
file_exists('test2/test2.mp4') && unlink('test2/test2.mp4');
file_exists('test3/test3.m4a') && unlink('test3/test3.m4a');
file_exists('test4/test4.other') && unlink('test4/test4.other');
file_exists('test5/test5.m4b') && unlink('test5/test5.m4b');
is_dir('test1') && rmdir('test1');
is_dir('test2') && rmdir('test2');
is_dir('test3') && rmdir('test3');
is_dir('test4') && rmdir('test4');
is_dir('test5') && rmdir('test5');
parent::delete_test_files();
}

Expand All @@ -89,6 +97,7 @@ public function test_regenerates_if_metadata_files_added()
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($filemtime+50 - 200, $mp->getMaxMtime());

unset($mp); // releases locks
Expand All @@ -111,6 +120,7 @@ public function test_regenerates_if_metadata_files_added()
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
$this->assertEquals($now-500, $mp->getMaxMtime());
$this->assertEquals('party123', $items[1]->getSummary());

Expand Down

0 comments on commit c4f23c1

Please sign in to comment.