Bug 23463: Move DelItem.t and Items_DelItemCheck.t tests to a Koha/Item.t subtest
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>
This commit is contained in:
parent
f70a738bca
commit
794e8f992e
|
|
@ -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;
|
||||
|
||||
|
|
@ -19,12 +19,14 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
|
||||
use C4::Biblio;
|
||||
use C4::Circulation;
|
||||
|
||||
use Koha::Items;
|
||||
use Koha::Database;
|
||||
use Koha::Old::Items;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
|
@ -329,3 +331,109 @@ subtest 'pickup_locations' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'deletion' => sub {
|
||||
plan tests => 11;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $biblio = $builder->build_sample_biblio();
|
||||
|
||||
my $item = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
}
|
||||
);
|
||||
|
||||
is( ref( $item->move_to_deleted ), 'Koha::Schema::Result::Deleteditem', 'Koha::Item->move_to_deleted should return the Deleted item' )
|
||||
; # FIXME This should be Koha::Deleted::Item
|
||||
is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 1, '->move_to_deleted must have moved the item to deleteditem' );
|
||||
$item = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
}
|
||||
);
|
||||
$item->delete;
|
||||
is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 0, '->move_to_deleted must not have moved the item to deleteditem' );
|
||||
|
||||
|
||||
my $library = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
|
||||
|
||||
my $patron = $builder->build_object({class => 'Koha::Patrons'});
|
||||
$item = $builder->build_sample_item({ library => $library->branchcode });
|
||||
|
||||
# book_on_loan
|
||||
C4::Circulation::AddIssue( $patron->unblessed, $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, $library->branchcode );
|
||||
|
||||
# book_reserved is tested in t/db_dependent/Reserves.t
|
||||
|
||||
# not_same_branch
|
||||
t::lib::Mocks::mock_preference('IndependentBranches', 1);
|
||||
my $item_2 = $builder->build_sample_item({ library => $library_2->branchcode });
|
||||
|
||||
is(
|
||||
$item_2->safe_to_delete,
|
||||
'not_same_branch',
|
||||
'Koha::Item->safe_to_delete reports IndependentBranches restriction',
|
||||
);
|
||||
|
||||
is(
|
||||
$item_2->safe_delete,
|
||||
'not_same_branch',
|
||||
'IndependentBranches prevents deletion at another branch',
|
||||
);
|
||||
|
||||
# linked_analytics
|
||||
|
||||
{ # codeblock to limit scope of $module->mock
|
||||
|
||||
my $module = Test::MockModule->new('C4::Items');
|
||||
$module->mock( GetAnalyticsCount => sub { return 1 } );
|
||||
|
||||
$item->discard_changes;
|
||||
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