Bugzilla – Attachment 137166 Details for
Bug 30275
Checkout renewals should be stored in their own table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30275: Unit Tests for Checkouts::Renewal
Bug-30275-Unit-Tests-for-CheckoutsRenewal.patch (text/plain), 8.89 KB, created by
Martin Renvoize (ashimema)
on 2022-07-05 12:38:15 UTC
(
hide
)
Description:
Bug 30275: Unit Tests for Checkouts::Renewal
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-07-05 12:38:15 UTC
Size:
8.89 KB
patch
obsolete
>From ae3e485cc2b4f4e5c834e5f5cbb6619e344f8da0 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 28 Apr 2022 13:13:24 +0100 >Subject: [PATCH] Bug 30275: Unit Tests for Checkouts::Renewal > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Checkouts/Renewal.t | 265 ++++++++++++++++++++++++ > 1 file changed, 265 insertions(+) > create mode 100755 t/db_dependent/Koha/Checkouts/Renewal.t > >diff --git a/t/db_dependent/Koha/Checkouts/Renewal.t b/t/db_dependent/Koha/Checkouts/Renewal.t >new file mode 100755 >index 0000000000..9e1a42a3dc >--- /dev/null >+++ b/t/db_dependent/Koha/Checkouts/Renewal.t >@@ -0,0 +1,265 @@ >+#!/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 Test::More tests => 4; >+use Test::Exception; >+ >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Checkouts::Renewal; >+use Koha::Checkouts::Renewals; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest "store() tests" => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ >+ my $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ my $old_checkout = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ throws_ok { >+ Koha::Checkouts::Renewal->new( { interface => 'intranet' } )->store() >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Exception thrown if no checkout_id is passed on creation'; >+ >+ my $renewal = Koha::Checkouts::Renewal->new( >+ { >+ checkout_id => $checkout->id, >+ renewer_id => $librarian->borrowernumber, >+ interface => 'intranet' >+ } >+ )->store; >+ >+ is( ref($renewal), 'Koha::Checkouts::Renewal', 'Object type is correct' ); >+ is( >+ Koha::Checkouts::Renewals->search( { checkout_id => $checkout->id } ) >+ ->count, >+ 1, >+ 'Renewal stored on the DB' >+ ); >+ >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ >+ my $another_checkout = >+ $builder->build_object( { class => 'Koha::Checkouts' } ); >+ my $checkout_id = $another_checkout->id; >+ $another_checkout->delete; >+ >+ my $THE_renewal; >+ >+ throws_ok { >+ $THE_renewal = Koha::Checkouts::Renewal->new( >+ { >+ checkout_id => $checkout_id, >+ interface => 'intranet' >+ } >+ )->store; >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'An exception is thrown on invalid checkout_id'; >+ close STDERR; >+ >+ is( $@->broken_fk, 'checkout_id', 'Exception field is correct' ); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'renewer() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ my $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ my $renewal = Koha::Checkouts::Renewal->new( >+ { >+ checkout_id => $checkout->id, >+ renewer_id => $librarian->id, >+ interface => 'intranet' >+ } >+ )->store; >+ >+ my $renewal_renewer_patron = $renewal->renewer; >+ is( ref($renewal_renewer_patron), >+ 'Koha::Patron', >+ 'Koha::Checkouts::Renewal->renewer should return a Koha::Patron' ); >+ is( $renewal->renewer_id, $renewal_renewer_patron->borrowernumber, >+ 'Koha::Checkouts::Renewal->renewer should return the correct borrower' >+ ); >+ >+ my $checkout_id = $checkout->id; >+ $librarian->delete; >+ my $renewals = >+ Koha::Checkouts::Renewals->search( { checkout_id => $checkout_id } ); >+ is( $renewals->count, 1, >+ 'Koha::Checkouts::Renewal is not deleted on librarian deletion' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'checkout() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ my $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ my $renewal = Koha::Checkouts::Renewal->new( >+ { >+ checkout_id => $checkout->id, >+ renewer_id => $librarian->id, >+ interface => 'intranet' >+ } >+ )->store; >+ >+ my $renewal_checkout = $renewal->checkout; >+ is( ref($renewal_checkout), 'Koha::Checkout', >+ 'Koha::Checkouts::Renewal->checkout should return a Koha::Checkout' ); >+ is( $renewal->checkout_id, $renewal_checkout->id, >+ 'Koha::Checkouts::Renewal->checkout should return the correct checkout' >+ ); >+ >+ my $issue_id = $checkout->issue_id; >+ $checkout->delete; >+ >+ my $renewals = >+ Koha::Checkouts::Renewals->search( { checkout_id => $issue_id } ); >+ is( $renewals->count, 1, >+ 'Koha::Checkouts::Renewal remains on checkout deletion' ); >+ >+ $renewal->discard_changes; >+ is( $renewal->checkout, undef, >+'Koha::Checkouts::Renewal->checkout should return undef if checkout has been deleted' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'old_checkout() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ my $old_checkout = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ my $renewal = Koha::Checkouts::Renewal->new( >+ { >+ checkout_id => $old_checkout->id, >+ renewer_id => $librarian->id, >+ interface => 'intranet' >+ } >+ )->store; >+ >+ my $renewal_old_checkout = $renewal->old_checkout; >+ is( ref($renewal_old_checkout), 'Koha::Old::Checkout', >+'Koha::Checkouts::Renewal->old_checkout should return a Koha::Old::Checkout' >+ ); >+ is( $renewal->checkout_id, $renewal_old_checkout->id, >+'Koha::Checkouts::Renewal->old_checkout should return the correct old checkout' >+ ); >+ >+ my $issue_id = $old_checkout->issue_id; >+ $old_checkout->delete; >+ >+ my $renewals = >+ Koha::Checkouts::Renewals->search( { checkout_id => $issue_id } ); >+ is( $renewals->count, 1, >+ 'Koha::Checkouts::Renewal remains on old_checkout deletion' ); >+ >+ # FIXME: Should we actually set null on OldCheckout deletion? >+ >+ $renewal->discard_changes; >+ is( $renewal->old_checkout, undef, >+'Koha::Checkouts::Renewal->old_checkout should return undef if old_checkout has been 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 30275
:
131593
|
131594
|
131595
|
131596
|
131597
|
131598
|
131599
|
131600
|
131601
|
131602
|
131603
|
131604
|
131605
|
131606
|
131607
|
131608
|
131609
|
131610
|
131611
|
131612
|
131613
|
131614
|
131615
|
131616
|
131879
|
131880
|
131881
|
131882
|
131883
|
131884
|
131885
|
131886
|
131887
|
131888
|
131889
|
131890
|
131897
|
131898
|
131899
|
131900
|
131901
|
131902
|
131903
|
131904
|
131905
|
131906
|
131907
|
131908
|
131909
|
131910
|
133908
|
133909
|
133910
|
133911
|
133912
|
133913
|
133914
|
133915
|
133916
|
133917
|
133918
|
133919
|
133920
|
133921
|
133922
|
133929
|
133930
|
133931
|
133932
|
133933
|
133934
|
133935
|
133936
|
133937
|
133938
|
133939
|
133940
|
133941
|
133942
|
133943
|
133944
|
133969
|
133970
|
133971
|
133972
|
133973
|
133974
|
133975
|
133976
|
133977
|
133978
|
133979
|
133980
|
133981
|
133982
|
133983
|
133984
|
134177
|
134178
|
134179
|
134180
|
134181
|
134182
|
134183
|
134184
|
134185
|
134186
|
134187
|
134188
|
134189
|
134190
|
134191
|
134192
|
134193
|
134210
|
134228
|
134229
|
134230
|
134231
|
134232
|
134233
|
134234
|
134235
|
134236
|
134237
|
134238
|
134239
|
134240
|
134241
|
134242
|
134243
|
134244
|
134245
|
134246
|
134247
|
134248
|
134470
|
134471
|
134472
|
134473
|
134869
|
134870
|
134871
|
134872
|
134873
|
134874
|
134875
|
134876
|
134877
|
134878
|
134879
|
134880
|
134881
|
134882
|
134883
|
134884
|
134885
|
134886
|
134887
|
134888
|
134889
|
135123
|
135124
|
135125
|
135126
|
135127
|
135128
|
135129
|
135130
|
135131
|
135132
|
135133
|
135134
|
135135
|
135136
|
135137
|
135138
|
135139
|
135140
|
135141
|
135142
|
135143
|
137146
|
137147
|
137148
|
137149
|
137150
|
137151
|
137152
|
137153
|
137154
|
137155
|
137156
|
137157
|
137158
|
137159
|
137160
|
137161
|
137162
|
137163
|
137164
|
137165
| 137166 |
137217
|
137598