App-MaMGal

 view release on metacpan or  search on metacpan

t/080_unit_picture.t  view on Meta::CPAN

	$self->{mock_image_info_factory}->mock('read', sub { die "oh my\n"; });
	$self->{entry}->logger->clear;
	my $val = $self->{entry}->image_info;
	logged_only_ok($self->{entry}->logger, qr{^Cannot retrieve image info: oh my$}, 'td/c.jpg'); # crash instantiating an object results in a warning
	is($val, undef, 'crash instantiating an object results in undef returned');
	$self->{mock_image_info_factory}->called_ok('read');
	$self->{mock_image_info_factory}->clear;
	$self->{entry}->logger->clear;
	$val = $self->{entry}->image_info;
	is($self->{entry}->logger->next_call, undef, 'no warnings are produced on second image_info call');
	is($val, undef, 'after one crash, undef is returned by image_info always');
	ok(! $self->{mock_image_info_factory}->called('read'), 'read is not called after it crashed once');
}

sub description_method : Test {
	my $self = shift;
	$self->{mock_image_info}->mock('description', sub { 'some text' });
	is($self->{entry}->description, 'some text');
}

sub description_method_undefined : Test {
	my $self = shift;
	$self->{mock_image_info}->mock('description', sub { undef });
	is($self->{entry}->description, undef);
}

sub description_method_crash : Test(5) {
	my $self = shift;
	$self->{mock_image_info_factory}->mock('read', sub { die "oh noes!\n" });
	my $d;
	$self->{entry}->logger->clear;
	$d = $self->{entry}->description;
	logged_only_ok($self->{entry}->logger, qr{^Cannot retrieve image info: oh noes!$}, 'td/c.jpg'); # crash when getting a description produces a warning
	is($d, undef, 'description is undefined');
}

sub thumbnail_path_method : Test(2) {
	my $self = shift;
	my $class_name = $self->{class_name};
	my @test_file_name = $self->file_name;
	{
		my $e = $self->{entry};
		is($e->thumbnail_path, '.mamgal-thumbnails/'.$test_file_name[1], "$class_name thumbnail_path is correct");
	}
	{
		my $e = $self->{entry_no_stat};
		is($e->thumbnail_path, '.mamgal-thumbnails/'.$test_file_name[1], "$class_name thumbnail_path is correct");
	}
}

sub stat_functionality : Test(1) {
	my $self = shift;
	$self->{mock_image_info}->mock('creation_time', sub { 1234567890 });
	is($self->{entry}->creation_time, 1234567890, 'if image info object returns a defined time, that time is returned');
}

sub stat_functionality_undefined : Test(2) {
	my $self = shift;
	$self->{mock_image_info}->mock('creation_time', sub { undef });
	# if image info object returns undef, we turn to the stat data supplied on creation
	$self->SUPER::stat_functionality;
}

sub stat_functionality_crashed : Test(6) {
	my $self = shift;
	$self->{mock_image_info_factory}->mock('read', sub { die "oh noes too!\n" });
	# if image info object construction fails, we turn to the stat data supplied on creation
	$self->{entry}->logger->clear;
	$self->SUPER::stat_functionality;
	logged_only_ok($self->{entry}->logger, qr{^Cannot retrieve image info: oh noes too!$}, 'td/c.jpg');
}

sub stat_functionality_when_created_without_stat : Test { ok(1) }

package App::MaMGal::Unit::Entry::Picture::Film;
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Test::Files;
use Test::Warn;
use Test::HTML::Content;
use App::MaMGal::Entry::Picture::Film;
use lib 'testlib';
BEGIN { our @ISA = 'App::MaMGal::Unit::Entry::Picture' }

use App::MaMGal::TestHelper;
use File::stat;

sub class_setting : Test(startup) {
	my $self = shift;
	$self->{class_name} = 'App::MaMGal::Entry::Picture::Film';
	$self->{test_file_name} = [qw(td/one_film m.mov)];
}

sub relative_miniature_path
{
	my $self = shift;
	$self->SUPER::relative_miniature_path(@_).'.png'
}

sub _touch {
	my $self = shift;
	$self->SUPER::_touch(@_, '.png')
}

sub call_refresh_miniatures
{
	my $self = shift;
	$self->SUPER::call_refresh_miniatures(@_, '.png')
}

sub thumbnail_path_method : Test(2) {
	my $self = shift;
	my $class_name = $self->{class_name};
	my @test_file_name = $self->file_name;
	{
		my $e = $self->{entry};
		is($e->thumbnail_path, '.mamgal-thumbnails/'.$test_file_name[1].'.png', "$class_name thumbnail_path is correct");
	}
	{
		my $e = $self->{entry_no_stat};
		is($e->thumbnail_path, '.mamgal-thumbnails/'.$test_file_name[1].'.png', "$class_name thumbnail_path is correct");
	}
}

sub read_image_method_normal : Test(2)
{
	my $self = shift;
	my $class_name = $self->{class_name};
	{
		my $e = $self->{entry};
		is($e->read_image, $self->{tools}->{mplayer_wrapper}->snapshot, 'read_image got correct image');
	}
	{
		my $e = $self->{entry_no_stat};
		is($e->read_image, $self->{tools}->{mplayer_wrapper}->snapshot, 'read_image got correct image');
	}
}

sub read_image_method_no_mplayer : Test(24)
{
	my $self = shift;
	my $class_name = $self->{class_name};
	{
		my $e = $self->{entry};
		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::NotAvailableException');
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;
		$e->{tools}->{mplayer_wrapper}->mock('snapshot', sub { die $ex; } );
		my $i;

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');

		$e->logger->clear;
		$i = $e->read_image;
		logged_exception_only_ok($e->logger, $ex, $e->{path_name});
		ok($i, 'read_image got SOME image');
		isa_ok($i, 'Image::Magick');

	}
	{
		my $e = $self->{entry_no_stat};
		my $ex = Test::MockObject->new;
		$ex->set_isa('App::MaMGal::MplayerWrapper::NotAvailableException');
		$e->{tools}->{mplayer_wrapper} = App::MaMGal::TestHelper->get_mock_mplayer_wrapper;



( run in 1.831 second using v1.01-cache-2.11-cpan-54e63673c56 )