use Modern::Perl;
-use Test::More tests => 57;
+use Test::More tests => 58;
use Data::Dumper;
use C4::Calendar qw( new insert_single_holiday );
use C4::Members;
use C4::Circulation qw( AddIssue AddReturn );
use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Items;
use Koha::Holds;
use Koha::CirculationRules;
# Frst branch from StaticHoldsQueueWeight
test_queue ('take from lowest cost branch', 0, $borrower_branchcode, $other_branches[0]);
test_queue ('take from lowest cost branch', 1, $borrower_branchcode, $least_cost_branch_code);
-my $queue = C4::HoldsQueue::GetHoldsQueueItems($least_cost_branch_code) || [];
+my $queue = C4::HoldsQueue::GetHoldsQueueItems({ branchlmit => $least_cost_branch_code}) || [];
my $queue_item = $queue->[0];
ok( $queue_item
&& $queue_item->{pickbranch} eq $borrower_branchcode
is( $queue_rs->count(), 1,
"Hold queue contains one hold" );
is(
- $queue_rs->next->borrowernumber,
+ $queue_rs->next->borrowernumber->borrowernumber,
$local_patron->borrowernumber,
"We should pick the local hold over the next available"
);
is( $queue_rs->count(), 1,
"Hold queue contains one hold" );
is(
- $q->borrowernumber,
+ $q->borrowernumber->borrowernumber,
$local_patron->borrowernumber,
"We should pick the local hold over the next available"
);
is( $queue_rs->count(), 1,
"Hold queue contains one hold" );
is(
- $q->borrowernumber,
+ $q->borrowernumber->borrowernumber,
$local_patron->borrowernumber,
"We should pick the local hold over the next available"
);
is( $queue_rs->count(), 1,
"Hold queue contains one hold" );
is(
- $q->borrowernumber,
+ $q->borrowernumber->borrowernumber,
$local_patron->borrowernumber,
"We should pick the local hold over the next available"
);
my $queue_rs = $schema->resultset('TmpHoldsqueue');
my $next = $queue_rs->next;
is($queue_rs->count, 1, 'Only 1 patron queueud' );
- is($next->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
+ is($next->borrowernumber->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
my $item2 = $builder->build_sample_item(
{
$queue_rs = $schema->resultset('TmpHoldsqueue');
is( $queue_rs->count, 2, '2 patrons queued' );
$next = $queue_rs->next;
- is($next->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
+ is($next->borrowernumber->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
$next = $queue_rs->next;
- is($next->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
+ is($next->borrowernumber->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
$item1->exclude_from_local_holds_priority(1)->store;
$queue_rs = $schema->resultset('TmpHoldsqueue');
is( $queue_rs->count, 2, '2 patrons queued' );
$next = $queue_rs->next;
- is($next->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
+ is($next->borrowernumber->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
$next = $queue_rs->next;
- is($next->borrowernumber, $local_patron_excluded->borrowernumber, 'Excluded local patron is queued');
+ is($next->borrowernumber->borrowernumber, $local_patron_excluded->borrowernumber, 'Excluded local patron is queued');
};
# Cleanup
$schema->storage->txn_rollback;
$schema->storage->txn_rollback;
};
+
+subtest "GetHoldsQueueItems" => sub {
+ plan tests => 4;
+
+ $schema->storage->txn_begin;
+
+ my $ccode = $builder->build_object(
+ {
+ class => 'Koha::AuthorisedValues',
+ value => {
+ category => 'CCODE'
+ }
+ }
+ );
+ my $location = $builder->build_object(
+ {
+ class => 'Koha::AuthorisedValues',
+ value => {
+ category => 'LOC'
+ }
+ }
+ );
+ my $item_1 = $builder->build_sample_item();
+ my $item_2 = $builder->build_sample_item(
+ {
+ itype => $item_1->itype,
+ ccode => $ccode->authorised_value
+ }
+ );
+ my $item_3 = $builder->build_sample_item(
+ {
+ itype => $item_1->itype,
+ ccode => $item_2->ccode,
+ location => $location->authorised_value
+ }
+ );
+
+ my $itemnumber_1 = $item_1->itemnumber;
+ my $itemnumber_2 = $item_2->itemnumber;
+ my $itemnumber_3 = $item_3->itemnumber;
+
+ my $biblionumber_1 = $item_1->biblionumber;
+ my $biblionumber_2 = $item_2->biblionumber;
+ my $biblionumber_3 = $item_3->biblionumber;
+
+ my $sth = $dbh->prepare(q{ SELECT COUNT(*) FROM tmp_holdsqueue });
+ $sth->execute();
+ my ($count) = $sth->fetchrow_array;
+
+ $dbh->do( "
+ INSERT INTO tmp_holdsqueue (itemnumber,biblionumber,surname,firstname,phone,borrowernumber,title,notes) VALUES
+ ($itemnumber_1,$biblionumber_1,'','','',22,'',''),
+ ($itemnumber_2,$biblionumber_2,'','','',32,'',''),
+ ($itemnumber_3,$biblionumber_3,'','','',42,'','')
+ " );
+
+ my $queue_items = GetHoldsQueueItems();
+ is( scalar @$queue_items, $count + 3, 'Three items added to queue' );
+
+ $queue_items = GetHoldsQueueItems( { itemtypeslimit => $item_1->itype } );
+ is( scalar @$queue_items,
+ 3, 'Three items of same itemtype found when itemtypeslimit passed' );
+
+ $queue_items = GetHoldsQueueItems(
+ { itemtypeslimit => $item_1->itype, ccodeslimit => $item_2->ccode } );
+ is( scalar @$queue_items,
+ 2, 'Two items of same collection found when ccodeslimit passed' );
+
+ @$queue_items = GetHoldsQueueItems(
+ {
+ itemtypeslimit => $item_1->itype,
+ ccodeslimit => $item_2->ccode,
+ locationslimit => $item_3->location
+ }
+ );
+ is( scalar @$queue_items,
+ 1, 'One item of shleving location found when locationslimit passed' );
+
+ $schema->storage->txn_rollback;
+};