Don't import files if they don't have the supportted format extension,
[catagits/App-IdiotBox.git] / t / importer / video_files_from_dir.t
1 use strict;
2 use warnings FATAL => 'all';
3 use autodie;
4
5 use Test::More;
6
7 use Cwd qw(getcwd);
8 use File::Temp qw(tempdir);
9
10 # Chdir to test directory for laziness
11 my $original_dir = getcwd;
12 END {
13         chdir $original_dir;
14 }
15
16 my $temp_dir = tempdir(CLEANUP => 1);
17 chdir($temp_dir);
18
19 use App::IdiotBox::Importer;
20
21 my $method = 'video_files_from_dir';
22
23 # No videos
24 my $videos = App::IdiotBox::Importer->$method($temp_dir);
25 is_deeply($videos, {}, 'No files reported from empty directory');
26
27 # Unknown extensions
28 open(undef, '>', 'fake.mp3');
29 open(undef, '>', 'fake2.aac');
30
31 $videos = App::IdiotBox::Importer->$method($temp_dir);
32 is_deeply($videos, {}, 'No files reported from empty directory');
33
34 # Known file types
35 open(undef, '>', 'good.m4v');
36 open(undef, '>', 'good2.flv');
37
38 my $expect = {
39         'good'  => [ 'm4v' ],
40         'good2' => [ 'flv' ],
41 };
42
43 $videos = App::IdiotBox::Importer->$method($temp_dir);
44 is_deeply($videos, $expect, 'Known filetypes detected');
45
46 # Grouping by file name without extension
47 open(undef, '>', 'good.flv');
48
49 unshift @{ $expect->{good} }, 'flv';
50
51 $videos = App::IdiotBox::Importer->$method($temp_dir);
52 is_deeply($videos, $expect, 'Known filetypes detected');
53
54 done_testing;