Bugzilla – Attachment 83626 Details for
Bug 22049
MarkIssueReturned should rely on returndate only
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22049: Add tests
Bug-22049-Add-tests.patch (text/plain), 9.82 KB, created by
Owen Leonard
on 2019-01-03 16:35:50 UTC
(
hide
)
Description:
Bug 22049: Add tests
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2019-01-03 16:35:50 UTC
Size:
9.82 KB
patch
obsolete
>From a7865a4d7d93da5cf1fb55d91bf2eca181efaad1 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 28 Dec 2018 15:23:38 -0300 >Subject: [PATCH] Bug 22049: Add tests > >The current tests only check some failure use cases. This patch makes it cover more use cases > >To test: >- Apply this patchset >- Run: > $ kshell > k$ prove t/db_dependent/Circulation/MarkIssueReturned.t >=> SUCCESS: Tests pass! > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >--- > t/db_dependent/Circulation/MarkIssueReturned.t | 184 +++++++++++++++++++------ > 1 file changed, 139 insertions(+), 45 deletions(-) > >diff --git a/t/db_dependent/Circulation/MarkIssueReturned.t b/t/db_dependent/Circulation/MarkIssueReturned.t >index 5538e1b..8b9a6f9 100644 >--- a/t/db_dependent/Circulation/MarkIssueReturned.t >+++ b/t/db_dependent/Circulation/MarkIssueReturned.t >@@ -17,8 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >-use Test::Warn; >+use Test::More tests => 3; >+use Test::Exception; > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -27,63 +27,157 @@ use C4::Circulation; > use C4::Context; > use Koha::Checkouts; > use Koha::Database; >+use Koha::Old::Checkouts; > use Koha::Patrons; > > my $schema = Koha::Database->schema; >-$schema->storage->txn_begin; >- > my $builder = t::lib::TestBuilder->new; > >-my $library = $builder->build({ source => 'Branch' }); >+subtest 'Failure tests' => sub { > >-t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); >+ plan tests => 5; > >-my $patron_category = $builder->build({ source => 'Category', value => { category_type => 'P', enrolmentfee => 0 } }); >-my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } ); >+ $schema->storage->txn_begin; > >-my $biblioitem = $builder->build( { source => 'Biblioitem' } ); >-my $item = $builder->build( >- { >- source => 'Item', >- value => { >- homebranch => $library->{branchcode}, >- holdingbranch => $library->{branchcode}, >- notforloan => 0, >- itemlost => 0, >- withdrawn => 0, >- biblionumber => $biblioitem->{biblionumber}, >+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => { category_type => 'P', enrolmentfee => 0 } } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', >+ value => { branchcode => $library->branchcode, categorycode => $category->categorycode } >+ } >+ ); >+ my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); >+ my $item = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ homebranch => $library->branchcode, >+ holdingbranch => $library->branchcode, >+ notforloan => 0, >+ itemlost => 0, >+ withdrawn => 0, >+ biblionumber => $biblioitem->biblionumber, >+ } > } >- } >-); >+ ); >+ >+ t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); >+ >+ my ( $issue_id, $issue ); >+ # The next call will return undef for invalid item number >+ eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, 'invalid_itemnumber', undef, 0 ) }; >+ is( $@, '', 'No die triggered by invalid itemnumber' ); >+ is( $issue_id, undef, 'No issue_id returned' ); >+ >+ # In the next call we return the item and try it another time >+ $issue = C4::Circulation::AddIssue( $patron, $item->barcode ); >+ eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) }; >+ is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" ); >+ eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) }; >+ is( $@, '', 'No crash on returning item twice' ); >+ is( $issue_id, undef, 'Cannot return an item twice' ); >+ >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Anonymous patron tests' => sub { > >-subtest 'anonymous patron' => sub { > plan tests => 2; >- # The next call will raise an error, because data are not correctly set >- t::lib::Mocks::mock_preference('AnonymousPatron', ''); >- my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); >- eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 2 ) }; >+ >+ $schema->storage->txn_begin; >+ >+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => { category_type => 'P', enrolmentfee => 0 } } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', >+ value => { branchcode => $library->branchcode, categorycode => $category->categorycode } >+ } >+ ); >+ my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); >+ my $item = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ homebranch => $library->branchcode, >+ holdingbranch => $library->branchcode, >+ notforloan => 0, >+ itemlost => 0, >+ withdrawn => 0, >+ biblionumber => $biblioitem->biblionumber, >+ } >+ } >+ ); >+ >+ t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); >+ >+ # Anonymous patron not set >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); >+ >+ my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); >+ eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) }; > like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' ); > Koha::Checkouts->find( $issue->issue_id )->delete; > >- my $anonymous_borrowernumber = Koha::Patron->new({categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode} })->store->borrowernumber; >- t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber); >- $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); >- eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 2 ) }; >+ # Create a valid anonymous user >+ my $anonymous = $builder->build_object({ >+ class => 'Koha::Patrons', >+ value => { >+ categorycode => $category->categorycode, >+ branchcode => $library->branchcode >+ } >+ }); >+ t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous->borrowernumber); >+ $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); >+ >+ eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) }; > is ( $@, q||, 'AnonymousPatron is set correctly - no error expected'); >+ >+ $schema->storage->txn_rollback; > }; > >-my ( $issue_id, $issue ); >-# The next call will return undef for invalid item number >-eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', undef, 0 ) }; >-is( $@, '', 'No die triggered by invalid itemnumber' ); >-is( $issue_id, undef, 'No issue_id returned' ); >- >-# In the next call we return the item and try it another time >-$issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); >-eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 0 ) }; >-is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" ); >-eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 0 ) }; >-is( $@, '', 'No crash on returning item twice' ); >-is( $issue_id, undef, 'Cannot return an item twice' ); >- >-$schema->storage->txn_rollback; >+subtest 'Manually pass a return date' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => { category_type => 'P', enrolmentfee => 0 } } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', >+ value => { branchcode => $library->branchcode, categorycode => $category->categorycode } >+ } >+ ); >+ my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); >+ my $item = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ homebranch => $library->branchcode, >+ holdingbranch => $library->branchcode, >+ notforloan => 0, >+ itemlost => 0, >+ withdrawn => 0, >+ biblionumber => $biblioitem->biblionumber, >+ } >+ } >+ ); >+ >+ t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); >+ >+ my ( $issue, $issue_id ); >+ >+ $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); >+ $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, '2018-12-25', 0 ); >+ >+ is( $issue_id, $issue->issue_id, "Item has been returned" ); >+ my $old_checkout = Koha::Old::Checkouts->find( $issue_id ); >+ is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' ); >+ >+ $issue = C4::Circulation::AddIssue( $patron, $item->barcode ); >+ >+ throws_ok >+ { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 ); } >+ 'Koha::Exceptions::Object::BadValue', >+ 'An exception is thrown on bad date'; >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.1.4
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 22049
:
83542
|
83543
|
83544
|
83548
|
83549
|
83625
|
83626
|
83627
|
83654
|
83655
|
83656
|
83727
|
83728
|
83729
|
83730
|
85498