Bugzilla – Attachment 65609 Details for
Bug 19059
Move C4::Reserves::CancelReserve to the Koha::Hold->cancel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19059: Remove CancelReserve - add new tests
Bug-19059-Remove-CancelReserve---add-new-tests.patch (text/plain), 4.14 KB, created by
Jonathan Druart
on 2017-08-07 21:11:49 UTC
(
hide
)
Description:
Bug 19059: Remove CancelReserve - add new tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-08-07 21:11:49 UTC
Size:
4.14 KB
patch
obsolete
>From 1319dd3a6bb4142f5693f5c0592580e321a29477 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 3 Aug 2017 18:00:22 -0300 >Subject: [PATCH] Bug 19059: Remove CancelReserve - add new tests > >This is bonus, let's add new tests >--- > t/db_dependent/Koha/Holds.t | 70 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 69 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t >index 282159288b..c2399d66b5 100644 >--- a/t/db_dependent/Koha/Holds.t >+++ b/t/db_dependent/Koha/Holds.t >@@ -20,6 +20,7 @@ > use Modern::Perl; > > use Test::More tests => 1; >+use Test::Warn; > > use C4::Reserves; > use Koha::Holds; >@@ -34,7 +35,7 @@ $schema->storage->txn_begin; > my $builder = t::lib::TestBuilder->new; > > subtest 'cancel' => sub { >- plan tests => 10; >+ plan tests => 12; > my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); > my $library = $builder->build_object( { class => 'Koha::Libraries' } ); > my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); >@@ -147,6 +148,73 @@ subtest 'cancel' => sub { > my $hold_old = Koha::Old::Holds->find( $reserve_id ); > is( $hold_old->found, 'W', 'The found column should have been kept and a hold is cancelled' ); > }; >+ >+ subtest 'HoldsLog' => sub { >+ plan tests => 2; >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my @hold_info = ( >+ $library->branchcode, $patron->borrowernumber, >+ $item->biblionumber, '', >+ 1, undef, >+ undef, '', >+ "title for fee", $item->itemnumber, >+ ); >+ >+ t::lib::Mocks::mock_preference('HoldsLog', 0); >+ my $reserve_id = C4::Reserves::AddReserve(@hold_info); >+ Koha::Holds->find( $reserve_id )->cancel; >+ my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count; >+ is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' ); >+ >+ t::lib::Mocks::mock_preference('HoldsLog', 1); >+ $reserve_id = C4::Reserves::AddReserve(@hold_info); >+ Koha::Holds->find( $reserve_id )->cancel; >+ $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count; >+ is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' ); >+ }; >+ >+ subtest 'rollback' => sub { >+ plan tests => 3; >+ my $patron_category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { reservefee => 0 } >+ } >+ ); >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $patron_category->categorycode } >+ } >+ ); >+ my @hold_info = ( >+ $library->branchcode, $patron->borrowernumber, >+ $item->biblionumber, '', >+ 1, undef, >+ undef, '', >+ "title for fee", $item->itemnumber, >+ ); >+ >+ t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',42 ); >+ my $reserve_id = C4::Reserves::AddReserve(@hold_info); >+ my $hold = Koha::Holds->find($reserve_id); >+ >+ # Add a row with the same id to make the cancel fails >+ Koha::Old::Hold->new( $hold->unblessed )->store; >+ >+ warning_like { >+ eval { $hold->cancel( { charge_cancel_fee => 1 } ) }; >+ } >+ qr{.*DBD::mysql::st execute failed: Duplicate entry.*}, >+ 'DBD should have raised an error about dup primary key'; >+ >+ $hold = Koha::Holds->find($reserve_id); >+ is( ref($hold), 'Koha::Hold', 'The hold should not have been deleted' ); >+ is( $patron->account->balance, 0, >+'If the hold has not been cancelled, the patron should not have been charged' >+ ); >+ }; >+ > }; > > $schema->storage->txn_rollback; >-- >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 19059
:
65607
|
65608
|
65609
|
65610
|
65611
|
65630
|
65631
|
65632
|
65633
|
65634
|
65636
|
65637
|
65638
|
65639
|
65640
|
66783
|
66930
|
66975
|
66976
|
66977
|
66978
|
66979
|
66980
|
66981