use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 6;
+
use Test::Exception;
+use Test::MockModule;
+
use MARC::Field;
use C4::Items;
-use C4::Biblio;
-use C4::Reserves;
+use C4::Biblio qw( AddBiblio ModBiblio );
+use C4::Reserves qw( AddReserve );
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Biblios;
subtest 'holds + current_holds' => sub {
plan tests => 5;
- C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber );
+ C4::Reserves::AddReserve(
+ {
+ branchcode => $patron->branchcode,
+ borrowernumber => $patron->borrowernumber,
+ biblionumber => $biblio->biblionumber,
+ }
+ );
my $holds = $biblio->holds;
is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' );
is( $holds->count, 1, '->holds should only return 1 hold' );
$holds->delete;
# Add a hold in the future
- C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber, undef, undef, dt_from_string->add( days => 2 ) );
+ C4::Reserves::AddReserve(
+ {
+ branchcode => $patron->branchcode,
+ borrowernumber => $patron->borrowernumber,
+ biblionumber => $biblio->biblionumber,
+ reservation_date => dt_from_string->add( days => 2 ),
+ }
+ );
$holds = $biblio->holds;
is( $holds->count, 1, '->holds should return future holds' );
$holds = $biblio->current_holds;
subtest 'waiting_or_in_transit' => sub {
plan tests => 4;
- my $biblio = $builder->build( { source => 'Biblio' } );
- my $item = $builder->build({
- source => 'Item',
- value => {
- biblionumber => $biblio->{biblionumber}
- }
- });
+ my $item = $builder->build_sample_item;
my $reserve = $builder->build({
source => 'Reserve',
value => {
- biblionumber => $biblio->{biblionumber},
+ biblionumber => $item->biblionumber,
found => undef
}
});
$reserve = Koha::Holds->find($reserve->{reserve_id});
- $biblio = Koha::Biblios->find($biblio->{biblionumber});
+ $biblio = $item->biblio;
is($biblio->has_items_waiting_or_intransit, 0, 'Item is neither waiting nor in transit');
my $transfer = $builder->build({
source => 'Branchtransfer',
value => {
- itemnumber => $item->{itemnumber},
- datearrived => undef
+ itemnumber => $item->itemnumber,
+ datearrived => undef,
+ datecancelled => undef,
}
});
my $t = Koha::Database->new()->schema()->resultset( 'Branchtransfer' )->find($transfer->{branchtransfer_id});
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
- my ($item_bibnum, $item_bibitemnum, $itemnumber)
- = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber);
- my $item = Koha::Items->find($itemnumber);
+ my $item = $builder->build_sample_item(
+ {
+ biblionumber => $biblio->biblionumber,
+ library => $library1->branchcode
+ }
+ );
is(Koha::Item::Transfer::Limits->search({
fromBranch => $library1->branchcode,
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
.'items is already located at to-library, then the transfer is possible.');
$item->holdingbranch($library1->branchcode)->store;
- my ($item_bibnum2, $item_bibitemnum2, $itemnumber2)
- = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $biblio->biblionumber);
- my $item2 = Koha::Items->find($itemnumber2);
+
+ my $item2 = $builder->build_sample_item(
+ {
+ biblionumber => $biblio->biblionumber,
+ homebranch => $library1->branchcode,
+ holdingbranch => $library3->branchcode,
+ }
+ );
is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
.'another item that should have no transfer limits applying on, then '
.'the transfer is possible.');
};
subtest 'custom_cover_image_url' => sub {
- plan tests => 3;
+ plan tests => 4;
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' );
my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn);
is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" );
+
+ $biblio->biblioitem->isbn('')->store;
+ is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
+
};
$schema->storage->txn_rollback;
+
+subtest 'pickup_locations() tests' => sub {
+
+ plan tests => 1;
+
+ $schema->storage->txn_begin;
+
+ # Build 8 libraries
+ my $l_1 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_2 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_3 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_4 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_5 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_6 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_7 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+ my $l_8 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
+
+ # Mock Koha::Item->pickup_locations so we have control on the output
+ # The $switch variable controls the output.
+ my $switch = 0;
+ my $queries = [
+ { branchcode => [ $l_1->branchcode, $l_2->branchcode ] },
+ { branchcode => [ $l_3->branchcode, $l_4->branchcode ] },
+ { branchcode => [ $l_5->branchcode, $l_6->branchcode ] },
+ { branchcode => [ $l_7->branchcode, $l_8->branchcode ] }
+ ];
+
+ my $mock_item = Test::MockModule->new('Koha::Item');
+ $mock_item->mock(
+ 'pickup_locations',
+ sub {
+ my $query = $queries->[$switch];
+ $switch++;
+ return Koha::Libraries->search($query);
+ }
+ );
+
+ # Two biblios
+ my $biblio_1 = $builder->build_sample_biblio;
+ my $biblio_2 = $builder->build_sample_biblio;
+
+ # Two items each
+ my $item_1_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber });
+ my $item_1_2 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber });
+ my $item_2_1 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber });
+ my $item_2_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber });
+
+ my $biblios = Koha::Biblios->search(
+ {
+ biblionumber => [ $biblio_1->biblionumber, $biblio_2->biblionumber ]
+ }
+ );
+
+ my $library_ids = [
+ Koha::Libraries->search(
+ {
+ branchcode => [
+ $l_1->branchcode, $l_2->branchcode, $l_3->branchcode,
+ $l_4->branchcode, $l_5->branchcode, $l_6->branchcode,
+ $l_7->branchcode, $l_8->branchcode
+ ]
+ },
+ { order_by => ['branchname'] }
+ )->_resultset->get_column('branchcode')->all
+ ];
+
+ my $pickup_locations_ids = [
+ $biblios->pickup_locations->_resultset->get_column('branchcode')->all
+ ];
+
+ is_deeply(
+ $library_ids,
+ $pickup_locations_ids,
+ 'The addition of all biblios+items pickup locations is returned'
+ );
+
+ $schema->storage->txn_rollback;
+};