Bugzilla – Attachment 113039 Details for
Bug 23916
Issuer should be recorded and visible in patron circulation history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23916: Add unit tests
Bug-23916-Add-unit-tests.patch (text/plain), 5.60 KB, created by
Andrew Isherwood
on 2020-11-05 09:05:53 UTC
(
hide
)
Description:
Bug 23916: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2020-11-05 09:05:53 UTC
Size:
5.60 KB
patch
obsolete
>From 3ff62a289fbb66acf9868d2b747a95b486c5ec9f Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Thu, 31 Oct 2019 14:26:18 +0000 >Subject: [PATCH] Bug 23916: Add unit tests > >This patch adds unit tests for the new functions > >Signed-off-by: Ben Veasey <B.T.Veasey@lboro.ac.uk> >Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com> >--- > t/db_dependent/Circulation.t | 51 +++++++++++++++++++++++++++++++-- > t/db_dependent/Koha/Checkouts.t | 31 +++++++++++++++++++- > t/db_dependent/Koha/Patrons.t | 7 +++++ > 3 files changed, 86 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 51706fcf38..f95b288e50 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 50; >+use Test::More tests => 51; > use Test::Exception; > use Test::MockModule; > use Test::Deep qw( cmp_deeply ); >@@ -121,6 +121,11 @@ for my $branch ( $branches->next ) { > $dbh->do('DELETE FROM issues'); > $dbh->do('DELETE FROM borrowers'); > >+# Disable recording of issuer until we're ready for it >+t::lib::Mocks::mock_preference('RecordIssuer', 0); >+ >+my $module = new Test::MockModule('C4::Context'); >+ > my $library = $builder->build({ > source => 'Branch', > }); >@@ -3345,7 +3350,6 @@ subtest 'Incremented fee tests' => sub { > my $library = > $builder->build_object( { class => 'Koha::Libraries' } )->store; > >- my $module = Test::MockModule->new('C4::Context'); > $module->mock( 'userenv', sub { { branch => $library->id } } ); > > my $patron = $builder->build_object( >@@ -4147,6 +4151,49 @@ subtest 'Checkout should correctly terminate a transfer' => sub { > $hold = $hold->get_from_storage; > is( $hold->found, undef, 'Hold is waiting' ); > is( $hold->priority, 1, ); >+} >+ >+subtest 'AddIssue records issuer if appropriate' => sub { >+ plan tests => 2; >+ >+ $module->mock( 'userenv', sub { { branch => $library->{id} } } ); >+ >+ my $library = >+ $builder->build_object( { class => 'Koha::Libraries' } )->store; >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $patron_category->{categorycode} } >+ } >+ )->store; >+ my $issuer = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $patron_category->{categorycode} } >+ } >+ )->store; >+ my $item = $builder->build_sample_item( >+ { >+ library => $library->{branchcode} >+ } >+ ); >+ >+ $module->mock( 'userenv', sub { { branch => $library->id, number => $issuer->{borrowernumber} } } ); >+ >+ my $dt_from = dt_from_string(); >+ my $dt_to = dt_from_string()->add( days => 7 ); >+ >+ my $issue = >+ AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); >+ >+ is( $issue->issuer, undef, "Issuer not recorded when RecordIssuer turned off" ); >+ >+ t::lib::Mocks::mock_preference('RecordIssuer', 1); >+ >+ my $issue2 = >+ AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); >+ >+ is( $issue->issuer, $issuer->{borrowernumber}, "Issuer recorded when RecordIssuer turned on" ); > }; > > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t >index d037970a40..0ee6a4d8b7 100755 >--- a/t/db_dependent/Koha/Checkouts.t >+++ b/t/db_dependent/Koha/Checkouts.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > > use C4::Circulation; > use Koha::Checkouts; >@@ -122,6 +122,35 @@ subtest 'patron' => sub { > ); > }; > >+subtest 'issuer' => sub { >+ plan tests => 3; >+ my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); >+ my $issuer = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); >+ >+ my $item = $builder->build_object( { class=> 'Koha::Items' } ); >+ my $checkout = Koha::Checkout->new({ >+ borrowernumber => $patron->borrowernumber, >+ issuer => $issuer->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $library->{branchcode}, >+ })->store; >+ >+ my $i = $checkout->issued_by; >+ is( ref($i), 'Koha::Patron', >+ 'Koha::Checkout->issued_by should return a Koha::Patron' ); >+ is( $i->borrowernumber, $issuer->borrowernumber, >+ 'Koha::Checkout->issued_by should return the correct patron' ); >+ >+ my $issue_id = $checkout->issue_id; >+ C4::Circulation::MarkIssueReturned( $i->borrowernumber, $checkout->itemnumber ); >+ $i->delete; >+ my $old_issue = Koha::Old::Checkouts->find($issue_id); >+ is( $old_issue->issuer, undef, >+ 'Koha::Checkout->issuer should return undef if the patron record has been deleted' >+ ); >+ >+}; >+ > $retrieved_checkout_1->delete; > is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index aa04e0564c..ca7dbdf761 100755 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -1419,6 +1419,13 @@ subtest 'get_overdues' => sub { > value => { branchcode => $library->{branchcode} } > } > ); >+ my $issuer = $builder->build( >+ { >+ source => 'Borrower', >+ value => { branchcode => $library->{branchcode} } >+ } >+ ); >+ t::lib::Mocks::mock_userenv({ number => $issuer->{borrowernumber} }); > > t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} }); > >-- >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 23916
:
94914
|
94915
|
94916
|
94917
|
94918
|
95503
|
95504
|
95505
|
95506
|
95507
|
95508
|
95509
|
97719
|
97720
|
97721
|
97722
|
97723
|
97724
|
98586
|
98587
|
98588
|
98589
|
98590
|
98591
|
98594
|
99886
|
99887
|
99888
|
99889
|
99890
|
99891
|
110649
|
110650
|
110651
|
110652
|
110653
|
110654
|
110655
|
111485
|
111486
|
111487
|
111488
|
111489
|
111490
|
111491
|
111492
|
111966
|
111967
|
111968
|
111969
|
111970
|
111971
|
111972
|
111973
|
111974
|
112248
|
112249
|
112250
|
112251
|
112252
|
112253
|
112254
|
112255
|
112256
|
112257
|
112363
|
112364
|
112365
|
112366
|
112367
|
112368
|
112369
|
112370
|
112371
|
112372
|
112373
|
113035
|
113036
|
113037
|
113038
|
113039
|
113040
|
113041
|
113042
|
113043
|
113044
|
113045
|
113316
|
113317
|
113318
|
113319
|
113320
|
113321
|
113322
|
113323
|
113324
|
113325
|
113326
|
113327
|
113367
|
113368
|
113369
|
113370
|
113371
|
113372
|
113373
|
113374
|
113375
|
113376
|
113377
|
113378
|
113379
|
113380
|
113381
|
113382
|
113396