Allow zebra search for Accelerated Reading Point in field 526$d
[koha.git] / t / db_dependent / SQLHelper.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8 use YAML;
9
10 use C4::Debug;
11 use C4::SQLHelper qw(:all);
12
13 use Test::More tests => 19;
14
15 #1
16 BEGIN {
17     use_ok('C4::SQLHelper');
18 }
19 use C4::Category;
20 use C4::Branch;
21 my @categories=C4::Category->all;
22 my $insert;
23 ok(($insert=InsertInTable("branches",{branchcode=>"ZZZZ",branchname=>"Brancheinconnue",city=>" ",zipcode=>" "},1))==0,"AddBranch (Insert In Table with primary key defined)");
24 my $branches=C4::Branch->GetBranches;
25 my @branchcodes=keys %$branches;
26 my ($borrid, $borrtmp);
27 ok($borrid=InsertInTable("borrowers",{firstname=>"Jean",surname=>"Valjean",city=>" ",zipcode=>" ",email=>"email",categorycode=>$categories[0]->{categorycode}, branchcode=>$branchcodes[0]}),"Insert In Table");
28 $borrtmp=InsertInTable("borrowers",{firstname=>"Jean",surname=>"cocteau",city=>" ",zipcode=>" ",email=>"email",categorycode=>$categories[0]->{categorycode}, branchcode=>$branchcodes[0]});
29 ok(my $status=UpdateInTable("borrowers",{borrowernumber=>$borrid,firstname=>"Jean",surname=>"Valjean",city=>"Dampierre",zipcode=>" ",email=>"email", branchcode=>$branchcodes[1]}),"Update In Table");
30 my $borrowers=SearchInTable("borrowers");
31 #4
32 ok(@$borrowers>0, "Search In Table All values");
33 $borrowers=SearchInTable("borrowers",{borrowernumber=>$borrid});
34 #5
35 ok(@$borrowers==1, "Search In Table by primary key on table");
36 $borrowers=SearchInTable("borrowers",{firstname=>"Jean"});
37 #6
38 ok(@$borrowers>0, "Search In Table hashref");
39 $borrowers=SearchInTable("borrowers",{firstname=>"Jean"},[{firstname=>1},{borrowernumber=>1}],undef, [qw(borrowernumber)]);
40 ok(($$borrowers[0]{borrowernumber} + 0) > ($$borrowers[1]{borrowernumber} + 0), "Search In Table Order");
41 $borrowers=SearchInTable("borrowers",{firstname=>"Jean"},[{surname=>0},{firstname=>1}], undef, [qw(firstname surname)]);
42 ok(uc($$borrowers[0]{surname}) lt uc($$borrowers[1]{surname}), "Search In Table Order");
43 $borrowers=SearchInTable("borrowers","Jean");
44 #7
45 ok(@$borrowers>0, "Search In Table string");
46 eval{$borrowers=SearchInTable("borrowers","Jean Valjean")};
47 #8
48 ok(scalar(@$borrowers)==1 && !($@), "Search In Table does an implicit AND of all the words in strings");
49 $borrowers=SearchInTable("borrowers",["Valjean",{firstname=>"Jean"}]);
50 #9
51 ok(@$borrowers>0, "Search In Table arrayref");
52 $borrowers=SearchInTable("borrowers",["Valjean",{firstname=>"Jean"}],undef,undef,[qw(borrowernumber)]);
53 #10
54 ok(keys %{$$borrowers[0]} ==1, "Search In Table columns out limit");
55 $borrowers=SearchInTable("borrowers",["Valjean",{firstname=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(firstname surname title)]);
56 #11
57 ok(@$borrowers>0, "Search In Table columns out limit to borrowernumber AND filter firstname surname title");
58 $borrowers=SearchInTable("borrowers",["Valjean",{firstname=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(firstname title)]);
59 #12
60 ok(@$borrowers==0, "Search In Table columns filter firstname title limit Valjean not in other fields than surname ");
61 $borrowers=SearchInTable("borrowers",["Val",{firstname=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(surname)],"start_with");
62 #13
63 ok(@$borrowers>0, "Search In Table columns filter surname  Val on a wide search found ");
64 $borrowers=SearchInTable("borrowers",["Val",{firstname=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(surname)],"exact");
65 #14
66 ok(@$borrowers==0, "Search In Table columns filter surname  Val in exact search not found ");
67 $borrowers=eval{SearchInTable("borrowers",["Val",{member=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(firstname title)],"exact")};
68 #15
69 ok(@$borrowers==0 && !($@), "Search In Table fails gracefully when no correct field passed in hash");
70 $borrowers=eval{SearchInTable("borrowers",["Jean"],undef,undef,undef,[qw(firstname surname borrowernumber)],"start_with")};
71 ok(@$borrowers==0 && !($@), "Search In Table fails gracefully when no correct field passed in hash");
72
73 $status=DeleteInTable("borrowers",{borrowernumber=>$borrid});
74 #16
75 ok($status>0 && !($@), "DeleteInTable OK");
76 $status=DeleteInTable("borrowers",{borrowernumber=>$borrtmp});