Bugzilla – Attachment 114356 Details for
Bug 27209
Add Koha::Hold->set_pickup_location
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27209: Unit tests
Bug-27209-Unit-tests.patch (text/plain), 4.18 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-12-11 19:55:48 UTC
(
hide
)
Description:
Bug 27209: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-12-11 19:55:48 UTC
Size:
4.18 KB
patch
obsolete
>From 30119093ef030cc23a884098c85f39c0caa4ff9f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 11 Dec 2020 16:51:34 -0300 >Subject: [PATCH] Bug 27209: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Hold.t | 94 +++++++++++++++++++++++++++++++++++++- > 1 file changed, 93 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index bdf4f499d28..dfe0c379c55 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -19,10 +19,15 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; >+ >+use Test::Exception; >+use Test::MockModule; > > use t::lib::TestBuilder; > >+use Koha::Libraries; >+ > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >@@ -48,3 +53,90 @@ subtest 'patron() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'set_pickup_location() tests' => sub { >+ >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ my $mock_biblio = Test::MockModule->new('Koha::Biblio'); >+ my $mock_item = Test::MockModule->new('Koha::Item'); >+ >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ # let's control what Koha::Biblio->pickup_locations returns, for testing >+ $mock_biblio->mock( 'pickup_locations', sub { >+ return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); >+ }); >+ # let's mock what Koha::Item->pickup_locations returns, for testing >+ $mock_item->mock( 'pickup_locations', sub { >+ return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); >+ }); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); >+ >+ # Test biblio-level holds >+ my $biblio_hold = $builder->build_object( >+ { >+ class => "Koha::Holds", >+ value => { >+ biblionumber => $biblio->biblionumber, >+ branchcode => $library_3->branchcode, >+ itemnumber => undef, >+ } >+ } >+ ); >+ >+ throws_ok >+ { $biblio_hold->set_pickup_location({ library_id => $library_1->branchcode }); } >+ 'Koha::Exceptions::Hold::InvalidPickupLocation', >+ 'Exception thrown on invalid pickup location'; >+ >+ $biblio_hold->discard_changes; >+ is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); >+ >+ my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id }); >+ is( ref($ret), 'Koha::Hold', 'self is returned' ); >+ >+ $biblio_hold->discard_changes; >+ is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' ); >+ >+ # Test item-level holds >+ my $item_hold = $builder->build_object( >+ { >+ class => "Koha::Holds", >+ value => { >+ biblionumber => $biblio->biblionumber, >+ branchcode => $library_3->branchcode, >+ itemnumber => $item->itemnumber, >+ } >+ } >+ ); >+ >+ throws_ok >+ { $item_hold->set_pickup_location({ library_id => $library_1->branchcode }); } >+ 'Koha::Exceptions::Hold::InvalidPickupLocation', >+ 'Exception thrown on invalid pickup location'; >+ >+ $item_hold->discard_changes; >+ is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); >+ >+ $ret = $item_hold->set_pickup_location({ library_id => $library_2->id }); >+ is( ref($ret), 'Koha::Hold', 'self is returned' ); >+ >+ $item_hold->discard_changes; >+ is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' ); >+ >+ throws_ok >+ { $item_hold->set_pickup_location({ library_id => undef }); } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if missing parameter'; >+ >+ is( "$@", 'The library_id parameter is mandatory', 'Exception message is clear' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.29.2
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 27209
:
114356
|
114357
|
114374
|
114378
|
114379
|
114380
|
114443
|
114444
|
114445
|
114448
|
114449
|
114450