Lines 18-28
Link Here
|
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use Test::More tests => 6; |
|
|
22 |
|
21 |
|
23 |
use Koha::AuthorisedValues; |
22 |
use Test::More tests => 7; |
|
|
23 |
use t::lib::TestBuilder; |
24 |
|
24 |
|
25 |
$| = 1; |
25 |
use C4::Biblio qw(AddBiblio); |
|
|
26 |
use C4::Reserves; |
27 |
use Koha::AuthorisedValues; |
28 |
use Koha::Biblios; |
29 |
use Koha::Database; |
30 |
use MARC::Record; |
26 |
|
31 |
|
27 |
BEGIN { |
32 |
BEGIN { |
28 |
use_ok('C4::Context'); |
33 |
use_ok('C4::Context'); |
Lines 33-48
BEGIN {
Link Here
|
33 |
|
38 |
|
34 |
can_ok('C4::Items','GetItemsForInventory'); |
39 |
can_ok('C4::Items','GetItemsForInventory'); |
35 |
|
40 |
|
36 |
my $dbh = C4::Context->dbh; |
41 |
my $schema = Koha::Database->new->schema; |
37 |
$dbh->{AutoCommit} = 0; |
42 |
my $builder = t::lib::TestBuilder->new; |
38 |
$dbh->{RaiseError} = 1; |
43 |
|
|
|
44 |
subtest 'Old version is unchanged' => sub { |
45 |
|
46 |
plan tests => 1; |
47 |
|
48 |
$schema->storage->txn_begin; |
49 |
|
50 |
my $dbh = $schema->storage->dbh; |
51 |
|
52 |
my ($oldResults, $oldCount) = OldWay($dbh); |
53 |
my ($newResults, $newCount) = GetItemsForInventory; |
54 |
|
55 |
is_deeply($newResults,$oldResults,"Inventory results unchanged."); |
56 |
|
57 |
$schema->storage->txn_rollback; |
58 |
}; |
59 |
|
60 |
subtest 'Skip items with waiting holds' => sub { |
61 |
|
62 |
plan tests => 5; |
63 |
|
64 |
$schema->storage->txn_begin; |
65 |
|
66 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
67 |
my $itemtype |
68 |
= $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); |
69 |
my $patron = $builder->build_object( |
70 |
{ class => 'Koha::Patrons', value => { branchcode => $library->id } } ); |
71 |
|
72 |
my $title_1 = 'Title 1'; |
73 |
my $title_2 = 'Title 2'; |
39 |
|
74 |
|
40 |
my ($oldResults, $oldCount) = OldWay($dbh); |
75 |
my $biblio_1 = create_helper_biblio( $itemtype->itemtype, $title_1 ); |
41 |
my ($newResults, $newCount) = GetItemsForInventory; |
76 |
my $biblio_2 = create_helper_biblio( $itemtype->itemtype, $title_2 ); |
42 |
|
77 |
|
43 |
is_deeply($newResults,$oldResults,"Inventory results unchanged."); |
78 |
my ( $items_1, $first_items_count ) = GetItemsForInventory(); |
|
|
79 |
is( scalar @{$items_1}, $first_items_count, 'Results and count match' ); |
44 |
|
80 |
|
45 |
$dbh->rollback; |
81 |
# Add two items, so we don't depend on existing data |
|
|
82 |
my $item_1 = $builder->build_object( |
83 |
{ class => 'Koha::Items', |
84 |
value => { |
85 |
biblionumber => $biblio_1->biblionumber, |
86 |
biblioitemnumber => $biblio_1->biblioitem->biblioitemnumber, |
87 |
homebranch => $library->id, |
88 |
holdingbranch => $library->id, |
89 |
itype => $itemtype->itemtype, |
90 |
} |
91 |
} |
92 |
); |
93 |
|
94 |
my $item_2 = $builder->build_object( |
95 |
{ class => 'Koha::Items', |
96 |
value => { |
97 |
biblionumber => $biblio_2->biblionumber, |
98 |
biblioitemnumber => $biblio_2->biblioitem->biblioitemnumber, |
99 |
homebranch => $library->id, |
100 |
holdingbranch => $library->id, |
101 |
itype => $itemtype->itemtype, |
102 |
} |
103 |
} |
104 |
); |
105 |
|
106 |
my ( $items_2, $second_items_count ) = GetItemsForInventory(); |
107 |
is( scalar @{$items_2}, $second_items_count, 'Results and count match' ); |
108 |
is( $first_items_count + 2, $second_items_count, 'Two items added, count makes sense' ); |
109 |
|
110 |
# Add a waiting hold |
111 |
my $reserve_id |
112 |
= C4::Reserves::AddReserve( $library->branchcode, $patron->borrowernumber, |
113 |
$item_1->biblionumber, '', 1, undef, undef, '', "title for fee", |
114 |
$item_1->itemnumber, 'W' ); |
115 |
|
116 |
my ( $new_items, $new_items_count ) = GetItemsForInventory( { ignore_waiting_holds => 1 } ); |
117 |
is( $new_items_count, $first_items_count + 1, 'Item on hold skipped, count makes sense' ); |
118 |
is( $new_items->[ scalar @{$new_items} - 1 ]->{title}, |
119 |
$title_2, 'Item on hold skipped, last item is the correct one' ); |
120 |
|
121 |
$schema->storage->txn_rollback; |
122 |
}; |
46 |
|
123 |
|
47 |
sub OldWay { |
124 |
sub OldWay { |
48 |
my ($tdbh) = @_; |
125 |
my ($tdbh) = @_; |
Lines 161-163
sub OldWay {
Link Here
|
161 |
|
238 |
|
162 |
return (\@results, $iTotalRecords); |
239 |
return (\@results, $iTotalRecords); |
163 |
} |
240 |
} |
164 |
- |
241 |
|
|
|
242 |
# Helper method to set up a Biblio. |
243 |
sub create_helper_biblio { |
244 |
my $itemtype = shift; |
245 |
my $title = shift; |
246 |
my $record = MARC::Record->new(); |
247 |
|
248 |
$record->append_fields( |
249 |
MARC::Field->new( '245', ' ', ' ', a => $title ), |
250 |
MARC::Field->new( '942', ' ', ' ', c => $itemtype ), |
251 |
); |
252 |
|
253 |
my $biblio_id = AddBiblio( $record, '' ); |
254 |
|
255 |
return Koha::Biblios->find($biblio_id); |
256 |
} |