|
Lines 20-28
use Modern::Perl;
Link Here
|
| 20 |
|
20 |
|
| 21 |
use MARC::Record; |
21 |
use MARC::Record; |
| 22 |
use C4::Biblio; |
22 |
use C4::Biblio; |
|
|
23 |
use C4::Branch; |
| 23 |
use Koha::Database; |
24 |
use Koha::Database; |
| 24 |
|
25 |
|
| 25 |
use Test::More tests => 4; |
26 |
use Test::More tests => 5; |
| 26 |
|
27 |
|
| 27 |
BEGIN { |
28 |
BEGIN { |
| 28 |
use_ok('C4::Items'); |
29 |
use_ok('C4::Items'); |
|
Lines 38-45
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
| 38 |
$dbh->{AutoCommit} = 0; |
39 |
$dbh->{AutoCommit} = 0; |
| 39 |
$dbh->{RaiseError} = 1; |
40 |
$dbh->{RaiseError} = 1; |
| 40 |
|
41 |
|
|
|
42 |
|
| 41 |
# Helper biblio. |
43 |
# Helper biblio. |
| 42 |
diag("Creating biblio instance for testing."); |
44 |
diag("Creating biblio instance for testing."); |
|
|
45 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 43 |
my ($bibnum, $bibitemnum) = get_biblio(); |
46 |
my ($bibnum, $bibitemnum) = get_biblio(); |
| 44 |
|
47 |
|
| 45 |
# Add an item. |
48 |
# Add an item. |
|
Lines 76-83
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
| 76 |
$dbh->{RaiseError} = 1; |
79 |
$dbh->{RaiseError} = 1; |
| 77 |
|
80 |
|
| 78 |
# Create a new biblio |
81 |
# Create a new biblio |
|
|
82 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 79 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
83 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
| 80 |
|
84 |
|
|
|
85 |
# Add branches if they don't exist |
| 86 |
if (not defined GetBranchDetail('CPL')) { |
| 87 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
| 88 |
} |
| 89 |
if (not defined GetBranchDetail('MPL')) { |
| 90 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
| 91 |
} |
| 92 |
|
| 81 |
# Add two items |
93 |
# Add two items |
| 82 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
94 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
| 83 |
{ homebranch => 'CPL', |
95 |
{ homebranch => 'CPL', |
|
Lines 175-180
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
Link Here
|
| 175 |
$schema->resultset('Systempreference')->update_or_create({ variable => 'item-level_itypes', value => 1 }); |
187 |
$schema->resultset('Systempreference')->update_or_create({ variable => 'item-level_itypes', value => 1 }); |
| 176 |
ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is disabled' ); |
188 |
ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is disabled' ); |
| 177 |
|
189 |
|
|
|
190 |
$dbh->rollback; |
| 191 |
}; |
| 192 |
|
| 193 |
subtest 'SearchItems test' => sub { |
| 194 |
plan tests => 10; |
| 195 |
|
| 196 |
# Start transaction |
| 197 |
$dbh->{AutoCommit} = 0; |
| 198 |
$dbh->{RaiseError} = 1; |
| 199 |
|
| 200 |
C4::Context->set_preference('marcflavour', 'MARC21'); |
| 201 |
my ($biblionumber) = get_biblio(); |
| 202 |
|
| 203 |
# Add branches if they don't exist |
| 204 |
if (not defined GetBranchDetail('CPL')) { |
| 205 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
| 206 |
} |
| 207 |
if (not defined GetBranchDetail('MPL')) { |
| 208 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
| 209 |
} |
| 210 |
|
| 211 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
| 212 |
|
| 213 |
# Add two items |
| 214 |
my (undef, undef, $item1_itemnumber) = AddItem({ |
| 215 |
homebranch => 'CPL', |
| 216 |
holdingbranch => 'CPL', |
| 217 |
}, $biblionumber); |
| 218 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
| 219 |
homebranch => 'MPL', |
| 220 |
holdingbranch => 'MPL', |
| 221 |
}, $biblionumber); |
| 222 |
|
| 223 |
my ($items, $total_results); |
| 224 |
|
| 225 |
($items, $total_results) = SearchItems(); |
| 226 |
is($total_results, $initial_items_count + 2, "Created 2 new items"); |
| 227 |
is(scalar @$items, $total_results, "SearchItems() returns all items"); |
| 228 |
|
| 229 |
($items, $total_results) = SearchItems(undef, {rows => 1}); |
| 230 |
is($total_results, $initial_items_count + 2); |
| 231 |
is(scalar @$items, 1, "SearchItems(undef, {rows => 1}) returns only 1 item"); |
| 232 |
|
| 233 |
# Search all items where homebranch = 'CPL' |
| 234 |
my $filter = { |
| 235 |
field => 'homebranch', |
| 236 |
query => 'CPL', |
| 237 |
operator => '=', |
| 238 |
}; |
| 239 |
($items, $total_results) = SearchItems($filter); |
| 240 |
ok($total_results > 0, "There is at least one CPL item"); |
| 241 |
my $all_items_are_CPL = 1; |
| 242 |
foreach my $item (@$items) { |
| 243 |
if ($item->{homebranch} ne 'CPL') { |
| 244 |
$all_items_are_CPL = 0; |
| 245 |
last; |
| 246 |
} |
| 247 |
} |
| 248 |
ok($all_items_are_CPL, "All items returned by SearchItems are from CPL"); |
| 249 |
|
| 250 |
# Search all items where homebranch != 'CPL' |
| 251 |
$filter = { |
| 252 |
field => 'homebranch', |
| 253 |
query => 'CPL', |
| 254 |
operator => '!=', |
| 255 |
}; |
| 256 |
($items, $total_results) = SearchItems($filter); |
| 257 |
ok($total_results > 0, "There is at least one non-CPL item"); |
| 258 |
my $all_items_are_not_CPL = 1; |
| 259 |
foreach my $item (@$items) { |
| 260 |
if ($item->{homebranch} eq 'CPL') { |
| 261 |
$all_items_are_not_CPL = 0; |
| 262 |
last; |
| 263 |
} |
| 264 |
} |
| 265 |
ok($all_items_are_not_CPL, "All items returned by SearchItems are not from CPL"); |
| 266 |
|
| 267 |
# Search all items where biblio title (245$a) is like 'Silence in the %' |
| 268 |
$filter = { |
| 269 |
field => 'marc:245$a', |
| 270 |
query => 'Silence in the %', |
| 271 |
operator => 'like', |
| 272 |
}; |
| 273 |
($items, $total_results) = SearchItems($filter); |
| 274 |
ok($total_results >= 2, "There is at least 2 items with a biblio title like 'Silence in the %'"); |
| 275 |
|
| 276 |
# Search all items where biblio title is 'Silence in the library' |
| 277 |
# and homebranch is 'CPL' |
| 278 |
$filter = { |
| 279 |
conjunction => 'AND', |
| 280 |
filters => [ |
| 281 |
{ |
| 282 |
field => 'marc:245$a', |
| 283 |
query => 'Silence in the %', |
| 284 |
operator => 'like', |
| 285 |
}, |
| 286 |
{ |
| 287 |
field => 'homebranch', |
| 288 |
query => 'CPL', |
| 289 |
operator => '=', |
| 290 |
}, |
| 291 |
], |
| 292 |
}; |
| 293 |
($items, $total_results) = SearchItems($filter); |
| 294 |
my $found = 0; |
| 295 |
foreach my $item (@$items) { |
| 296 |
if ($item->{itemnumber} == $item1_itemnumber) { |
| 297 |
$found = 1; |
| 298 |
last; |
| 299 |
} |
| 300 |
} |
| 301 |
ok($found, "item1 found"); |
| 178 |
|
302 |
|
| 179 |
$dbh->rollback; |
303 |
$dbh->rollback; |
| 180 |
}; |
304 |
}; |