Bugzilla – Attachment 189086 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: add restore item/biblio tests
Bug-17387-add-restore-itembiblio-tests.patch (text/plain), 8.96 KB, created by
Jacob O'Mara
on 2025-11-05 15:39:23 UTC
(
hide
)
Description:
Bug 17387: add restore item/biblio tests
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-11-05 15:39:23 UTC
Size:
8.96 KB
patch
obsolete
>From e24fe391b90314becf47804659db83b8aecdf95b Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Thu, 30 Oct 2025 10:09:03 +0000 >Subject: [PATCH] Bug 17387: add restore item/biblio tests > >--- > t/db_dependent/api/v1/deleted_biblios.t | 71 ++++++++- > t/db_dependent/api/v1/deleted_items.t | 187 ++++++++++++++++++++++++ > 2 files changed, 257 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/api/v1/deleted_items.t > >diff --git a/t/db_dependent/api/v1/deleted_biblios.t b/t/db_dependent/api/v1/deleted_biblios.t >index bd80fbacffc..bf9c8bccf4e 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 => 3; >+use Test::More tests => 4; > use Test::MockModule; > use Test::Mojo; > use Test::Warn; >@@ -261,3 +261,72 @@ subtest 'list() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'restore() tests' => sub { >+ >+ plan tests => 13; >+ >+ $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 $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ my $biblio = $builder->build_sample_biblio( >+ { >+ title => 'Test Restore Biblio', >+ author => 'Test Author' >+ } >+ ); >+ >+ my $biblionumber = $biblio->biblionumber; >+ >+ DelBiblio($biblionumber); >+ >+ is( Koha::Biblios->find($biblionumber), undef, 'Biblio deleted successfully' ); >+ my $deleted_biblio = Koha::Old::Biblios->find($biblionumber); >+ ok( $deleted_biblio, 'Biblio found in deleted table' ); >+ >+ $t->put_ok("//$unauth_userid:$password@/api/v1/deleted/biblios/$biblionumber")->status_is(403); >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/biblios/$biblionumber")->status_is(200) >+ ->json_is( '/biblio_id' => $biblionumber ); >+ >+ my $restored_biblio = Koha::Biblios->find($biblionumber); >+ ok( $restored_biblio, 'Biblio restored successfully' ); >+ is( $restored_biblio->title, 'Test Restore Biblio', 'Biblio title preserved' ); >+ is( $restored_biblio->author, 'Test Author', 'Biblio author preserved' ); >+ >+ is( Koha::Old::Biblios->find($biblionumber), undef, 'Biblio removed from deleted table' ); >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/biblios/$biblionumber")->status_is(404); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/api/v1/deleted_items.t b/t/db_dependent/api/v1/deleted_items.t >new file mode 100755 >index 00000000000..e3b1c6a683d >--- /dev/null >+++ b/t/db_dependent/api/v1/deleted_items.t >@@ -0,0 +1,187 @@ >+#!/usr/bin/env 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::NoWarnings; >+use Test::More tests => 4; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::Items; >+use Koha::Old::Items; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'list() tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Old::Items->search->delete; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**2 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ $t->get_ok("//$userid:$password@/api/v1/deleted/items")->status_is(200)->json_is( [] ); >+ >+ my $item = $builder->build_sample_item(); >+ my $item_id = $item->itemnumber; >+ my $item_data = $item->unblessed; >+ my $deleted_item = Koha::Old::Item->new($item_data)->store; >+ $item->delete; >+ >+ $t->get_ok("//$userid:$password@/api/v1/deleted/items")->status_is(200); >+ >+ my $expected = $deleted_item->to_api; >+ >+ $t->json_has('/0')->json_is( '/0' => $expected ); >+ >+ $t->get_ok("//$unauth_userid:$password@/api/v1/deleted/items")->status_is(403); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'get() tests' => sub { >+ >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $item = $builder->build_sample_item(); >+ my $item_id = $item->itemnumber; >+ my $item_data = $item->unblessed; >+ my $deleted_item = Koha::Old::Item->new($item_data)->store; >+ $item->delete; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**2 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ $t->get_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(200)->json_is( $deleted_item->to_api ); >+ >+ $t->get_ok("//$unauth_userid:$password@/api/v1/deleted/items/$item_id")->status_is(403); >+ >+ my $non_existent_id = $item_id + 99999; >+ >+ $t->get_ok("//$userid:$password@/api/v1/deleted/items/$non_existent_id")->status_is(404) >+ ->json_is( '/error' => 'Item not found' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'restore() tests' => sub { >+ >+ plan tests => 11; >+ >+ $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 $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $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 $item_data = $item->unblessed; >+ my $deleted_item = Koha::Old::Item->new($item_data)->store; >+ $item->delete; >+ >+ is( Koha::Items->find($item_id), undef, 'Item deleted successfully' ); >+ ok( $deleted_item, 'Item found in deleted table' ); >+ >+ $t->put_ok("//$unauth_userid:$password@/api/v1/deleted/items/$item_id")->status_is(403); >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(200); >+ >+ my $restored_item = Koha::Items->find($item_id); >+ ok( $restored_item, 'Item restored successfully' ); >+ is( $restored_item->barcode, 'TEST_RESTORE_ITEM', 'Item barcode preserved' ); >+ >+ is( Koha::Old::Items->find($item_id), undef, 'Item removed from deleted table' ); >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404); >+ >+ $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