Bug 21987: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Dec 2018 17:02:14 +0000 (14:02 -0300)
committerLucas Gass <lucas@bywatersolutions.com>
Tue, 19 Mar 2019 23:25:20 +0000 (23:25 +0000)
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit afb39b132b10b74efec31cd8191cdcd72a61d8d3)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 43a58d640a3193ade1f357a31736bafcd939444a)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

t/db_dependent/Images.t [new file with mode: 0644]

diff --git a/t/db_dependent/Images.t b/t/db_dependent/Images.t
new file mode 100644 (file)
index 0000000..9e2e509
--- /dev/null
@@ -0,0 +1,39 @@
+use Modern::Perl;
+use GD;
+use Test::More tests => 4;
+
+use C4::Images;
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->schema;
+$schema->storage->txn_begin();
+
+my $builder = t::lib::TestBuilder->new;
+my $biblio = $builder->build_sample_biblio;
+
+my $path = 'koha-tmpl/intranet-tmpl/prog/img/koha-logo.png';
+my $koha_logo = GD::Image->new($path);
+
+{
+    # True color == 0
+    $koha_logo->trueColor(0);
+    C4::Images::PutImage( $biblio->biblionumber, $koha_logo );
+
+    my @imagenumbers = C4::Images::ListImagesForBiblio( $biblio->biblionumber );
+    is( scalar(@imagenumbers), 1 );
+    my $image = C4::Images::RetrieveImage($imagenumbers[0]);
+    ok( length $image->{thumbnail} < length $image->{imagefile}, 'thumbnail should be shorter than the original image' );
+}
+
+{
+    # True color == 1
+    # Note that we are cheating here, the original file is not a true color image
+    $koha_logo->trueColor(1);
+    C4::Images::PutImage( $biblio->biblionumber, $koha_logo, 'replace' );
+
+    my @imagenumbers = C4::Images::ListImagesForBiblio( $biblio->biblionumber );
+    is( scalar(@imagenumbers), 1 );
+    my $image = C4::Images::RetrieveImage($imagenumbers[0]);
+    ok( length $image->{thumbnail} > length $image->{imagefile}, 'thumbnail should be bigger than the original image.' );
+    # Actually it should not be bigger, but we cheat with the trueColor flag
+}