Bugzilla – Attachment 110641 Details for
Bug 26515
Add Koha::Acquisition::Order->cancel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26515: Unit tests
Bug-26515-Unit-tests.patch (text/plain), 6.70 KB, created by
Martin Renvoize (ashimema)
on 2020-09-24 09:25:04 UTC
(
hide
)
Description:
Bug 26515: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-09-24 09:25:04 UTC
Size:
6.70 KB
patch
obsolete
>From 37f347b780b0a7decbcbd0d755207421617b0839 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 23 Sep 2020 11:35:53 -0300 >Subject: [PATCH] Bug 26515: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Acquisition/Order.t | 152 +++++++++++++++++++++++- > 1 file changed, 151 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t >index 2fa7310ae6..ebbc23058b 100755 >--- a/t/db_dependent/Koha/Acquisition/Order.t >+++ b/t/db_dependent/Koha/Acquisition/Order.t >@@ -19,13 +19,18 @@ > > use Modern::Perl; > >-use Test::More tests => 11; >+use Test::More tests => 12; >+use Test::Exception; > > use t::lib::TestBuilder; > use t::lib::Mocks; > >+use C4::Circulation; >+ >+use Koha::Biblios; > use Koha::Database; > use Koha::DateUtils qw(dt_from_string); >+use Koha::Items; > > my $schema = Koha::Database->schema; > my $builder = t::lib::TestBuilder->new; >@@ -582,5 +587,150 @@ subtest 'filter_by_current & filter_by_cancelled' => sub { > is( $orders->filter_by_cancelled->count, 1); > > >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'cancel() tests' => sub { >+ >+ plan tests => 23; >+ >+ $schema->storage->txn_begin; >+ >+ # Scenario: >+ # * order with one item attached >+ # * the item is on loan >+ # * delete_biblio => 1 is passed >+ # => order is not cancelled >+ # => item in order is not removed >+ # => biblio is kept >+ # => exception is thrown >+ >+ my $item = $builder->build_sample_item; >+ my $biblio_id = $item->biblio->id; >+ my $order = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ orderstatus => 'new', >+ biblionumber => $item->biblio->id, >+ datecancellationprinted => undef, >+ cancellationreason => undef, >+ } >+ } >+ ); >+ $order->add_item( $item->id ); >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ t::lib::Mocks::mock_userenv( >+ { patron => $patron, branchcode => $patron->branchcode } ); >+ >+ # Add a checkout so cancelling fails because od 'book_on_loan' >+ C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); >+ >+ throws_ok >+ { $order->cancel({ delete_biblio => 1, reason => 'Some reason' }); } >+ 'Koha::Exceptions::Object::CannotBeDeleted', >+ 'An exception is thrown'; >+ >+ like( >+ "$@", >+ qr/Cannot delete Koha::Item=HASH\(.*\) object \(id=\d*\). Reason: book_on_loan/, >+ 'The exception is correct, item on loan' >+ ); >+ >+ # refresh the order object >+ $order->discard_changes; >+ >+ isnt( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' ); >+ is( $order->datecancellationprinted, undef, 'datecancellationprinted is undef' ); >+ is( $order->cancellationreason, undef, 'cancellationreason is undef' ); >+ is( ref(Koha::Items->find($item->id)), 'Koha::Item', 'The item is present' ); >+ is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' ); >+ >+ # Scenario: >+ # * order with one item attached >+ # * the item is no longer on loan >+ # * delete_biblio => 1 is passed >+ # => order is cancelled >+ # => item in order is removed >+ # => biblio is removed because delete_biblio => 1 is passed >+ >+ C4::Circulation::AddReturn( $item->barcode ); >+ >+ $order->cancel({ delete_biblio => 1, reason => 'Some reason' }) >+ ->discard_changes; >+ >+ is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); >+ isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); >+ is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); >+ is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); >+ is( Koha::Biblios->find($biblio_id), undef, 'The biblio is no longer present' ); >+ >+ # Scenario: >+ # * order with one item attached >+ # * biblio has one more item >+ # * delete_biblio => 1 is passed >+ # => order is cancelled >+ # => item in order is removed >+ # => biblio is kept as there's a remaining item >+ # => the extra item remains untouched >+ >+ my $item_1 = $builder->build_sample_item; >+ $biblio_id = $item_1->biblio->id; >+ my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_id }); >+ $order = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ orderstatus => 'new', >+ biblionumber => $biblio_id, >+ datecancellationprinted => undef, >+ cancellationreason => undef, >+ } >+ } >+ ); >+ $order->add_item( $item_1->id ); >+ >+ $order->cancel({ delete_biblio => 1, reason => 'Some reason' }) >+ ->discard_changes; >+ >+ is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); >+ isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); >+ is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); >+ is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' ); >+ is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' ); >+ is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); >+ >+ # Scenario: >+ # * order with one item attached >+ # * delete_biblio => 0 is passed >+ # => order is cancelled >+ # => item in order is removed >+ # => biblio is kept because delete_biblio => 0 passed >+ >+ $item = $builder->build_sample_item; >+ $biblio_id = $item->biblio->id; >+ $order = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ orderstatus => 'new', >+ biblionumber => $biblio_id, >+ datecancellationprinted => undef, >+ cancellationreason => undef, >+ } >+ } >+ ); >+ $order->add_item( $item->id ); >+ >+ $order->cancel({ delete_biblio => 0, reason => 'Some reason' }) >+ ->discard_changes; >+ >+ is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); >+ isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); >+ is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); >+ is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); >+ is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); >+ > $schema->storage->txn_rollback; > }; >-- >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 26515
:
110603
|
110604
|
110641
|
110642
|
110751
|
110752
|
110939
|
110940
|
110970
|
110971
|
110992
|
111031
|
111170
|
111172
|
111173
|
111372
|
111430
|
111724