App-MaMGal
view release on metacpan or search on metacpan
t/080_unit_picture.t view on Meta::CPAN
}
sub slide_path
{
my $self = shift;
my $component = shift;
return $self->{test_file_name}->[0].'/'.$self->relative_slide_path($component);
}
sub relative_slide_path
{
my $self = shift;
my $component = shift;
return $component.'/'.$self->{test_file_name}->[1].'.html';
}
sub call_refresh_miniatures
{
my $self = shift;
my $infix = shift;
my $suffix = shift;
my $e = $self->{entry};
$e->refresh_miniatures([$infix, 60, 60, $suffix]);
}
sub call_refresh_slide
{
my $self = shift;
my $e = $self->{entry};
$e->refresh_slide;
}
sub miniature_writing : Test(3) {
my $self = shift;
my $infix = 'test_miniature-'.$self->{class_name};
my $path = $self->miniature_path($infix);
ok(! -f $path, "$path does not exist yet");
my @ret = $self->call_refresh_miniatures($infix);
is($ret[0], $self->relative_miniature_path($infix), "refesh_miniatures call returns the perhaps-refreshed path");
ok(-f $path, "$path exists now");
}
sub slide_writing : Test(6) {
my $self = shift;
my $infix = 'test_slide-'.$self->{class_name};
use App::MaMGal::Entry;
local $App::MaMGal::Entry::slides_dir = $infix;
my $path = $self->slide_path($infix);
ok(! -f $path, "$path does not exist yet");
my @ret = $self->call_refresh_slide();
is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the perhaps-refreshed path");
my ($m, $args) = $self->{mock_container}->next_call;
is($m, 'ensure_subdir_exists', 'subdir existence was ensured');
is($args->[1], $infix, 'correct subdir was requested');
($m, $args) = $self->{mock_container}->next_call;
is($m, '_write_contents_to', 'slide was written');
is($args->[2], $infix.'/'.$self->{test_file_name}->[1].'.html', 'correct slide path was requested');
$self->{mock_container}->clear;
}
sub miniature_not_rewriting : Test(3) {
my $self = shift;
my $file_mtime = $self->{entry}->{stat}->mtime;
my $miniature_mtime = $file_mtime + 60;
my $infix = 'rewriting_miniature-'.$self->{class_name};
$self->_touch($infix, $miniature_mtime);
my $path = $self->miniature_path($infix);
my $stat_before = stat($path) or die "Cannot stat [$path]: $!";
is($stat_before->mtime, $miniature_mtime);
my @ret = $self->call_refresh_miniatures($infix);
is($ret[0], $self->relative_miniature_path($infix), "refesh_miniatures call returns the not-refreshed path");
my $stat_after = stat($path) or die "Cannot stat: $!";
is($stat_after->mtime, $miniature_mtime);
}
sub slide_not_rewriting : Test(3) {
my $self = shift;
my $file_mtime = $self->{entry}->{stat}->mtime;
my $slide_mtime = $file_mtime + 60;
my $infix = 'rewriting_slide-'.$self->{class_name};
$self->_touch($infix, $slide_mtime, '.html');
my $path = $self->slide_path($infix);
my $stat_before = stat($path) or die "Cannot stat [$path]: $!";
is($stat_before->mtime, $slide_mtime);
local $App::MaMGal::Entry::slides_dir = $infix;
my @ret = $self->call_refresh_slide();
is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the not-refreshed path");
my $stat_after = stat($path) or die "Cannot stat: $!";
is($stat_after->mtime, $slide_mtime, 'timestamp did not change after refresh_slide()');
}
sub miniature_refreshing : Test(4) {
my $self = shift;
my $file_mtime = $self->{entry}->{stat}->mtime;
# make the miniature older than the source file
my $miniature_mtime = $file_mtime - 60;
my $infix = 'refreshed_miniature-'.$self->{class_name};
$self->_touch($infix, $miniature_mtime);
my $path = $self->miniature_path($infix);
my $stat_before = stat($path) or die "Cannot stat: $!";
is($stat_before->mtime, $miniature_mtime);
my @ret = $self->call_refresh_miniatures($infix);
is($ret[0], $self->relative_miniature_path($infix), "refesh_miniatures call returns the refreshed path");
my $stat_after = stat($path) or die "Cannot stat: $!";
cmp_ok($stat_after->mtime, '>', $miniature_mtime, 'refreshed miniature mtime is newer than its previous mtime');
cmp_ok($stat_after->mtime, '>', $file_mtime, 'refreshed miniature mtime is newer than its source file\'s mtime');
}
sub slide_refreshing : Test(6) {
my $self = shift;
my $file_mtime = $self->{entry}->{stat}->mtime;
# make the slide older than the source file
my $slide_mtime = $file_mtime - 60;
my $infix = 'refreshed_slide-'.$self->{class_name};
$self->_touch($infix, $slide_mtime, '.html');
my $path = $self->slide_path($infix);
my $stat_before = stat($path) or die "Cannot stat: $!";
is($stat_before->mtime, $slide_mtime);
local $App::MaMGal::Entry::slides_dir = $infix;
my @ret = $self->call_refresh_slide();
is($ret[0], $self->relative_slide_path($infix), "refesh_slide call returns the refreshed path");
my ($m, $args) = $self->{mock_container}->next_call;
is($m, 'ensure_subdir_exists', 'subdir existence was ensured');
is($args->[1], $infix, 'correct subdir was requested');
($m, $args) = $self->{mock_container}->next_call;
is($m, '_write_contents_to', 'slide was written');
is($args->[2], $infix.'/'.$self->{test_file_name}->[1].'.html', 'correct slide path was requested');
$self->{mock_container}->clear;
}
sub page_path_method : Test(2) {
my $self = shift;
my $class_name = $self->{class_name};
my @test_file_name = $self->file_name;
{
my $e = $self->{entry};
( run in 0.880 second using v1.01-cache-2.11-cpan-b16cb0d3907 )