View | Details | Raw Unified | Return to bug 14778
Collapse All | Expand All

(-)a/C4/Images.pm (-1 / +1 lines)
Lines 102-108 sub RetrieveImage { Link Here
102
102
103
    my $dbh = C4::Context->dbh;
103
    my $dbh = C4::Context->dbh;
104
    my $query =
104
    my $query =
105
'SELECT mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?';
105
'SELECT imagenumber, mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?';
106
    my $sth = $dbh->prepare($query);
106
    my $sth = $dbh->prepare($query);
107
    $sth->execute($imagenumber);
107
    $sth->execute($imagenumber);
108
    my $imagedata = $sth->fetchrow_hashref;
108
    my $imagedata = $sth->fetchrow_hashref;
(-)a/t/Images.t (-34 / +30 lines)
Lines 2-54 Link Here
2
#
2
#
3
#Testing C4 Images
3
#Testing C4 Images
4
4
5
use strict;
5
use Modern::Perl;
6
use warnings;
6
use Test::More tests => 8;
7
use Test::More tests => 7;
8
use Test::MockModule;
7
use Test::MockModule;
9
8
10
BEGIN {
9
use_ok('C4::Images');
11
    use_ok('C4::Images');
10
12
}
11
use Test::DBIx::Class {
13
12
    schema_class => 'Koha::Schema',
14
my $module = new Test::MockModule('C4::Context');
13
    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
15
$module->mock(
14
    connect_opts => { name_sep => '.', quote_char => '`', },
16
    '_new_dbh',
15
    fixture_class => '::Populate',
17
    sub {
16
}, 'Biblioimage' ;
18
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17
19
          || die "Cannot create handle: $DBI::errstr\n";
18
# Make the code in the module use our mocked Koha::Schema/Koha::Database
20
        return $dbh;
19
my $db = Test::MockModule->new('Koha::Database');
21
    }
20
$db->mock(
21
    # Schema() gives us the DB connection set up by Test::DBIx::Class
22
    _new_schema => sub { return Schema(); }
22
);
23
);
24
25
my $biblionumber = 2;
23
my $images = [
26
my $images = [
24
    [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ],
27
    [ 1, $biblionumber, 'gif',  'imagefile1', 'thumbnail1' ],
25
    [ 1, 2, 'gif',  'red',  001, 000 ],
28
    [ 3, $biblionumber, 'jpeg', 'imagefile3', 'thumbnail3' ],
26
    [ 3, 2, 'jpeg', 'blue', 111, 110 ]
27
];
29
];
28
my $dbh = C4::Context->dbh();
30
fixtures_ok [
29
31
    Biblioimage => [
30
$dbh->{mock_add_resultset} = $images;
32
        [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ],
33
        @$images,
34
    ],
35
], 'add fixtures';
31
36
32
my $image = C4::Images::RetrieveImage();
37
my $image = C4::Images::RetrieveImage(1);
33
38
34
is( $image->{'imagenumber'}, 1, 'First imagenumber is 1' );
39
is( $image->{'imagenumber'}, 1, 'First imagenumber is 1' );
35
40
36
is( $image->{'mimetype'}, 'gif', 'First mimetype is red' );
41
is( $image->{'mimetype'}, 'gif', 'First mimetype is gif' );
37
42
38
is( $image->{'thumbnail'}, 001, 'First thumbnail is 001' );
43
is( $image->{'thumbnail'}, 'thumbnail1', 'First thumbnail is correct' );
39
44
40
$image = C4::Images::RetrieveImage();
45
my @imagenumbers = C4::Images::ListImagesForBiblio($biblionumber);
41
42
$image = C4::Images::RetrieveImage();
43
44
$dbh->{mock_add_resultset} = $images;
45
46
my @imagenumbers = C4::Images::ListImagesForBiblio();
47
46
48
is( $imagenumbers[0], 1, 'imagenumber is 1' );
47
is( $imagenumbers[0], 1, 'imagenumber is 1' );
49
48
50
is( $imagenumbers[1], 3, 'imagenumber is 3' );
49
is( $imagenumbers[1], 3, 'imagenumber is 3' );
51
50
52
$dbh->{mock_add_resultset} = $images;
53
54
is( $imagenumbers[4], undef, 'imagenumber undef' );
51
is( $imagenumbers[4], undef, 'imagenumber undef' );
55
- 

Return to bug 14778