Bugzilla – Attachment 101186 Details for
Bug 23463
Move C4::Items CRUD subroutines to Koha::Item
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23463: Move DelItem.t and Items_DelItemCheck.t tests to a Koha/Item.t subtest
Bug-23463-Move-DelItemt-and-ItemsDelItemCheckt-tes.patch (text/plain), 9.54 KB, created by
Jonathan Druart
on 2020-03-20 14:51:59 UTC
(
hide
)
Description:
Bug 23463: Move DelItem.t and Items_DelItemCheck.t tests to a Koha/Item.t subtest
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-20 14:51:59 UTC
Size:
9.54 KB
patch
obsolete
>From c13f2a8b701f2ef07405363559ac309414d9f2d0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 27 Jan 2020 17:20:26 +0100 >Subject: [PATCH] Bug 23463: Move DelItem.t and Items_DelItemCheck.t tests to a > Koha/Item.t subtest > >Signed-off-by: Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > t/db_dependent/Items/DelItem.t | 35 ------ > t/db_dependent/Items_DelItemCheck.t | 171 ---------------------------- > t/db_dependent/Koha/Item.t | 110 +++++++++++++++++- > 3 files changed, 109 insertions(+), 207 deletions(-) > delete mode 100644 t/db_dependent/Items/DelItem.t > delete mode 100644 t/db_dependent/Items_DelItemCheck.t > >diff --git a/t/db_dependent/Items/DelItem.t b/t/db_dependent/Items/DelItem.t >deleted file mode 100644 >index 6b778ddaf8..0000000000 >--- a/t/db_dependent/Items/DelItem.t >+++ /dev/null >@@ -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." ); >diff --git a/t/db_dependent/Items_DelItemCheck.t b/t/db_dependent/Items_DelItemCheck.t >deleted file mode 100644 >index b25be149da..0000000000 >--- a/t/db_dependent/Items_DelItemCheck.t >+++ /dev/null >@@ -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; >- >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index 3a2d2a8c67..5485a7df37 100644 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -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; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23463
:
95899
|
95900
|
95901
|
95902
|
95903
|
95904
|
95905
|
95906
|
95907
|
95908
|
95909
|
95910
|
95911
|
95912
|
95913
|
95914
|
95915
|
95916
|
95917
|
95918
|
95919
|
95920
|
95921
|
95922
|
95923
|
95925
|
96145
|
97895
|
97896
|
97897
|
97898
|
97899
|
97900
|
97901
|
97902
|
97903
|
97904
|
97905
|
97906
|
97907
|
97908
|
97909
|
97910
|
97911
|
97912
|
97913
|
97914
|
97915
|
97916
|
97917
|
97918
|
97919
|
97920
|
97921
|
101151
|
101152
|
101153
|
101154
|
101156
|
101157
|
101158
|
101161
|
101163
|
101165
|
101167
|
101169
|
101170
|
101171
|
101172
|
101173
|
101174
|
101175
|
101176
|
101177
|
101178
|
101179
|
101180
|
101181
|
101182
|
101183
|
101184
|
101185
|
101186
|
101188
|
101189
|
101190
|
101191
|
101192
|
101193
|
101194
|
101195
|
101196
|
101197
|
101246
|
101247
|
101248
|
101249
|
101250
|
101251
|
101252
|
101253
|
101254
|
101255
|
101256
|
101257
|
101258
|
101259
|
101260
|
101261
|
101262
|
101263
|
101264
|
101265
|
101266
|
101267
|
101268
|
101269
|
101270
|
101271
|
101272
|
101273
|
101274
|
101275
|
101276
|
101277
|
101278
|
101279
|
101280
|
101281
|
101282
|
101283
|
101284
|
101413
|
101414
|
101415
|
101416
|
101432
|
101476
|
102071
|
103129
|
113581