Bugzilla – Attachment 91991 Details for
Bug 23112
Add circulation process to inter-library loans
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23112: Add unit tests
Bug-23112-Add-unit-tests.patch (text/plain), 6.70 KB, created by
Andrew Isherwood
on 2019-08-05 13:02:21 UTC
(
hide
)
Description:
Bug 23112: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2019-08-05 13:02:21 UTC
Size:
6.70 KB
patch
obsolete
>From d4fb3a89b6ef5232f41fbf1fc3703d49b06f4093 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 30 Jul 2019 14:54:53 +0100 >Subject: [PATCH] Bug 23112: Add unit tests > >This patch adds unit test for the new Koha::Illrequest::check_out method >--- > t/db_dependent/Illrequests.t | 146 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 143 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t >index d3a68084bc..514fafb778 100644 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -21,7 +21,11 @@ use File::Basename qw/basename/; > use Koha::Database; > use Koha::Illrequestattributes; > use Koha::Illrequest::Config; >+use Koha::Biblios; > use Koha::Patrons; >+use Koha::ItemTypes; >+use Koha::Items; >+use Koha::Libraries; > use Koha::AuthorisedValueCategories; > use Koha::AuthorisedValues; > use t::lib::Mocks; >@@ -30,7 +34,7 @@ use Test::MockObject; > use Test::MockModule; > use Test::Exception; > >-use Test::More tests => 11; >+use Test::More tests => 12; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -247,7 +251,6 @@ subtest 'Backend testing (mocks)' => sub { > my $patron = $builder->build({ source => 'Borrower' }); > my $illrq = $builder->build_object({ > class => 'Koha::Illrequests', >- value => { borrowernumber => $patron->{borrowernumber} } > }); > > $illrq->_backend($backend); >@@ -308,7 +311,7 @@ subtest 'Backend testing (mocks)' => sub { > name => 'Completed', > ui_method_name => 'Mark completed', > method => 'mark_completed', >- next_actions => [ ], >+ next_actions => [ 'CHK' ], > ui_method_icon => 'fa-check', > }, > "Dummy status graph for COMP."); >@@ -673,6 +676,143 @@ subtest 'Censorship' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'Checking out' => sub { >+ >+ plan tests => 16; >+ >+ $schema->storage->txn_begin; >+ >+ my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); >+ my $patron = $builder->build_object({ >+ class => 'Koha::Patrons', >+ value => { category_type => 'x' } >+ }); >+ my $request = $builder->build_object({ >+ class => 'Koha::Illrequests', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ biblio_id => $biblio->biblionumber >+ } >+ }); >+ >+ # First test that calling check_out without a stage param returns >+ # what's required to build the form >+ my $no_stage = $request->check_out(); >+ is($no_stage->{method}, 'check_out'); >+ is($no_stage->{stage}, 'form'); >+ isa_ok($no_stage->{value}, 'HASH'); >+ isa_ok($no_stage->{value}->{itemtypes}, 'Koha::ItemTypes'); >+ isa_ok($no_stage->{value}->{libraries}, 'Koha::Libraries'); >+ isa_ok($no_stage->{value}->{statistical}, 'Koha::Patrons'); >+ isa_ok($no_stage->{value}->{biblio}, 'Koha::Biblio'); >+ >+ # Now test that form validation works when we supply a 'form' stage >+ # >+ # No item_type >+ my $form_stage_missing_params = $request->check_out({ >+ stage => 'form' >+ }); >+ is_deeply($form_stage_missing_params->{value}->{errors}, { >+ item_type => 1 >+ }); >+ # inhouse passed but not a valid patron >+ my $form_stage_bad_patron = $request->check_out({ >+ stage => 'form', >+ item_type => $itemtype->itemtype, >+ inhouse => 'I_DONT_EXIST' >+ }); >+ is_deeply($form_stage_bad_patron->{value}->{errors}, { >+ inhouse => 1 >+ }); >+ # Too many items attached to biblio >+ my $item1 = $builder->build_object({ >+ class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio->biblionumber, >+ biblioitemnumber => 1 >+ } >+ }); >+ my $item2 = $builder->build_object({ >+ class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio->biblionumber, >+ biblioitemnumber => 2 >+ } >+ }); >+ my $form_stage_two_items = $request->check_out({ >+ stage => 'form', >+ item_type => $itemtype->itemtype, >+ }); >+ is_deeply($form_stage_two_items->{value}->{errors}, { >+ itemcount => 1 >+ }); >+ >+ # Passed validation >+ # >+ # Delete the items we created, so we can test that we can create one >+ Koha::Items->find({ itemnumber => $item1->itemnumber })->delete; >+ Koha::Items->find({ itemnumber => $item2->itemnumber })->delete; >+ # Create a biblioitem >+ my $biblioitem = $builder->build_object({ >+ class => 'Koha::Biblioitems', >+ value => { >+ biblionumber => $biblio->biblionumber >+ } >+ }); >+ # First we pass bad parameters to the item creation to test we're >+ # catching the failure of item creation >+ # Note: This will generate a DBD::mysql error when running this test! >+ my $form_stage_bad_branchcode = $request->check_out({ >+ stage => 'form', >+ item_type => $itemtype->itemtype, >+ branchcode => '---' >+ }); >+ is_deeply($form_stage_bad_branchcode->{value}->{errors}, { >+ item_creation => 1 >+ }); >+ # Now create a proper item >+ my $form_stage_good_branchcode = $request->check_out({ >+ stage => 'form', >+ item_type => $itemtype->itemtype, >+ branchcode => $library->branchcode >+ }); >+ # By default, this item should not be loanable, so check that we're >+ # informed of that fact >+ is_deeply( >+ $form_stage_good_branchcode->{value}->{check_out_errors}, >+ { >+ error => { >+ NOT_FOR_LOAN => 1, >+ itemtype_notforloan => $itemtype->itemtype >+ } >+ } >+ ); >+ # Delete the item that was created >+ $biblio->items->delete; >+ # Now create an itemtype that is loanable >+ my $itemtype_loanable = $builder->build_object({ >+ class => 'Koha::ItemTypes', >+ value => { >+ notforloan => 0 >+ } >+ }); >+ # We need to mock the user environment for AddIssue >+ t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); >+ my $form_stage_loanable = $request->check_out({ >+ stage => 'form', >+ item_type => $itemtype_loanable->itemtype, >+ branchcode => $library->branchcode >+ }); >+ is($form_stage_loanable->{stage}, 'done_check_out'); >+ isa_ok($patron->checkouts, 'Koha::Checkouts'); >+ is($patron->checkouts->count, 1); >+ is($request->status, 'CHK'); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'Checking Limits' => sub { > > plan tests => 30; >-- >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 23112
:
91987
|
91988
|
91989
|
91990
|
91991
|
92000
|
92001
|
92002
|
92003
|
92004
|
93530
|
93531
|
93532
|
93533
|
93534
|
93958
|
94264
|
94265
|
94266
|
94267
|
94268
|
94269
|
95565
|
95566
|
95567
|
95568
|
95569
|
95570
|
96834
|
96870
|
99910
|
99911
|
99912
|
99913
|
99914
|
99915
|
99916
|
99917
|
100100
|
100101
|
100102
|
100103
|
100104
|
100105
|
100106
|
100107
|
100108
|
100169
|
100224
|
100225
|
100252
|
100253
|
100254
|
100255
|
100256
|
100257
|
100258
|
100259
|
100260
|
100261
|
100262
|
100263