Bugzilla – Attachment 189100 Details for
Bug 17387
Add an undelete feature for items/biblios
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17387: (follow-up) restore tests should account for new library groups checks
Bug-17387-follow-up-restore-tests-should-account-f.patch (text/plain), 8.90 KB, created by
Jacob O'Mara
on 2025-11-05 15:40:13 UTC
(
hide
)
Description:
Bug 17387: (follow-up) restore tests should account for new library groups checks
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-11-05 15:40:13 UTC
Size:
8.90 KB
patch
obsolete
>From d57833bda32b38839b4c17f06baa8fbc6748eb9a Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Wed, 5 Nov 2025 15:14:12 +0000 >Subject: [PATCH] Bug 17387: (follow-up) restore tests should account for new > library groups checks > >--- > t/db_dependent/api/v1/deleted_biblios.t | 96 ++++++++++++++++++++++++- > t/db_dependent/api/v1/deleted_items.t | 82 +++++++++++++++++++-- > 2 files changed, 173 insertions(+), 5 deletions(-) > >diff --git a/t/db_dependent/api/v1/deleted_biblios.t b/t/db_dependent/api/v1/deleted_biblios.t >index bf9c8bccf4e..a8bd570a7b1 100755 >--- a/t/db_dependent/api/v1/deleted_biblios.t >+++ b/t/db_dependent/api/v1/deleted_biblios.t >@@ -21,7 +21,7 @@ use utf8; > use Encode; > > use Test::NoWarnings; >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::MockModule; > use Test::Mojo; > use Test::Warn; >@@ -40,6 +40,10 @@ use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Checkouts; > use Koha::Old::Checkouts; >+use Koha::Library::Groups; >+use Koha::Old::Biblioitem; >+use Koha::Old::Biblioitems; >+use Koha::Old::Biblio::Metadata; > > use Mojo::JSON qw(encode_json); > >@@ -330,3 +334,93 @@ subtest 'restore() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'restore() with library group permissions tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $librarian->borrowernumber, >+ module_bit => 13, >+ code => 'records_restore', >+ } >+ } >+ ); >+ >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ $librarian->branchcode( $library1->branchcode )->store; >+ >+ my $library_group = Koha::Library::Group->new( { title => 'Test Group', ft_limit_item_editing => 1 } )->store; >+ Koha::Library::Group->new( >+ { >+ parent_id => $library_group->id, >+ branchcode => $library1->branchcode, >+ } >+ )->store; >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $item1 = >+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber, homebranch => $library1->branchcode } ); >+ my $item2 = >+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber, homebranch => $library2->branchcode } ); >+ >+ my $biblionumber = $biblio->biblionumber; >+ my $item1_id = $item1->itemnumber; >+ my $item2_id = $item2->itemnumber; >+ >+ my $biblio_data = $biblio->unblessed; >+ my $biblioitem_data = $biblio->biblioitem->unblessed; >+ my $metadata_data = $biblio->metadata->unblessed; >+ my $item1_data = $item1->unblessed; >+ my $item2_data = $item2->unblessed; >+ >+ my $deleted_biblio = Koha::Old::Biblio->new($biblio_data)->store; >+ Koha::Old::Biblioitem->new($biblioitem_data)->store; >+ Koha::Old::Biblio::Metadata->new($metadata_data)->store; >+ Koha::Old::Item->new($item1_data)->store; >+ Koha::Old::Item->new($item2_data)->store; >+ >+ $item1->delete; >+ $item2->delete; >+ $biblio->metadata->delete; >+ $biblio->biblioitem->delete; >+ $biblio->delete; >+ >+ my $body = encode_json( { item_ids => [ $item1_id, $item2_id ] } ); >+ >+ $t->put_ok( >+ "//$userid:$password@/api/v1/deleted/biblios/$biblionumber" => { 'Content-Type' => 'application/json' } => >+ $body )->status_is(200)->json_is( '/biblio_id' => $biblionumber ) >+ ->json_is( '/restored_items/0' => $item1_id )->json_is( '/skipped_items/0' => $item2_id ); >+ >+ my $restored_biblio = Koha::Biblios->find($biblionumber); >+ ok( $restored_biblio, 'Biblio restored' ); >+ >+ my $restored_item1 = Koha::Items->find($item1_id); >+ ok( $restored_item1, 'Item from allowed library restored' ); >+ >+ my $restored_item2 = Koha::Items->find($item2_id); >+ is( $restored_item2, undef, 'Item from restricted library not restored' ); >+ >+ my $deleted_item2 = Koha::Old::Items->find($item2_id); >+ ok( $deleted_item2, 'Restricted item still in deleted table' ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/api/v1/deleted_items.t b/t/db_dependent/api/v1/deleted_items.t >index 0492cffe172..76514504cf7 100755 >--- a/t/db_dependent/api/v1/deleted_items.t >+++ b/t/db_dependent/api/v1/deleted_items.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -27,6 +27,7 @@ use t::lib::Mocks; > use Koha::Items; > use Koha::Old::Items; > use Koha::Database; >+use Koha::Library::Groups; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -162,8 +163,11 @@ subtest 'restore() tests' => sub { > $patron->set_password( { password => $password, skip_validation => 1 } ); > my $unauth_userid = $patron->userid; > >- my $item = $builder->build_sample_item( { barcode => 'TEST_RESTORE_ITEM' } ); >- my $item_id = $item->itemnumber; >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ $librarian->branchcode( $library->branchcode )->store; >+ >+ my $item = $builder->build_sample_item( { barcode => 'TEST_RESTORE_ITEM', homebranch => $library->branchcode } ); >+ my $item_id = $item->itemnumber; > my $item_data = $item->unblessed; > my $deleted_item = Koha::Old::Item->new($item_data)->store; > $item->delete; >@@ -183,7 +187,8 @@ subtest 'restore() tests' => sub { > > $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404); > >- my $item_without_biblio = $builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO' } ); >+ my $item_without_biblio = >+ $builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO', homebranch => $library->branchcode } ); > my $orphan_item_id = $item_without_biblio->itemnumber; > my $orphan_biblio_id = $item_without_biblio->biblionumber; > my $orphan_item_data = $item_without_biblio->unblessed; >@@ -196,3 +201,72 @@ subtest 'restore() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'restore() with library group permissions tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $librarian->borrowernumber, >+ module_bit => 13, >+ code => 'records_restore', >+ } >+ } >+ ); >+ >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ $librarian->branchcode( $library1->branchcode )->store; >+ >+ my $library_group = Koha::Library::Group->new( { title => 'Test Group', ft_limit_item_editing => 1 } )->store; >+ Koha::Library::Group->new( >+ { >+ parent_id => $library_group->id, >+ branchcode => $library1->branchcode, >+ } >+ )->store; >+ >+ my $item_allowed = $builder->build_sample_item( { homebranch => $library1->branchcode } ); >+ my $item_restricted = $builder->build_sample_item( { homebranch => $library2->branchcode } ); >+ >+ my $item_allowed_id = $item_allowed->itemnumber; >+ my $item_restricted_id = $item_restricted->itemnumber; >+ >+ my $item_allowed_data = $item_allowed->unblessed; >+ my $item_restricted_data = $item_restricted->unblessed; >+ >+ my $deleted_item_allowed = Koha::Old::Item->new($item_allowed_data)->store; >+ my $deleted_item_restricted = Koha::Old::Item->new($item_restricted_data)->store; >+ >+ $item_allowed->delete; >+ $item_restricted->delete; >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_allowed_id")->status_is(200); >+ >+ my $restored_item = Koha::Items->find($item_allowed_id); >+ ok( $restored_item, 'Item from allowed library restored' ); >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_restricted_id")->status_is(403) >+ ->json_is( '/error' => 'You do not have permission to restore items from this library.' ); >+ >+ my $not_restored = Koha::Items->find($item_restricted_id); >+ is( $not_restored, undef, 'Item from restricted library not restored' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.39.5
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 17387
:
188670
|
188671
|
188672
|
188673
|
188674
|
188675
|
188676
|
188677
|
188678
|
188679
|
188680
|
188681
|
188682
|
188683
|
188684
|
188685
|
188686
|
188687
|
188688
|
188689
|
188690
|
188691
|
188692
|
188693
|
188694
|
188695
|
188696
|
188697
|
188698
|
188699
|
188700
|
188701
|
188780
|
188781
|
188782
|
188783
|
188784
|
188785
|
188786
|
188787
|
188788
|
188789
|
188790
|
188791
|
188792
|
188793
|
188794
|
188795
|
189046
|
189047
|
189048
|
189049
|
189050
|
189051
|
189052
|
189053
|
189054
|
189055
|
189056
|
189057
|
189058
|
189059
|
189060
|
189061
|
189062
|
189082
|
189083
|
189084
|
189085
|
189086
|
189087
|
189088
|
189089
|
189090
|
189091
|
189092
|
189093
|
189094
|
189095
|
189096
|
189097
|
189098
|
189099
|
189100
|
189101
|
189102
|
189103
|
189104
|
189105
|
189106
|
189107
|
189108
|
189109
|
189110
|
189111
|
189112
|
189113
|
189114
|
189115
|
189116
|
189117
|
189118
|
189119