Bugzilla – Attachment 97723 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.39 KB, created by
Andrew Isherwood
on 2020-01-22 13:44:19 UTC
(
hide
)
Description:
Bug 23916: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2020-01-22 13:44:19 UTC
Size:
5.39 KB
patch
obsolete
>From 6bca4bb537436c87a7fd2f9d20a556744a0cd720 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> >--- > t/db_dependent/Circulation.t | 49 ++++++++++++++++++++++++++++++++++++++++- > t/db_dependent/Koha/Checkouts.t | 31 +++++++++++++++++++++++++- > t/db_dependent/Koha/Patrons.t | 7 ++++++ > 3 files changed, 85 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index c0e2dacece..f905de69ac 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -117,6 +117,11 @@ $cache->clear_from_cache('single_holidays'); > $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', > }); >@@ -3103,7 +3108,6 @@ subtest 'Incremented fee tests' => sub { > my $library = > $builder->build_object( { class => 'Koha::Libraries' } )->store; > >- my $module = new Test::MockModule('C4::Context'); > $module->mock( 'userenv', sub { { branch => $library->id } } ); > > my $patron = $builder->build_object( >@@ -3384,6 +3388,49 @@ subtest "Test Backdating of Returns" => sub { > is( $accountline->amount+0, 0, 'Fee amount was reduced to 0' ); > }; > >+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; > C4::Context->clear_syspref_cache(); > $cache->clear_from_cache('single_holidays'); >diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t >index dfb90e42a8..193f0bf11f 100644 >--- 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 f94bd2aba9..d7a8b5462b 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -1404,6 +1404,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.11.0
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