Bug 21987: Add tests
[koha.git] / t / db_dependent / Images.t
1 use Modern::Perl;
2 use GD;
3 use Test::More tests => 4;
4
5 use C4::Images;
6 use t::lib::TestBuilder;
7
8 my $schema = Koha::Database->schema;
9 $schema->storage->txn_begin();
10
11 my $builder = t::lib::TestBuilder->new;
12 my $biblio = $builder->build_sample_biblio;
13
14 my $path = 'koha-tmpl/intranet-tmpl/prog/img/koha-logo.png';
15 my $koha_logo = GD::Image->new($path);
16
17 {
18     # True color == 0
19     $koha_logo->trueColor(0);
20     C4::Images::PutImage( $biblio->biblionumber, $koha_logo );
21
22     my @imagenumbers = C4::Images::ListImagesForBiblio( $biblio->biblionumber );
23     is( scalar(@imagenumbers), 1 );
24     my $image = C4::Images::RetrieveImage($imagenumbers[0]);
25     ok( length $image->{thumbnail} < length $image->{imagefile}, 'thumbnail should be shorter than the original image' );
26 }
27
28 {
29     # True color == 1
30     # Note that we are cheating here, the original file is not a true color image
31     $koha_logo->trueColor(1);
32     C4::Images::PutImage( $biblio->biblionumber, $koha_logo, 'replace' );
33
34     my @imagenumbers = C4::Images::ListImagesForBiblio( $biblio->biblionumber );
35     is( scalar(@imagenumbers), 1 );
36     my $image = C4::Images::RetrieveImage($imagenumbers[0]);
37     ok( length $image->{thumbnail} > length $image->{imagefile}, 'thumbnail should be bigger than the original image.' );
38     # Actually it should not be bigger, but we cheat with the trueColor flag
39 }