X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fimporter%2Fvideo_files_from_dir.t;fp=t%2Fimporter%2Fvideo_files_from_dir.t;h=45e0f808080ddaf66a6cf92e8214e6ac64be6f7b;hb=625f105e80e46edfcae9732c6591842a87c91e1e;hp=0000000000000000000000000000000000000000;hpb=bb98017328db8e28a5b48d1390fe50e935d119c2;p=catagits%2FApp-IdiotBox.git diff --git a/t/importer/video_files_from_dir.t b/t/importer/video_files_from_dir.t new file mode 100644 index 0000000..45e0f80 --- /dev/null +++ b/t/importer/video_files_from_dir.t @@ -0,0 +1,54 @@ +use strict; +use warnings FATAL => 'all'; +use autodie; + +use Test::More; + +use Cwd qw(getcwd); +use File::Temp qw(tempdir); + +# Chdir to test directory for laziness +my $original_dir = getcwd; +END { + chdir $original_dir; +} + +my $temp_dir = tempdir(CLEANUP => 1); +chdir($temp_dir); + +use App::IdiotBox::Importer; + +my $method = 'video_files_from_dir'; + +# No videos +my $videos = App::IdiotBox::Importer->$method($temp_dir); +is_deeply($videos, {}, 'No files reported from empty directory'); + +# Unknown extensions +open(undef, '>', 'fake.mp3'); +open(undef, '>', 'fake2.aac'); + +$videos = App::IdiotBox::Importer->$method($temp_dir); +is_deeply($videos, {}, 'No files reported from empty directory'); + +# Known file types +open(undef, '>', 'good.m4v'); +open(undef, '>', 'good2.flv'); + +my $expect = { + 'good' => [ 'm4v' ], + 'good2' => [ 'flv' ], +}; + +$videos = App::IdiotBox::Importer->$method($temp_dir); +is_deeply($videos, $expect, 'Known filetypes detected'); + +# Grouping by file name without extension +open(undef, '>', 'good.flv'); + +unshift @{ $expect->{good} }, 'flv'; + +$videos = App::IdiotBox::Importer->$method($temp_dir); +is_deeply($videos, $expect, 'Known filetypes detected'); + +done_testing;