|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 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. |
| 9 |
# |
| 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. |
| 14 |
# |
| 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>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 11; |
| 21 |
|
| 22 |
use C4::Context; |
| 23 |
use C4::Branch; |
| 24 |
use C4::Members; |
| 25 |
|
| 26 |
use Data::Printer; |
| 27 |
|
| 28 |
use_ok( "C4::Utils::DataTables::Members" ); |
| 29 |
|
| 30 |
my $dbh = C4::Context->dbh; |
| 31 |
my $res; |
| 32 |
|
| 33 |
# Start transaction |
| 34 |
$dbh->{AutoCommit} = 0; |
| 35 |
$dbh->{RaiseError} = 1; |
| 36 |
|
| 37 |
# Pick a categorycode from the DB |
| 38 |
my @categories = C4::Category->all; |
| 39 |
my $categorycode = $categories[0]->categorycode; |
| 40 |
# Add a new branch so we control what borrowers it has |
| 41 |
my $branchcode = "UNC"; |
| 42 |
my $branch_data = { |
| 43 |
add => 1, |
| 44 |
branchcode => $branchcode, |
| 45 |
branchname => 'Universidad Nacional de Cordoba', |
| 46 |
branchaddress1 => 'Haya de la Torre', |
| 47 |
branchaddress2 => 'S/N', |
| 48 |
branchzip => '5000', |
| 49 |
branchcity => 'Cordoba', |
| 50 |
branchstate => 'Cordoba', |
| 51 |
branchcountry => 'Argentina' |
| 52 |
}; |
| 53 |
ModBranch( $branch_data ); |
| 54 |
|
| 55 |
my %john_doe = ( |
| 56 |
cardnumber => '123456', |
| 57 |
firstname => 'John', |
| 58 |
surname => 'Doe', |
| 59 |
categorycode => $categorycode, |
| 60 |
branchcode => $branchcode, |
| 61 |
dateofbirth => '', |
| 62 |
dateexpiry => '9999-12-31', |
| 63 |
userid => 'john.doe' |
| 64 |
); |
| 65 |
|
| 66 |
my %john_smith = ( |
| 67 |
cardnumber => '234567', |
| 68 |
firstname => 'John', |
| 69 |
surname => 'Smith', |
| 70 |
categorycode => $categorycode, |
| 71 |
branchcode => $branchcode, |
| 72 |
dateofbirth => '', |
| 73 |
dateexpiry => '9999-12-31', |
| 74 |
userid => 'john.smith' |
| 75 |
); |
| 76 |
|
| 77 |
my %jane_doe = ( |
| 78 |
cardnumber => '345678', |
| 79 |
firstname => 'Jane', |
| 80 |
surname => 'Doe', |
| 81 |
categorycode => $categorycode, |
| 82 |
branchcode => $branchcode, |
| 83 |
dateofbirth => '', |
| 84 |
dateexpiry => '9999-12-31', |
| 85 |
userid => 'jane.doe' |
| 86 |
); |
| 87 |
|
| 88 |
$res = AddMember( %john_doe ); |
| 89 |
warn "Error adding John Doe, check your tests" unless $res; |
| 90 |
$res = AddMember( %john_smith ); |
| 91 |
warn "Error adding John Smith, check your tests" unless $res; |
| 92 |
$res = AddMember( %jane_doe ); |
| 93 |
warn "Error adding Jane Doe, check your tests" unless $res; |
| 94 |
|
| 95 |
# Search "John Doe" |
| 96 |
my $search_results = C4::Utils::DataTables::Members::search({ |
| 97 |
searchmember => "John Doe", |
| 98 |
searchfieldstype => 'standard', |
| 99 |
searchtype => 'contains', |
| 100 |
branchcode => $branchcode |
| 101 |
}); |
| 102 |
|
| 103 |
is( $search_results->{ iTotalDisplayRecords }, 1, |
| 104 |
"John Doe has only one match on $branchcode (Bug 12595)"); |
| 105 |
|
| 106 |
ok( $search_results->{ patrons }[0]->{ cardnumber } eq $john_doe{ cardnumber } |
| 107 |
&& ! $search_results->{ patrons }[1], |
| 108 |
"John Doe is the only match (Bug 12595)"); |
| 109 |
|
| 110 |
# Search "Jane Doe" |
| 111 |
$search_results = C4::Utils::DataTables::Members::search({ |
| 112 |
searchmember => "Jane Doe", |
| 113 |
searchfieldstype => 'standard', |
| 114 |
searchtype => 'contains', |
| 115 |
branchcode => $branchcode |
| 116 |
}); |
| 117 |
|
| 118 |
is( $search_results->{ iTotalDisplayRecords }, 1, |
| 119 |
"Jane Doe has only one match on $branchcode (Bug 12595)"); |
| 120 |
|
| 121 |
is( $search_results->{ patrons }[0]->{ cardnumber }, |
| 122 |
$jane_doe{ cardnumber }, |
| 123 |
"Jane Doe is the only match (Bug 12595)"); |
| 124 |
|
| 125 |
# Search "John" |
| 126 |
$search_results = C4::Utils::DataTables::Members::search({ |
| 127 |
searchmember => "John", |
| 128 |
searchfieldstype => 'standard', |
| 129 |
searchtype => 'contains', |
| 130 |
branchcode => $branchcode |
| 131 |
}); |
| 132 |
|
| 133 |
is( $search_results->{ iTotalDisplayRecords }, 2, |
| 134 |
"There are two John at $branchcode"); |
| 135 |
|
| 136 |
is( $search_results->{ patrons }[0]->{ cardnumber }, |
| 137 |
$john_doe{ cardnumber }, |
| 138 |
"John Doe is the first result"); |
| 139 |
|
| 140 |
is( $search_results->{ patrons }[1]->{ cardnumber }, |
| 141 |
$john_smith{ cardnumber }, |
| 142 |
"John Smith is the second result"); |
| 143 |
|
| 144 |
# Search "Doe" |
| 145 |
$search_results = C4::Utils::DataTables::Members::search({ |
| 146 |
searchmember => "Doe", |
| 147 |
searchfieldstype => 'standard', |
| 148 |
searchtype => 'contains', |
| 149 |
branchcode => $branchcode |
| 150 |
}); |
| 151 |
|
| 152 |
is( $search_results->{ iTotalDisplayRecords }, 2, |
| 153 |
"There are two Doe at $branchcode"); |
| 154 |
|
| 155 |
is( $search_results->{ patrons }[0]->{ cardnumber }, |
| 156 |
$john_doe{ cardnumber }, |
| 157 |
"John Doe is the first result"); |
| 158 |
|
| 159 |
is( $search_results->{ patrons }[1]->{ cardnumber }, |
| 160 |
$jane_doe{ cardnumber }, |
| 161 |
"Jane Doe is the second result"); |
| 162 |
|
| 163 |
$dbh->rollback; |
| 164 |
|
| 165 |
1; |