App-sitelenmute

 view release on metacpan or  search on metacpan

t/album.t  view on Meta::CPAN

#!/usr/bin/env perl
# Copyright (C) 2022  Alex Schroeder <alex@gnu.org>

# This program 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, either version 3 of the License, or (at your option) any later
# version.
#
# This program 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.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

use utf8;
# apply before loading Test::More
use open ':std', ':encoding(utf8)';
use Test::More;
use Modern::Perl;
use Config;
use File::Copy;
use File::Copy::Recursive qw(dircopy);
use File::Path qw(remove_tree);
use File::SearchPath qw(searchpath);
use File::Slurper qw(read_text read_binary);
use File::Spec::Functions qw(catfile);
use JSON::Tiny qw(decode_json);
use Mojo::DOM58;

plan skip_all => "'convert' not installed"
    unless searchpath('convert');

plan skip_all => "neither '7z' nor 'zip' installed"
    unless searchpath('7za') || searchpath('zip');

my $options = " -v -v";
# -o means without auto-orient
$options .= " -o" unless searchpath('exiftran') or searchpath('exifautotran');
# -no-sRGB means without intermediate sRGB colorspace conversion
$options .= " --no-sRGB" unless searchpath('tificc');
# -d means without zip
$options .= " -d" unless searchpath('zip') or searchpath('7za');
# -n "album name"
$options .= " -n Test";
# --index back button URL
$options .= " --index=../top.html";
# --title of preview
$options .= " --title='Test Preview'";
# --description long
$options .= " --description='Test Description'";
# --url of the gallery
$options .= " --url=http://example.org/test";

# where the images are
my $album = catfile("t", "album");
# where the gallery is generated
my $gallery = catfile("t", "gallery");
remove_tree($gallery) if -d $gallery;
my $json = catfile($gallery, "data.json");
my $html = catfile($gallery, "index.html");

# generate album
my $perl = $^X;
my $script = catfile("blib", "script", "sitelen-mute");
my $output = qx("$perl" "$script" -c txt $options "$album" "$gallery");
unlike($output, qr(error)i, "Running script");
like($output, qr(Processing 4 image files), "Proccessing files");
ok(-d $gallery, "Gallery was created");
ok(-f $json, "data.json was created");
ok(-e catfile($gallery, "imgs", "Blaufußtölpel.jpg"), "Blue-Footed Booby");
ok(-e catfile($gallery, "imgs", "P3111190.jpg"), "Marine Iguana");
ok(-e catfile($gallery, "imgs", "P3111203.jpg"), "Red Rock Crab");

# data
my $data = decode_json(read_binary($json));
is($data->{data}->[0]->{caption}->[0], "Zwei Blaufußtölpel beim Balztanz", "Caption title from text file");
is($data->{data}->[0]->{img}->[0], "imgs/Blaufußtölpel.jpg", "Filename of the blue-footed booby image in the JSON");
is($data->{data}->[0]->{date}, "2020-02-29 16:36", "Date of the blue-footed booby image in the JSON");
is($data->{data}->[1]->{caption}->[0], "The white stuff is salt", "Caption title from text file");



( run in 4.671 seconds using v1.01-cache-2.11-cpan-5e09290becf )