Browse Source
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>20.05.x
3 changed files with 109 additions and 207 deletions
@ -1,35 +0,0 @@ |
|||
use Modern::Perl; |
|||
|
|||
# FIXME This file must be removed and the test moved to Koha::Item->delete |
|||
|
|||
use MARC::Record; |
|||
use C4::Items; |
|||
use C4::Biblio; |
|||
|
|||
use Koha::Items; |
|||
|
|||
use t::lib::TestBuilder; |
|||
|
|||
use Test::More tests => 2; |
|||
|
|||
my $schema = Koha::Database->schema; |
|||
$schema->storage->txn_begin; |
|||
my $builder = t::lib::TestBuilder->new; |
|||
|
|||
my $library = $builder->build({ |
|||
source => 'Branch', |
|||
}); |
|||
|
|||
my $biblio = $builder->build_sample_biblio(); |
|||
|
|||
my $item = $builder->build_sample_item( |
|||
{ |
|||
biblionumber => $biblio->biblionumber, |
|||
library => $library->{branchcode} |
|||
} |
|||
); |
|||
|
|||
my $deleted = $item->delete; |
|||
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); |
|||
my $deleted_item = Koha::Items->find($item->itemnumber); |
|||
is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." ); |
@ -1,171 +0,0 @@ |
|||
#!/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_object( |
|||
{ |
|||
class => 'Koha::Items', |
|||
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( |
|||
$item->safe_to_delete, |
|||
'book_on_loan', |
|||
'Koha::Item->safe_to_delete reports item on loan', |
|||
); |
|||
|
|||
is( |
|||
$item->safe_delete, |
|||
'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); |
|||
$item->set( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} })->store; |
|||
|
|||
$item->discard_changes; |
|||
is( |
|||
$item->safe_to_delete, |
|||
'not_same_branch', |
|||
'Koha::Item->safe_to_delete reports IndependentBranches restriction', |
|||
); |
|||
|
|||
is( |
|||
$item->safe_delete, |
|||
'not_same_branch', |
|||
'IndependentBranches prevents deletion at another branch', |
|||
); |
|||
|
|||
$item->set( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branchcode} })->store; |
|||
|
|||
# linked_analytics |
|||
|
|||
{ # codeblock to limit scope of $module->mock |
|||
|
|||
my $module = Test::MockModule->new('C4::Items'); |
|||
$module->mock( GetAnalyticsCount => sub { return 1 } ); |
|||
|
|||
is( |
|||
$item->safe_to_delete, |
|||
'linked_analytics', |
|||
'Koha::Item->safe_to_delete reports linked analytics', |
|||
); |
|||
|
|||
is( |
|||
$item->safe_delete, |
|||
'linked_analytics', |
|||
'Linked analytics prevents deletion of item', |
|||
); |
|||
|
|||
} |
|||
|
|||
is( |
|||
$item->safe_to_delete, |
|||
1, |
|||
'Koha::Item->safe_to_delete shows item safe to delete' |
|||
); |
|||
|
|||
$item->safe_delete, |
|||
|
|||
my $test_item = Koha::Items->find( $item->itemnumber ); |
|||
|
|||
is( $test_item, undef, |
|||
"Koha::Item->safe_delete should delete item if safe_to_delete returns true" |
|||
); |
|||
|
|||
$schema->storage->txn_rollback; |
|||
|
Loading…
Reference in new issue