Bugzilla – Attachment 137906 Details for
Bug 30933
Add a designated owner for shared and public lists at patron deletion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30933: Unit tests
Bug-30933-Unit-tests.patch (text/plain), 11.23 KB, created by
Marcel de Rooy
on 2022-07-20 11:36:03 UTC
(
hide
)
Description:
Bug 30933: Unit tests
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-07-20 11:36:03 UTC
Size:
11.23 KB
patch
obsolete
>From 12b82c9b0d5d8c24d927f9a106c786dde6e8f05c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 19 Jul 2022 14:49:24 -0300 >Subject: [PATCH] Bug 30933: Unit tests >Content-Type: text/plain; charset=utf-8 > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Koha/Virtualshelf.t | 99 +++++++++++++ > t/db_dependent/Koha/Virtualshelves.t | 207 +++++++++++++++++++++++++++ > 2 files changed, 306 insertions(+) > create mode 100755 t/db_dependent/Koha/Virtualshelf.t > create mode 100755 t/db_dependent/Koha/Virtualshelves.t > >diff --git a/t/db_dependent/Koha/Virtualshelf.t b/t/db_dependent/Koha/Virtualshelf.t >new file mode 100755 >index 0000000000..af6c2e1b32 >--- /dev/null >+++ b/t/db_dependent/Koha/Virtualshelf.t >@@ -0,0 +1,99 @@ >+#!/usr/bin/perl >+ >+# Copyright 2022 Koha Development team >+# >+# 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 Test::More tests => 1; >+use Test::Exception; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'transfer_ownership() tests' => sub { >+ >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $public_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 1 } >+ } >+ ); >+ >+ my $private_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ throws_ok >+ { $public_list->transfer_ownership } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if missing parameter'; >+ >+ like( "$@", qr/Mandatory parameter 'patron' missing/, 'Exception string as expected' ); >+ >+ # add shares >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $public_list->id, invitekey => undef, borrowernumber => $patron_2->id } >+ } >+ ); >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $private_list->id, invitekey => undef, borrowernumber => $patron_2->id } >+ } >+ ); >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $private_list->id, invitekey => undef, borrowernumber => $patron_3->id } >+ } >+ ); >+ >+ $public_list->transfer_ownership( $patron_2->id ); >+ $public_list->discard_changes; >+ >+ is( $public_list->owner, $patron_2->id, 'Owner changed correctly' ); >+ my $public_list_shares = $public_list->get_shares; >+ is( $public_list_shares->count, 1, 'Count is correct' ); >+ is( $public_list_shares->next->borrowernumber, $patron_2->id, "Public lists don't get the share removed" ); >+ >+ $private_list->transfer_ownership( $patron_2->id ); >+ $private_list->discard_changes; >+ >+ is( $private_list->owner, $patron_2->id ); >+ my $private_list_shares = $private_list->get_shares; >+ is( $private_list_shares->count, 1, 'Count is correct' ); >+ is( $private_list_shares->next->borrowernumber, $patron_3->id, "Private lists get the share for the new owner removed" ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/Koha/Virtualshelves.t b/t/db_dependent/Koha/Virtualshelves.t >new file mode 100755 >index 0000000000..9b39ebd5ae >--- /dev/null >+++ b/t/db_dependent/Koha/Virtualshelves.t >@@ -0,0 +1,207 @@ >+#!/usr/bin/perl >+ >+# Copyright 2022 Koha Development team >+# >+# 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 Test::More tests => 1; >+use Test::Exception; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'disown_or_delete() tests' => sub { >+ >+ plan tests => 3; >+ >+ subtest 'All set cases' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $public_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 1 } >+ } >+ ); >+ >+ my $private_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ my $private_list_shared = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ # add share >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $private_list_shared->id, invitekey => undef, borrowernumber => $patron_3->id } >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); >+ t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $patron_2->id ); >+ >+ my $rs = Koha::Virtualshelves->search( { shelfnumber => [ $public_list->id, $private_list->id, $private_list_shared->id ] } ); >+ >+ my $result = $rs->disown_or_delete; >+ is( ref($result), 'Koha::Virtualshelves', 'Return type is correct' ); >+ $rs->reset; >+ >+ is( $rs->count, 2, 'The private/non-shared list was deleted' ); >+ my $first = $rs->next; >+ is( $first->id, $public_list->id ); >+ is( $first->owner, $patron_2->id ); >+ >+ my $second = $rs->next; >+ is( $second->id, $private_list_shared->id ); >+ is( $second->owner, $patron_2->id ); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'Fallback to userenv' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $public_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 1 } >+ } >+ ); >+ >+ my $private_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ my $private_list_shared = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ # add share >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $private_list_shared->id, invitekey => undef, borrowernumber => $patron_2->id } >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' ); >+ t::lib::Mocks::mock_preference( 'ListOwnerDesignated', undef ); >+ t::lib::Mocks::mock_userenv({ patron => $patron_3 }); >+ >+ my $rs = Koha::Virtualshelves->search( { shelfnumber => [ $public_list->id, $private_list->id, $private_list_shared->id ] } ); >+ >+ my $result = $rs->disown_or_delete; >+ is( ref($result), 'Koha::Virtualshelves', 'Return type is correct' ); >+ $rs->reset; >+ >+ is( $rs->count, 2, 'The private/non-shared list was deleted' ); >+ my $first = $rs->next; >+ is( $first->id, $public_list->id ); >+ is( $first->owner, $patron_3->id ); >+ >+ my $second = $rs->next; >+ is( $second->id, $private_list_shared->id ); >+ is( $second->owner, $patron_3->id ); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'ListOwnershipUponPatronDeletion set to delete' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $public_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 1 } >+ } >+ ); >+ >+ my $private_list = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ my $private_list_shared = $builder->build_object( >+ { >+ class => "Koha::Virtualshelves", >+ value => { owner => $patron_1->id, public => 0 } >+ } >+ ); >+ >+ # add share >+ $builder->build_object( >+ { >+ class => 'Koha::Virtualshelfshares', >+ value => { shelfnumber => $private_list_shared->id, invitekey => undef, borrowernumber => $patron_2->id } >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' ); >+ >+ my $rs = Koha::Virtualshelves->search( { shelfnumber => [ $public_list->id, $private_list->id, $private_list_shared->id ] } ); >+ >+ my $result = $rs->disown_or_delete; >+ is( ref($result), 'Koha::Virtualshelves', 'Return type is correct' ); >+ $rs->reset; >+ >+ is( $rs->count, 0, 'All lists deleted' ); >+ >+ $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 30933
:
136420
|
136421
|
136422
|
136423
|
136424
|
137241
|
137242
|
137243
|
137244
|
137245
|
137421
|
137422
|
137423
|
137424
|
137425
|
137879
|
137880
|
137906
|
137907
|
137909
|
137910
|
137911
|
137912
|
137913
|
137914
|
137915
|
137916
|
137917