Merge remote branch 'kc/new/bug_4218' into kcmaster
[koha.git] / t / db_dependent / Koha.t
1 #!/usr/bin/perl
2 #
3 # This is to test C4/Koha
4 # It requires a working Koha database with the sample data
5
6 use strict;
7 use warnings;
8 use C4::Context;
9
10 use Test::More tests => 4;
11
12 BEGIN {
13     use_ok('C4::Koha');
14 }
15
16 my $data = {
17     category            => 'CATEGORY',
18     authorised_value    => 'AUTHORISED_VALUE',
19     lib                 => 'LIB',
20     lib_opac            => 'LIBOPAC',
21     imageurl            => 'IMAGEURL'
22 };
23
24 my $dbh = C4::Context->dbh;
25
26 # Insert an entry into authorised_value table
27 my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);";
28 my $sth = $dbh->prepare($query);
29 my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
30 ok($insert_success, "Insert data in database");
31
32
33 # Tests
34 SKIP: {
35     skip "INSERT failed", 2 unless $insert_success;
36     
37     is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
38     is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" );
39 }
40
41 # Clean up
42 if($insert_success){
43     $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
44     $sth = $dbh->prepare($query);
45     $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
46 }
47