use Modern::Perl;
-use Test::More tests => 10;
+use Test::More tests => 9;
use C4::Biblio;
use C4::Context;
isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly creates Koha::Objects." );
-subtest 'pickup_locations' => sub {
- plan tests => 2;
-
- Koha::CirculationRules->set_rules(
- {
- branchcode => undef,
- itemtype => undef,
- rules => {
- holdallowed => 2,
- hold_fulfillment_policy => 'any',
- returnbranch => 'any'
- }
- }
- );
-
- my $from = Koha::Library->new({
- branchcode => 'zzzfrom',
- branchname => 'zzzfrom',
- branchnotes => 'zzzfrom',
- })->store;
- my $to = Koha::Library->new({
- branchcode => 'zzzto',
- branchname => 'zzzto',
- branchnotes => 'zzzto',
- })->store;
-
-
- my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
- my $itemtype = $biblio->itemtype;
- my $item_info = {
- biblionumber => $biblio->biblionumber,
- library => $from->branchcode,
- itype => $itemtype
- };
- my $item1 = $builder->build_sample_item({%$item_info});
- my $item2 = $builder->build_sample_item({%$item_info});
- my $item3 = $builder->build_sample_item({%$item_info});
- my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $from->branchcode } } );
-
- subtest 'UseBranchTransferLimits = OFF' => sub {
- plan tests => 5;
-
- t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
- t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- Koha::Item::Transfer::Limits->delete;
- Koha::Item::Transfer::Limit->new({
- fromBranch => $from->branchcode,
- toBranch => $to->branchcode,
- itemtype => $biblio->itemtype,
- })->store;
- my $total_pickup = Koha::Libraries->search({
- pickup_location => 1
- })->count;
- my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
- .'preference UseBranchTransferLimits is switched OFF,');
- is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
- .'equal number of libraries with pickup_location => 1');
-
- t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- is(@{$pickup}, $total_pickup, '...when '
- .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
- t::lib::Mocks::mock_preference('item-level_itypes', 0);
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- is(@{$pickup}, $total_pickup, '...as well as when '
- .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
- t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- is(@{$pickup}, $total_pickup, '...as well as when '
- .'BranchTransferLimitsType = ccode');
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- };
-
- subtest 'UseBranchTransferLimits = ON' => sub {
- plan tests => 4;
- t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
-
- is(C4::Context->preference('UseBranchTransferLimits'), 1, 'Given system '
- .'preference UseBranchTransferLimits is switched ON,');
-
- subtest 'Given BranchTransferLimitsType = itemtype and '
- .'item-level_itypes = ON' => sub {
- plan tests => 11;
-
- t::lib::Mocks::mock_preference('BranchTransferLimitsType','itemtype');
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- Koha::Item::Transfer::Limits->delete;
- my $limit = Koha::Item::Transfer::Limit->new({
- fromBranch => $from->branchcode,
- toBranch => $to->branchcode,
- itemtype => $item1->effective_itemtype,
- })->store;
- ok($item1->effective_itemtype eq $item2->effective_itemtype
- && $item1->effective_itemtype eq $item3->effective_itemtype,
- 'Given all items of a biblio have same the itemtype,');
- is($limit->itemtype, $item1->effective_itemtype, 'and given there '
- .'is an existing transfer limit for that itemtype,');
- my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- my $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'Then the to-library of which the limit applies for, '
- .'is not included in the list of pickup libraries.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'The same applies when asking pickup locations of '
- .'a single item.');
- my $others = Koha::Libraries->search({
- pickup_location => 1,
- branchcode => { 'not in' => [$limit->toBranch] }})->count;
- is(@{$pickup}, $others, 'However, the number of other pickup '
- .'libraries is correct.');
- $item2->itype('BK')->store;
- ok($item1->effective_itemtype ne $item2->effective_itemtype,
- 'Given one of the item in this biblio has a different itemtype,');
- is(Koha::Item::Transfer::Limits->search({
- itemtype => $item2->effective_itemtype })->count, 0, 'and it is'
- .' not restricted by transfer limits,');
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Then the to-library of which the limit applies for, '
- .'is included in the list of pickup libraries.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item2, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'The same applies when asking pickup locations of '
- .'a that particular item.');
- Koha::Item::Transfer::Limits->delete;
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Given we deleted transfer limit, the previously '
- .'transfer-limited library is included in the list.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'The same applies when asking pickup locations of '
- .'a single item.');
- };
-
- subtest 'Given BranchTransferLimitsType = itemtype and '
- .'item-level_itypes = OFF' => sub {
- plan tests => 9;
-
- t::lib::Mocks::mock_preference('BranchTransferLimitsType','itemtype');
- t::lib::Mocks::mock_preference('item-level_itypes', 0);
- $biblio->biblioitem->itemtype('BK')->store;
- Koha::Item::Transfer::Limits->delete;
- my $limit = Koha::Item::Transfer::Limit->new({
- fromBranch => $from->branchcode,
- toBranch => $to->branchcode,
- itemtype => $item1->effective_itemtype,
- })->store;
-
- ok($item1->effective_itemtype eq 'BK',
- 'Given items use biblio-level itemtype,');
- is($limit->itemtype, $item1->effective_itemtype, 'and given there '
- .'is an existing transfer limit for that itemtype,');
- my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- my $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'Then the to-library of which the limit applies for, '
- .'is not included in the list of pickup libraries.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'The same applies when asking pickup locations of '
- .'a single item.');
- my $others = Koha::Libraries->search({
- pickup_location => 1,
- branchcode => { 'not in' => [$limit->toBranch] }})->count;
- is(@{$pickup}, $others, 'However, the number of other pickup '
- .'libraries is correct.');
- Koha::Item::Transfer::Limits->delete;
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Given we deleted transfer limit, the previously '
- .'transfer-limited library is included in the list.');
- $limit = Koha::Item::Transfer::Limit->new({
- fromBranch => $from->branchcode,
- toBranch => $to->branchcode,
- itemtype => $item1->itype,
- })->store;
- ok($item1->itype ne $item1->effective_itemtype
- && $limit->itemtype eq $item1->itype, 'Given we have added a limit'
- .' matching ITEM-level itemtype,');
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Then the limited branch is still included as a pickup'
- .' library.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'The same applies when asking pickup locations of '
- .'a single item.');
- };
-
- subtest 'Given BranchTransferLimitsType = ccode' => sub {
- plan tests => 10;
-
- t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
- $item1->ccode('hi')->store;
- $item2->ccode('hi')->store;
- $item3->ccode('hi')->store;
- Koha::Item::Transfer::Limits->delete;
- my $limit = Koha::Item::Transfer::Limit->new({
- fromBranch => $from->branchcode,
- toBranch => $to->branchcode,
- ccode => $item1->ccode,
- })->store;
-
- is($limit->ccode, $item1->ccode, 'Given there '
- .'is an existing transfer limit for that ccode,');
- my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- my $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'Then the to-library of which the limit applies for, '
- .'is not included in the list of pickup libraries.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 0, 'The same applies when asking pickup locations of '
- .'a single item.');
- my $others = Koha::Libraries->search({
- pickup_location => 1,
- branchcode => { 'not in' => [$limit->toBranch] }})->count;
- is(@{$pickup}, $others, 'However, the number of other pickup '
- .'libraries is correct.');
- $item3->ccode('yo')->store;
- ok($item1->ccode ne $item3->ccode,
- 'Given one of the item in this biblio has a different ccode,');
- is(Koha::Item::Transfer::Limits->search({
- ccode => $item3->ccode })->count, 0, 'and it is'
- .' not restricted by transfer limits,');
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Then the to-library of which the limit applies for, '
- .'is included in the list of pickup libraries.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item3, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'The same applies when asking pickup locations of '
- .'a that particular item.');
- Koha::Item::Transfer::Limits->delete;
- $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'Given we deleted transfer limit, the previously '
- .'transfer-limited library is included in the list.');
- $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
- $found = 0;
- foreach my $lib (@{$pickup}) {
- if ($lib->{branchcode} eq $limit->toBranch) {
- $found = 1;
- }
- }
- is($found, 1, 'The same applies when asking pickup locations of '
- .'a single item.');
- };
- };
-};
-
$schema->storage->txn_rollback;
subtest '->get_effective_marcorgcode' => sub {