Jonathan Druart
31c29fd31f
Note: This is here for information purpose, feel free to test it if you wan to play with it. TODO: C4::Reserves::_get_itype is not longer in use No more GetItem must be returned by: git grep GetItem|grep -v GetItemsAvailableToFillHoldRequestsForBib|grep -v GetItemsForInventory|grep -v GetItemsInfo|grep -v GetItemsLocationInfo|grep -v GetItemsInCollection|grep -v GetItemCourseReservesInfo|grep -v GetItemnumbersFromOrder|grep -v GetItemSearchField|grep -v GetItemTypesCategorized|grep -v GetItemNumbersFromImportBatch|cut -d':' -f1|sort|uniq Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
170 lines
4.1 KiB
Perl
170 lines
4.1 KiB
Perl
#!/usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
|
|
use C4::Circulation;
|
|
use Koha::Database;
|
|
use Koha::Items;
|
|
|
|
use t::lib::TestBuilder;
|
|
use t::lib::Mocks;
|
|
|
|
use Test::More tests => 9;
|
|
use Test::MockModule;
|
|
|
|
BEGIN {
|
|
use_ok('C4::Items');
|
|
}
|
|
|
|
my $builder = t::lib::TestBuilder->new();
|
|
my $schema = Koha::Database->new->schema;
|
|
# Begin transaction
|
|
$schema->storage->txn_begin;
|
|
|
|
my $branch = $builder->build(
|
|
{
|
|
source => 'Branch',
|
|
}
|
|
);
|
|
|
|
my $module = new Test::MockModule('C4::Context');
|
|
$module->mock('userenv', sub {
|
|
{ flags => 0,
|
|
branch => $branch->{branchcode}
|
|
}
|
|
});
|
|
|
|
my $branch2 = $builder->build(
|
|
{
|
|
source => 'Branch',
|
|
}
|
|
);
|
|
|
|
my $category = $builder->build(
|
|
{
|
|
source => 'Category',
|
|
}
|
|
);
|
|
|
|
my $patron = $builder->build(
|
|
{
|
|
source => 'Borrower',
|
|
value => {
|
|
categorycode => $category->{categorycode},
|
|
branchcode => $branch->{branchcode},
|
|
},
|
|
}
|
|
);
|
|
|
|
my $biblio = $builder->build(
|
|
{
|
|
source => 'Biblio',
|
|
value => {
|
|
branchcode => $branch->{branchcode},
|
|
},
|
|
}
|
|
);
|
|
|
|
my $item = $builder->build(
|
|
{
|
|
source => 'Item',
|
|
value => {
|
|
biblionumber => $biblio->{biblionumber},
|
|
homebranch => $branch->{branchcode},
|
|
holdingbranch => $branch->{branchcode},
|
|
withdrawn => 0, # randomly assigned value may block return.
|
|
withdrawn_on => undef,
|
|
},
|
|
}
|
|
);
|
|
|
|
# book_on_loan
|
|
|
|
AddIssue( $patron, $item->{barcode} );
|
|
|
|
is(
|
|
ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'book_on_loan',
|
|
'ItemSafeToDelete reports item on loan',
|
|
);
|
|
|
|
is(
|
|
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'book_on_loan',
|
|
'item that is on loan cannot be deleted',
|
|
);
|
|
|
|
AddReturn( $item->{barcode}, $branch->{branchcode} );
|
|
|
|
# book_reserved is tested in t/db_dependent/Reserves.t
|
|
|
|
# not_same_branch
|
|
t::lib::Mocks::mock_preference('IndependentBranches', 1);
|
|
ModItem( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
|
|
|
|
is(
|
|
ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'not_same_branch',
|
|
'ItemSafeToDelete reports IndependentBranches restriction',
|
|
);
|
|
|
|
is(
|
|
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'not_same_branch',
|
|
'IndependentBranches prevents deletion at another branch',
|
|
);
|
|
|
|
ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
|
|
|
|
# linked_analytics
|
|
|
|
{ # codeblock to limit scope of $module->mock
|
|
|
|
my $module = Test::MockModule->new('C4::Items');
|
|
$module->mock( GetAnalyticsCount => sub { return 1 } );
|
|
|
|
is(
|
|
ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'linked_analytics',
|
|
'ItemSafeToDelete reports linked analytics',
|
|
);
|
|
|
|
is(
|
|
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
'linked_analytics',
|
|
'Linked analytics prevents deletion of item',
|
|
);
|
|
|
|
}
|
|
|
|
is(
|
|
ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
|
|
1,
|
|
'ItemSafeToDelete shows item safe to delete'
|
|
);
|
|
|
|
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
|
|
|
|
my $test_item = Koha::Items->find( $item->{itemnumber} );
|
|
|
|
is( $test_item, undef,
|
|
"DelItemCheck should delete item if ItemSafeToDelete returns true"
|
|
);
|
|
|
|
$schema->storage->txn_rollback;
|
|
|