view release on metacpan or search on metacpan
lib/App/MaMGal/Entry/Picture/Static.pm
lib/App/MaMGal/Entry/Unreadable.pm
td.in/.mamgal-root
td.in/c.jpg
td.in/root_dir/.mamgal-root
td.in/varying_datetimes.jpg
td.in/without_0x9003.jpg
td.in/without_0x9003_0x9004.jpg
td.in/without_0x9003_0x9004_0x0132.jpg
td.in/one_film/m.mov
td.in/one_pic/a1.png
td.in/empty_file
td.in/more/a.png
td.in/more/b.png
td.in/more/x.png
td.in/more/subdir/p.png
td.in/more/subdir/p2.png
td.in/more/subdir/interesting/b.png
td.in/more/subdir/uninteresting/bar.txt
td.in/p.png
Makefile.PL
MANIFEST
dir.png
video.png
testlib/App/MaMGal/TestHelper.pm
README
BUGS
TODO
classes.dia
mamgal
po/Makefile
po/mamgal.pot
po/pl.po
META.yml Module YAML meta-data (added by MakeMaker)
As a special exception, any files produced by running the program (i.e. the
produced gallery) are instead covered by the following license, even when they
are being made by copying parts of the program itself:
Redistribution and use in any form, with or without modification, are
permitted in any medium. They are offered as-are, without warranty of any
kind.
--------------------------------------------------------------------------------
The directory icon file (dir.png) is Copyright by Susan Kare
It was taken from a file called
icon-themes/Sandy/72x72/filesystems/gnome-fs-directory-accept.png in the
gnome-themes package.
The lib/App/MaMGal/DirIcon.pm file contains an uuencoded version of that file, as
well as code Copyright 2007 Marcin Owsiany.
The license for dir.png and lib/App/MaMGal/DirIcon.pm is:
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------------
The video icon file (video.png) is Copyright 2006 by Lapo Calamandrei <calamandrei@gmail.com>
It was created by conversion from a file called
calable/mimetypes/video-x-generic.svg in the gnome-icon-theme package.
The lib/App/MaMGal/VideoIcon.pm file contains an uuencoded version of that file, as
well as code Copyright 2009 Marcin Owsiany.
The license for video.png and lib/App/MaMGal/VideoIcon.pm is:
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
lib/App/MaMGal/Entry/Dir.pm view on Meta::CPAN
use warnings;
use base 'App::MaMGal::Entry';
use Carp;
use App::MaMGal::Entry::Picture;
use App::MaMGal::DirIcon;
use Image::Magick;
use App::MaMGal::Exceptions;
sub child { $_[0]->{path_name}.'/'.$_[1] }
sub page_path { $_[0]->{base_name}.'/index.html' }
sub thumbnail_path { $_[0]->{base_name}.'/.mamgal-index.png' }
sub init
{
my $self = shift;
$self->SUPER::init(@_);
if ($self->{dir_name} eq '/' and ($self->{base_name} eq '/' or $self->{base_name} eq '.')) {
$self->{path_name} = '/';
$self->{base_name} = '/';
$self->{is_root} = 1;
} elsif (-e $self->child('.mamgal-root')) {
lib/App/MaMGal/Entry/Dir.pm view on Meta::CPAN
}
sub _write_montage
{
my $self = shift;
my $pruned_files = shift;
my @images = $self->_all_interesting_elements;
unless (@images) {
$self->_write_contents_to(sub { App::MaMGal::DirIcon->img }, '.mamgal-index.png');
return;
}
my $montage_path = $self->child('.mamgal-index.png');
# Return early if the montage is fresh
return if $self->fresher_than_me($montage_path, consider_interesting_only => 1) and $pruned_files == 0;
# Get just a bunch of images, not all of them.
my $montage_count = scalar @images > 36 ? 36 : scalar @images;
# Stack them all together
my $stack = Image::Magick->new;
push @$stack, map {
my $img = Image::Magick->new;
my $rr;
lib/App/MaMGal/Entry/Dir.pm view on Meta::CPAN
$r = $montage->Write($montage_path) and App::MaMGal::SystemException->throw(message => '%s: writing montage failed: %s', objects => [$montage_path, $r]);
}
sub _ignorable_name($)
{
my $self = shift;
my $name = shift;
# ignore hidden files
return 1 if substr($_, 0, 1) eq '.';
# TODO: optimize out contants calls, keeping in mind that they are not really constant (eg. tests change them when testing slides/miniatures generation)
return 1 if grep { $_ eq $name } (qw(lost+found index.html .mamgal-index.png .mamgal-style.css), $self->slides_dir, $self->thumbnails_dir, $self->medium_dir);
return 0;
}
sub _prune_inactive_files
{
my $self = shift;
my $active_files = shift;
# delete old temporary file, if any
unlink $self->child('.mamgal-tmp') if (-e $self->child('.mamgal-tmp'));
my @known_subdirs = ($self->slides_dir, $self->thumbnails_dir, $self->medium_dir);
lib/App/MaMGal/Entry/Picture/Film.pm view on Meta::CPAN
# See the README file for license information
# The picture encapsulating class
package App::MaMGal::Entry::Picture::Film;
use strict;
use warnings;
use base 'App::MaMGal::Entry::Picture';
use App::MaMGal::VideoIcon;
use Carp;
use Scalar::Util 'blessed';
my $thumbnail_extension = '.png';
sub refresh_scaled_pictures
{
my $self = shift;
return $self->refresh_miniatures([$self->thumbnails_dir, 200, 150, $thumbnail_extension]);
}
sub _new_video_icon
{
my $self = shift;
my $s = Image::Magick->new(magick => 'png');
$s->BlobToImage(App::MaMGal::VideoIcon->img);
$s;
}
sub read_image
{
my $self = shift;
my $tools = $self->tools or croak "Tools were not injected.";
my $w = $tools->{mplayer_wrapper} or croak "MplayerWrapper required.";
my $s;
lib/App/MaMGal/EntryFactory.pm view on Meta::CPAN
ref $logger and $logger->isa('App::MaMGal::Logger') or croak "Arg is not a App::MaMGal::Logger , but a [$logger]";
$self->{formatter} = $formatter;
$self->{mplayer_wrapper} = $mplayer_wrapper;
$self->{image_info_factory} = $image_info_factory;
$self->{logger} = $logger;
}
sub sounds_like_picture($)
{
my $base_name = shift;
return $base_name =~ /\.(jpe?g|gif|png|tiff?|bmp)$/io;
}
sub sounds_like_film($)
{
my $base_name = shift;
return $base_name =~ /\.(mpe?g|mov|avi|mjpeg|m[12]v|wmv|fli|nuv|vob|ogm|vcd|svcd|mp4|qt|ogg)$/io;
}
sub canonicalize_path($)
{
a directory containing HTML files presenting one image each
=item .mamgal-medium
a directory containing images scaled to be viewable on screen when shown within the slides
=item .mamgal-thumbnails
a directory containing "iconized" versions of images
=item .mamgal-index.png
a montage image showing the contents of the given directory
=item .mamgal-style.css
a stylesheet for the HTML files in the given tree
=item .mamgal-tmp
a temporary file that might be left over from a crash
t/010_unit_imageinfo.t view on Meta::CPAN
my $self = shift;
my $mpp = $self->{injected_parser} = get_mock_datetime_parser;
my $ml = $self->{injected_logger} = get_mock_logger;
my $f = App::MaMGal::ImageInfoFactory->new($mpp, $ml);
ok($f);
isa_ok($f, 'App::MaMGal::ImageInfoFactory');
$self->{jpg} = $f->read('td/varying_datetimes.jpg');
$self->{jpg_no_0x9003} = $f->read('td/without_0x9003.jpg');
$self->{jpg_no_0x9003_0x9004} = $f->read('td/without_0x9003_0x9004.jpg');
$self->{jpg_no_0x9003_0x9004_0x0132} = $f->read('td/without_0x9003_0x9004_0x0132.jpg');
$self->{png_nodesc} = $f->read('td/more/b.png');
$self->{png_desc} = $f->read('td/more/a.png');
}
sub parser_injection : Test(6) {
my $self = shift;
my $mpp = $self->{injected_parser};
is($self->{jpg}->{parser}, $mpp, 'parser was injected correctly by the factory');
is($self->{jpg_no_0x9003}->{parser}, $mpp, 'parser was injected correctly by the factory');
is($self->{jpg_no_0x9003_0x9004}->{parser}, $mpp, 'parser was injected correctly by the factory');
is($self->{jpg_no_0x9003_0x9004_0x0132}->{parser}, $mpp, 'parser was injected correctly by the factory');
is($self->{png_nodesc}->{parser}, $mpp, 'parser was injected correctly by the factory');
is($self->{png_desc}->{parser}, $mpp, 'parser was injected correctly by the factory');
}
sub logger_injection : Test(6) {
my $self = shift;
my $logger = $self->{injected_logger};
is($self->{jpg}->{logger}, $logger, 'logger was injected correctly by the factory');
is($self->{jpg_no_0x9003}->{logger}, $logger, 'logger was injected correctly by the factory');
is($self->{jpg_no_0x9003_0x9004}->{logger}, $logger, 'logger was injected correctly by the factory');
is($self->{jpg_no_0x9003_0x9004_0x0132}->{logger}, $logger, 'logger was injected correctly by the factory');
is($self->{png_nodesc}->{logger}, $logger, 'logger was injected correctly by the factory');
is($self->{png_desc}->{logger}, $logger, 'logger was injected correctly by the factory');
}
sub description_method : Test(6) {
my $self = shift;
is($self->{jpg}->description, "A description of c.jpg\n", 'jpeg description is correct');
is($self->{jpg_no_0x9003}->description, "A description of c.jpg\n", 'jpeg description is correct');
is($self->{jpg_no_0x9003_0x9004}->description, "A description of c.jpg\n", 'jpeg description is correct');
is($self->{jpg_no_0x9003_0x9004_0x0132}->description, "A description of c.jpg\n", 'jpeg description is correct');
is($self->{png_desc}->description, "Test image A", 'png description is correct');
is($self->{png_nodesc}->description, undef, 'png with no description returns undef');
}
sub exif_datetime_original_string : Test(4) {
my $self = shift;
is($self->{jpg}->datetime_original_string, '2008:11:27 20:43:53', 'returned datetime original is the exif field');
is($self->{jpg_no_0x9003}->datetime_original_string, undef, 'returned datetime original is undefined');
is($self->{jpg_no_0x9003_0x9004}->datetime_original_string, undef, 'returned datetime original is undefined');
is($self->{jpg_no_0x9003_0x9004_0x0132}->datetime_original_string, undef, 'returned datetime original is undefined');
}
t/070_unit_dir.t view on Meta::CPAN
is($e->page_path, $test_file_name[1].'/index.html', "$class_name page_path is correct");
}
}
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, $test_file_name[1].'/.mamgal-index.png', "$class_name thumbnail_path is correct");
}
{
my $e = $self->{entry_no_stat};
is($e->thumbnail_path, $test_file_name[1].'/.mamgal-index.png', "$class_name thumbnail_path is correct");
}
}
sub invalid_make_invocation : Test {
my $self = shift;
dies_ok(sub { $self->{entry}->make }, "Dir dies on make invocation with no arg");
}
sub empty_creation_time_range_test {
my $self = shift;
t/070_unit_dir.t view on Meta::CPAN
sub valid_make_invocation : Test(5) {
my $self = shift;
my $d = $self->{entry};
my $mf = get_mock_formatter(qw(format stylesheet));
$d->add_tools({formatter => $mf});
lives_ok(sub { $d->make }, "Dir lives on make invocation");
ok($mf->called('format'), "Dir->make calls formatter->format internally");
if ($d->is_root) {
ok($mf->called('stylesheet'), "Dir->make calls formatter->stylesheet internally");
dir_only_contains_ok('td/empty', [qw{index.html .mamgal-index.png .mamgal-style.css}],
"Directory contains only the index file, thumb and stylesheet afterwards");
} else {
ok(1, "Keep the number of tests constant.");
dir_only_contains_ok('td/empty', [qw{index.html .mamgal-index.png}],
"Directory contains only the index file and thumb afterwards");
}
use Text::Diff::Table; # work around a warning from UNIVERSAL::can
file_ok('td/empty/index.html', "whatever", "Dir->make creates an index file");
}
sub creation_time_range : Test(3) {
my $self = shift;
# one-element range for empty dirss
$self->empty_creation_time_range_test;
t/070_unit_dir.t view on Meta::CPAN
is($e->page_path, '//index.html', "$class_name page_path is correct");
}
}
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-index.png', "$class_name thumbnail_path is correct");
}
{
my $e = $self->{entry_no_stat};
is($e->thumbnail_path, '//.mamgal-index.png', "$class_name thumbnail_path is correct");
}
}
# We cannot run these, as the general condition for Entry does not hold for non-empty dirs
# Instead we test this in the integration tests
sub stat_functionality : Test { ok(1) }
sub stat_functionality_when_created_without_stat : Test { ok(1) }
sub is_intetresting_method : Test(1) { ok(1) }
package App::MaMGal::Unit::Entry::Dir::Dot;
t/080_unit_picture.t view on Meta::CPAN
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');
t/300_integration_dir_with_many.t view on Meta::CPAN
use App::MaMGal::ImageInfoFactory;
use POSIX;
prepare_test_data;
my $time_now = time;
my $time_past = POSIX::mktime(25,6,8,17,3,109,0,0,1);
cmp_ok($time_past + 3600, '<', $time_now, 'your clock is wrong');
my $time_old = POSIX::mktime(0,0,0,18,11,104);# in 2004 - "very old"
my $time_not_oldest = $time_old + 3600;# whatever time between "past" and "old" to keep other entries from interfering
# touch up the directory and picture with different times
utime $time_past, $time_past, 'td/more/subdir/p.png' or die "Touching p.png failed";
utime $time_old, $time_old, 'td/more/subdir/p2.png' or die "Touching p2.png failed";
utime $time_old, $time_now, 'td/more/subdir' or die "Touching directory failed";
utime $time_not_oldest, $time_not_oldest, 'td/more/subdir/interesting' or die "Touching interesting failed";
utime $time_not_oldest, $time_not_oldest, 'td/more/subdir/uninteresting' or die "Touching uninteresting failed";
utime $time_not_oldest, $time_not_oldest, 'td/more/subdir/interesting/b.png' or die "Touching b.png failed";
utime $time_not_oldest, $time_not_oldest, 'td/more/subdir/uninteresting/bar.txt' or die "Touching bar.txt failed";
use_ok('App::MaMGal::Entry::Dir');
my $d;
lives_ok(sub { $d = App::MaMGal::Entry::Dir->new(qw(td more), stat('td/more')) }, "creation ok");
isa_ok($d, 'App::MaMGal::Entry::Dir', "a dir is a dir");
my $mf = get_mock_formatter(qw(format stylesheet));
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $tools = {
t/300_integration_dir_with_one_file.t view on Meta::CPAN
use Image::EXIF::DateTime::Parser;
use App::MaMGal::ImageInfoFactory;
use App::MaMGal::EntryFactory;
prepare_test_data;
my $time = time;
my $pic_time = $time - 120;
# touch up the directory and picture with different times
utime $time, $time, 'td/one_pic' or die "Touching directory failed";
utime $pic_time, $pic_time, 'td/one_pic/a1.png' or die "Touching picture failed";
use_ok('App::MaMGal::Entry::Dir');
my $d;
lives_ok(sub { $d = App::MaMGal::Entry::Dir->new(qw(td one_pic), stat('td/one_pic')) }, "dir can be created with an array: existant dir with one pic");
isa_ok($d, 'App::MaMGal::Entry::Dir');
my $mf = get_mock_formatter(qw(format stylesheet format_slide));
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $tools = {
formatter => $mf,
t/300_integration_dir_with_one_file.t view on Meta::CPAN
is($ret[0]->element_index, 0, "picture knows its index");
ok($d->is_interesting, 'dir with one picture is interesting');
is($d->tile_path, $ret[0]->tile_path, 'interesting thumbnail path of a dir with one picture is that pictures interesting thumbnail path');
my ($prev, $next);
dies_ok(sub { ($prev, $next) = $d->neighbours_of_index(1) }, "there is no index one");
lives_ok(sub { ($prev, $next) = $d->neighbours_of_index(0) }, "there is index zero");
ok(not(defined($prev)), "there is no prev neighbour");
ok(not(defined($next)), "there is no next neighbour");
dir_only_contains_ok('td/one_pic', [qw(a1.png)], "Only the picture at start");
lives_ok(sub { $d->make }, "dir makes stuff and survives");
dir_only_contains_ok('td/one_pic', [qw(.mamgal-medium .mamgal-thumbnails .mamgal-slides index.html .mamgal-index.png
a1.png
.mamgal-thumbnails/a1.png
.mamgal-medium/a1.png
.mamgal-slides/a1.png.html)],
"index, picture, .mamgal-thumbnails, .mamgal-medium and .mamgal-slides");
my $single_creation_time = $d->creation_time;
ok($single_creation_time, "There is some non-zero create time");
my @creation_time_range = $d->creation_time;
is(scalar @creation_time_range, 1, "Creation time range is empty");
is($creation_time_range[0], $single_creation_time, "Range-type creation time is equal to the scalar one");
my ($one_pic_entry) = $d->elements();
ok($one_pic_entry, "There is one picture");
t/300_integration_entry_factory.t view on Meta::CPAN
lives_ok(sub { $e = $ef->create_entry_for('td/symlink_to_empty') }, "EF creates entry from symlink to empty dir");
isa_ok($e, 'App::MaMGal::Entry::Dir', "expected entry is a Dir");
is($e->name, 'symlink_to_empty', "file name matches");
tools_ok($e);
lives_ok(sub { $e = $ef->create_entry_for('td/symlink_broken') }, "EF creates entry from broken symlink");
isa_ok($e, 'App::MaMGal::Entry::BrokenSymlink', "expected entry is a BrokenSymlink");
is($e->name, 'symlink_broken', "file name matches");
tools_ok($e);
lives_ok(sub { $e = $ef->create_entry_for('td/one_pic/a1.png') }, "EF creates entry from a picture");
isa_ok($e, 'App::MaMGal::Entry::Picture::Static', "expected entry is a Picture::Static");
is($e->name, 'a1.png', "file name matches");
tools_ok($e);
lives_ok(sub { $e = $ef->create_entry_for('td/symlink_pic.png') }, "EF creates entry from a symlink to picture");
isa_ok($e, 'App::MaMGal::Entry::Picture::Static', "expected entry is a Picture::Static");
is($e->name, 'symlink_pic.png', "file name matches");
tools_ok($e);
lives_ok(sub { $e = $ef->create_entry_for('td/symlink_pic_noext') }, "EF creates entry from a secret symlink to picture");
isa_ok($e, 'App::MaMGal::Entry::NonPicture', "expected entry is a NonPicture");
is($e->name, 'symlink_pic_noext', "file name matches");
tools_ok($e);
dies_ok(sub { $ef->create_entry_for('td/non-existant') }, "EF dies on nonexistant arg");
# some corner cases:
t/500_integration_formatter_one_film.t view on Meta::CPAN
#
my $time = 1228933448;
utime($time, $time, 'td/one_film/m.mov') == 1 or die "Failed to touch file";
my $dir = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, App::MaMGal::ImageInfoFactory->new(get_mock_datetime_parser, get_mock_logger), get_mock_logger)->create_entry_for('td/one_film');
# this is m.mov
my $mov = ($dir->elements)[0];
my $t;
lives_ok(sub { $t = $f->format($dir) }, "formatter formats index page with one film");
tag_ok($t, "a", { href => '.mamgal-slides/m.mov.html' }, "there is a link to the slide");
tag_ok($t, "img", { src => '.mamgal-thumbnails/m.mov.png' }, "there is a pic on the page");
text_ok($t, 'm.mov', "contains the filename alone");
dies_ok(sub { $f->format_slide }, "dies with no arg");
dies_ok(sub { $f->format_slide(1) }, "dies non pic arg");
dies_ok(sub { $f->format_slide($mov, 2) }, "dies with > 1 arg");
my $st_mov;
lives_ok(sub { $st_mov = $f->format_slide($mov) }, "lives with a film arg");
text_ok($st_mov, 'm.mov', "slide contains filename");
for my $n ('td', 'one_film') {
t/500_integration_formatter_one_picture.t view on Meta::CPAN
my $f = App::MaMGal::Formatter->new($le);
my $edtp = Image::EXIF::DateTime::Parser->new;
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $ef = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, $iif, get_mock_logger);
#
# a dir with a single pic _without_ description
#
my $time = 1228933448;
utime($time, $time, 'td/more/zzz another subdir/p.png') == 1 or die "Failed to touch file";
my $dir_nd = $ef->create_entry_for('td/more/zzz another subdir');
# this is p.png, which has no description
my $p_nd = ($dir_nd->elements)[0];
my $t_nd;
lives_ok(sub { $t_nd = $f->format($dir_nd) }, "formatter formats index page with one picture");
tag_ok($t_nd, "a", { href => '.mamgal-slides/p.png.html' }, "there is a link to the slide");
tag_ok($t_nd, "img", { src => '.mamgal-thumbnails/p.png' }, "there is a pic on the page");
text_ok($t_nd, 'p.png', "does not contain filename alone");
dies_ok(sub { $f->format_slide }, "dies with no arg");
dies_ok(sub { $f->format_slide(1) }, "dies non pic arg");
dies_ok(sub { $f->format_slide($p_nd, 2) }, "dies with > 1 arg");
my $st_p_nd;
lives_ok(sub { $st_p_nd = $f->format_slide($p_nd) }, "lives with a pic arg");
text_ok($st_p_nd, 'p.png', "slide contains filename");
for my $n ('td', 'more', 'zzz another subdir') {
text_ok($st_p_nd, $n, "slide contains parent filename");
}
tag_ok($st_p_nd, "img", {src => '../.mamgal-medium/p.png'}, "there is a medium pic on the page");
no_tag($st_p_nd, "embed", "there is no embed tag on the page");
tag_count($st_p_nd, "img", {}, 1, "just one img tag");
tag_ok($st_p_nd, "a", {href => '../index.html'}, "there is a link up on the page");
tag_ok($st_p_nd, "a", {href => '../p.png'}, "there is a link to image itself");
tag_count($st_p_nd, "a", {}, 2, "two links in total");
tag_ok($st_p_nd, "span", {class => 'date', _content => '03/18/08'},"there is a date");
tag_ok($st_p_nd, "span", {class => 'time', _content => '09:33:32'},"there is a time");
my $ct_p_nd;
lives_ok(sub { $ct_p_nd = $f->entry_cell($p_nd) }, "lives through cell entry generation");
text_ok($ct_p_nd, 'p.png', "cell contains filename");
#
# a dir with a single pic _with_ description
#
my $d = $ef->create_entry_for('td/one_pic');
my $t;
lives_ok(sub { $t = $f->format($d) }, "formatter formats index page with one picture");
tag_ok($t, "a", { href => '.mamgal-slides/a1.png.html' }, "there is a link to the slide");
tag_ok($t, "img", { src => '.mamgal-thumbnails/a1.png' }, "there is a pic on the page");
text_ok($t, 'Another test image.', "contains description");
no_text($t, 'a1.png', "does not contain filename alone");
my $p = $ef->create_entry_for('td/one_pic/a1.png');
my $st;
lives_ok(sub { $st = $f->format_slide($p) }, "formatter formats a slide");
tag_ok($st, "img", {src => '../.mamgal-medium/a1.png'}, "there is a medium pic on the page");
tag_count($st, "img", {}, 1, "just one img tag");
tag_ok($st, "a", {href => '../index.html'}, "there is a link up on the page");
tag_ok($st, "a", {href => '../a1.png'}, "there is a link to image itself");
tag_count($st, "a", {}, 2, "two links");
text_ok($st, 'Another test image.', "contains description");
no_text($st, 'a1.png', "does not contain filename alone");
my $ct;
lives_ok(sub { $ct = $f->entry_cell($p) }, "lives through cell entry generation");
no_text($ct, 'a1.png', "cell does not contain filename");
text_ok($ct, 'Another test image.', "cell contains description");
my $p_dir = ($d->elements)[0];
my $st2;
lives_ok(sub { $st2 = $f->format_slide($p_dir) }, "formatter formats a slide");
is($st, $st2, "slide is the same for both kinds of picture access");
t/500_integration_formatter_one_subdir.t view on Meta::CPAN
use App::MaMGal::Formatter;
my $f = App::MaMGal::Formatter->new($le);
use App::MaMGal::EntryFactory;
use App::MaMGal::ImageInfoFactory;
my $d = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, App::MaMGal::ImageInfoFactory->new(get_mock_datetime_parser, get_mock_logger), get_mock_logger)->create_entry_for('td/one_dir');
$d->set_root(1);
my $t = $f->format($d);
text_ok($t, 'one_dir', "there is the directory name");
tag_count($t, "a", { href => 'subdir/index.html' }, 2, "there are two links to the subdir");
tag_ok($t, "img", { src => 'subdir/.mamgal-index.png' }, "there is a pic on the page");
no_tag($t, "a", { href => "../index.html" }, "there is no link down");
no_text($t, '/', "there is no (leading) slash on root dir page");
my $tsub = $f->format(($d->elements)[0]);
no_tag($tsub, "img", {}, "subdir index has no pics");
link_ok($tsub, "../index.html", "subdir has link down");
text_ok($tsub, 'subdir', "there is the directory name");
text_ok($tsub, 'one_dir', "there is the parent directory name");
no_text($tsub, 'td', "there isn't the grandfather directory name");
t/500_integration_formatter_slides_sequence.t view on Meta::CPAN
$le->set_locale('C');
my $edtp = Image::EXIF::DateTime::Parser->new,
my $f = App::MaMGal::Formatter->new($le);
my $iif = App::MaMGal::ImageInfoFactory->new($edtp, get_mock_logger);
my $ef = App::MaMGal::EntryFactory->new($f, get_mock_mplayer_wrapper, $iif, get_mock_logger);
my $d = $ef->create_entry_for('td/more');
my @elems = $d->elements;
my $p = $elems[1];
my $t = $f->format_slide($p);
tag_ok($t, "img", {src => '../.mamgal-medium/b.png'}, "b.png: there is a medium pic on the page");
tag_ok($t, "a", {href => '../index.html'}, "b.png: there is a link to the index on the page");
tag_ok($t, "a", {href => 'a.png.html'}, "b.png: there is a link to previous slide");
tag_ok($t, "a", {href => 'x.png.html'}, "b.png: there is a link to next slide");
tag_ok($t, "a", {href => '../b.png'}, "b.png: there is a link to the image itself");
tag_count($t, "a", {}, 4, "b.png: there are only 3 links in total");
my $p2 = $elems[3];
my $t2 = $f->format_slide($p2);
tag_ok($t2, "img", {src => '../.mamgal-medium/x.png'}, "x.png: there is a medium pic on the page");
tag_ok($t2, "a", {href => '../index.html'}, "x.png: there is a link to the index on the page");
tag_ok($t2, "a", {href => 'b.png.html'}, "x.png: there is a link to previous slide");
tag_ok($t2, "a", {href => '../x.png'}, "x.png: there is a link to the image itself");
tag_count($t2, "a", {}, 3, "x.png: there are only 3 links in total");
t/800_integration_maker_one_film.t view on Meta::CPAN
use lib 'testlib';
use App::MaMGal::TestHelper;
prepare_test_data;
dir_only_contains_ok('td/one_film', ['m.mov'],
"index does not exist initially");
use_ok('App::MaMGal');
my $m = App::MaMGal->new;
ok($m->make_without_roots('td/one_film'), "maker returns success on an dir with one film");
dir_only_contains_ok('td/one_film', [qw(index.html .mamgal-index.png .mamgal-thumbnails .mamgal-slides
m.mov
.mamgal-thumbnails/m.mov.png
.mamgal-slides/m.mov.html)],
"maker created index.html, .mamgal-thumbnails and .mamgal-slides");
t/800_integration_maker_one_picture.t view on Meta::CPAN
use warnings;
use Carp 'verbose';
use Test::More tests => 6;
use Test::Files;
use Test::HTML::Content;
use lib 'testlib';
use App::MaMGal::TestHelper;
prepare_test_data;
dir_only_contains_ok('td/one_pic', ['a1.png'], "index does not exist initially");
use_ok('App::MaMGal');
my $M = App::MaMGal->new;
ok($M->make_without_roots('td/one_pic'), "maker returns success on an dir with one file");
dir_only_contains_ok('td/one_pic', [qw(index.html .mamgal-index.png .mamgal-medium .mamgal-thumbnails .mamgal-slides
a1.png
.mamgal-medium/a1.png
.mamgal-thumbnails/a1.png
.mamgal-slides/a1.png.html)],
"maker created index.html, .mamgal-medium, .mamgal-thumbnails and .mamgal-slides");
unlink('td/one_pic/a1.png') or die;
$M = App::MaMGal->new;
ok($M->make_without_roots('td/one_pic'), "maker returns success on an dir with one file");
dir_only_contains_ok('td/one_pic', [qw(index.html .mamgal-index.png)], "maker deleted .mamgal-medium, .mamgal-thumbnails and .mamgal-slides");
t/900_integration_maker_many_files.t view on Meta::CPAN
use Carp 'verbose';
use Test::More tests => 11;
use Test::Files;
use Test::HTML::Content;
use Test::Exception;
use lib 'testlib';
use App::MaMGal::TestHelper;
prepare_test_data;
dir_only_contains_ok('td/more', [qw(a.png b.png x.png subdir subdir/p.png subdir/p2.png subdir/lost+found),
qw(subdir/uninteresting subdir/uninteresting/bar.txt),
qw(subdir/interesting subdir/interesting/b.png),
'zzz another subdir', 'zzz another subdir/p.png'], "not much exists initially");
use_ok('App::MaMGal');
# Get locale from environment so that you can see some representatative output in your language
my $M = App::MaMGal->new('');
ok($M->{logger});
ok($M->make_roots('td/more'), "maker returns success on an dir with some files");
dir_only_contains_ok('td/more', [qw(.mamgal-root
index.html .mamgal-index.png .mamgal-style.css
.mamgal-medium .mamgal-thumbnails .mamgal-slides
a.png b.png x.png
.mamgal-medium/a.png .mamgal-medium/b.png .mamgal-medium/x.png
.mamgal-thumbnails/a.png .mamgal-thumbnails/b.png .mamgal-thumbnails/x.png
.mamgal-slides/a.png.html .mamgal-slides/b.png.html .mamgal-slides/x.png.html
subdir subdir/p.png subdir/p2.png subdir/lost+found
subdir/index.html subdir/.mamgal-index.png
subdir/.mamgal-medium subdir/.mamgal-medium/p.png subdir/.mamgal-medium/p2.png
subdir/.mamgal-thumbnails subdir/.mamgal-thumbnails/p.png
subdir/.mamgal-thumbnails/p2.png
subdir/.mamgal-slides subdir/.mamgal-slides/p.png.html
subdir/.mamgal-slides/p2.png.html
subdir/uninteresting subdir/uninteresting/bar.txt subdir/interesting subdir/interesting/b.png
subdir/interesting/.mamgal-index.png subdir/interesting/.mamgal-medium
subdir/interesting/.mamgal-medium/b.png subdir/uninteresting/.mamgal-index.png
subdir/uninteresting/index.html subdir/interesting/index.html subdir/interesting/.mamgal-thumbnails
subdir/interesting/.mamgal-slides subdir/interesting/.mamgal-slides/b.png.html
subdir/interesting/.mamgal-thumbnails/b.png),
'zzz another subdir', 'zzz another subdir/.mamgal-index.png', 'zzz another subdir/index.html',
'zzz another subdir/p.png', 'zzz another subdir/.mamgal-slides',
'zzz another subdir/.mamgal-slides/p.png.html', 'zzz another subdir/.mamgal-thumbnails',
'zzz another subdir/.mamgal-thumbnails/p.png', 'zzz another subdir/.mamgal-medium',
'zzz another subdir/.mamgal-medium/p.png'
],
"maker created index.html, .mamgal-medium, .mamgal-thumbnails and .mamgal-slides, also for both subdirs");
# Test failures
my $ex = get_mock_exception 'App::MaMGal::SystemException';
$M->{maker} = Test::MockObject->new;
$M->{maker}->mock('make_roots', sub { die $ex });
$M->{maker}->mock('make_without_roots', sub { die $ex });
$M->{logger} = get_mock_logger;
lives_ok(sub { $M->make_roots('whatever') }, 'make_roots survives');
testlib/App/MaMGal/TestHelper.pm view on Meta::CPAN
}
sub prepare_test_data {
# We have to create empty directories, because git does not track them
for my $dir (qw(empty one_dir one_dir/subdir more/subdir/lost+found)) {
mkdir("td.in/$dir") or die "td.in/$dir: $!" unless -d "td.in/$dir";
}
# We have to create and populate directories with spaces in their
# names, because perl's makemaker does not like them
mkdir "td.in/more/zzz another subdir" unless -d "td.in/more/zzz another subdir";
my $orig_size = -s "td.in/p.png" or die "Unable to stat td.in/p.png";
my $dest_size = -s 'td.in/more/zzz another subdir/p.png';
unless ($dest_size and $orig_size == $dest_size) {
system('cp', '-a', 'td.in/p.png', 'td.in/more/zzz another subdir/p.png');
}
# We also need to create our test symlinks, because MakeMaker does not like them
for my $pair ([qw(td.in/symlink_broken broken)], [qw(td.in/symlink_pic_noext one_pic/a1.png)], [qw(td.in/symlink_to_empty empty)], [qw(td.in/symlink_to_empty_file empty_file)], [qw(td.in/symlink_pic.png one_pic/a1.png)]) {
my ($link, $dest) = @$pair;
symlink($dest, $link) or die "Failed to symlink [$dest] to [$link]" unless -l $link;
}
# Finally, purge and copy a clean version of the test data into "td"
system('rm -rf td ; cp -a td.in td') == 0 or die "Test data preparation failed: $?";
}
sub logged_only_ok($$;$)
{
my $mock = shift;