bug_6253: Unified member Search()
[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 => 8;
11
12 BEGIN {
13     use_ok('C4::Koha');
14     use_ok('C4::Members');
15 }
16
17 my $data = {
18     category            => 'CATEGORY',
19     authorised_value    => 'AUTHORISED_VALUE',
20     lib                 => 'LIB',
21     lib_opac            => 'LIBOPAC',
22     imageurl            => 'IMAGEURL'
23 };
24
25 my $dbh = C4::Context->dbh;
26
27 # Insert an entry into authorised_value table
28 my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);";
29 my $sth = $dbh->prepare($query);
30 my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
31 ok($insert_success, "Insert data in database");
32
33
34 # Tests
35 SKIP: {
36     skip "INSERT failed", 5 unless $insert_success;
37     
38     is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
39     is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" );
40
41     my $sortdet=C4::Members::GetSortDetails("lost", "3");
42     is ($sortdet, "Lost and Paid For", "lost and paid works");
43
44     my $sortdet2=C4::Members::GetSortDetails("loc", "child");
45     is ($sortdet2, "Children's Area", "Child area works");
46
47     my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1");
48     is ($sortdet3, "Withdrawn", "Withdrawn works");
49 }
50
51 # Clean up
52 if($insert_success){
53     $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
54     $sth = $dbh->prepare($query);
55     $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
56 }
57