3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 11;
26 use_ok( "C4::Utils::DataTables::Members" );
28 my $dbh = C4::Context->dbh;
32 $dbh->{AutoCommit} = 0;
33 $dbh->{RaiseError} = 1;
35 # Pick a categorycode from the DB
36 my @categories = C4::Category->all;
37 my $categorycode = $categories[0]->categorycode;
38 # Add a new branch so we control what borrowers it has
39 my $branchcode = "UNC";
42 branchcode => $branchcode,
43 branchname => 'Universidad Nacional de Cordoba',
44 branchaddress1 => 'Haya de la Torre',
45 branchaddress2 => 'S/N',
47 branchcity => 'Cordoba',
48 branchstate => 'Cordoba',
49 branchcountry => 'Argentina'
51 ModBranch( $branch_data );
54 cardnumber => '123456',
57 categorycode => $categorycode,
58 branchcode => $branchcode,
60 dateexpiry => '9999-12-31',
65 cardnumber => '234567',
68 categorycode => $categorycode,
69 branchcode => $branchcode,
71 dateexpiry => '9999-12-31',
72 userid => 'john.smith'
76 cardnumber => '345678',
79 categorycode => $categorycode,
80 branchcode => $branchcode,
82 dateexpiry => '9999-12-31',
86 $res = AddMember( %john_doe );
87 warn "Error adding John Doe, check your tests" unless $res;
88 $res = AddMember( %john_smith );
89 warn "Error adding John Smith, check your tests" unless $res;
90 $res = AddMember( %jane_doe );
91 warn "Error adding Jane Doe, check your tests" unless $res;
93 # Set common datatables params
100 my $search_results = C4::Utils::DataTables::Members::search({
101 searchmember => "John Doe",
102 searchfieldstype => 'standard',
103 searchtype => 'contains',
104 branchcode => $branchcode,
105 dt_params => \%dt_params
108 is( $search_results->{ iTotalDisplayRecords }, 1,
109 "John Doe has only one match on $branchcode (Bug 12595)");
111 ok( $search_results->{ patrons }[0]->{ cardnumber } eq $john_doe{ cardnumber }
112 && ! $search_results->{ patrons }[1],
113 "John Doe is the only match (Bug 12595)");
116 $search_results = C4::Utils::DataTables::Members::search({
117 searchmember => "Jane Doe",
118 searchfieldstype => 'standard',
119 searchtype => 'contains',
120 branchcode => $branchcode,
121 dt_params => \%dt_params
124 is( $search_results->{ iTotalDisplayRecords }, 1,
125 "Jane Doe has only one match on $branchcode (Bug 12595)");
127 is( $search_results->{ patrons }[0]->{ cardnumber },
128 $jane_doe{ cardnumber },
129 "Jane Doe is the only match (Bug 12595)");
132 $search_results = C4::Utils::DataTables::Members::search({
133 searchmember => "John",
134 searchfieldstype => 'standard',
135 searchtype => 'contains',
136 branchcode => $branchcode,
137 dt_params => \%dt_params
140 is( $search_results->{ iTotalDisplayRecords }, 2,
141 "There are two John at $branchcode");
143 is( $search_results->{ patrons }[0]->{ cardnumber },
144 $john_doe{ cardnumber },
145 "John Doe is the first result");
147 is( $search_results->{ patrons }[1]->{ cardnumber },
148 $john_smith{ cardnumber },
149 "John Smith is the second result");
152 $search_results = C4::Utils::DataTables::Members::search({
153 searchmember => "Doe",
154 searchfieldstype => 'standard',
155 searchtype => 'contains',
156 branchcode => $branchcode,
157 dt_params => \%dt_params
160 is( $search_results->{ iTotalDisplayRecords }, 2,
161 "There are two Doe at $branchcode");
163 is( $search_results->{ patrons }[0]->{ cardnumber },
164 $john_doe{ cardnumber },
165 "John Doe is the first result");
167 is( $search_results->{ patrons }[1]->{ cardnumber },
168 $jane_doe{ cardnumber },
169 "Jane Doe is the second result");