From 8ea7e20017e3754365567002b93a3d0ca64ce1f4 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 28 Dec 2018 15:23:38 -0300 Subject: [PATCH] Bug 22049: Add tests The current tests only check failure use cases. As we are changing the way we store data, some tests are needed. To test: - Apply this patchset - Run: $ kshell k$ prove t/db_dependent/Circulation/MarkIssueReturned.t => SUCCESS: Tests pass! --- .../Circulation/MarkIssueReturned.t | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/t/db_dependent/Circulation/MarkIssueReturned.t b/t/db_dependent/Circulation/MarkIssueReturned.t index 5538e1ba99..1915a9582b 100644 --- a/t/db_dependent/Circulation/MarkIssueReturned.t +++ b/t/db_dependent/Circulation/MarkIssueReturned.t @@ -17,7 +17,8 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; +use Test::Exception; use Test::Warn; use t::lib::Mocks; @@ -27,27 +28,28 @@ 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' }); +$schema->storage->txn_begin; + +my $library = $builder->build_object({ class => 'Koha::Libraries' }); -t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); +t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); -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} } } ); +my $category = $builder->build({ source => 'Category', value => { category_type => 'P', enrolmentfee => 0 } }); +my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->branchcode, categorycode => $category->{categorycode} } } ); my $biblioitem = $builder->build( { source => 'Biblioitem' } ); my $item = $builder->build( { source => 'Item', value => { - homebranch => $library->{branchcode}, - holdingbranch => $library->{branchcode}, + homebranch => $library->branchcode, + holdingbranch => $library->branchcode, notforloan => 0, itemlost => 0, withdrawn => 0, @@ -65,13 +67,27 @@ subtest 'anonymous patron' => sub { like ( $@, qr, '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; + my $anonymous_borrowernumber = Koha::Patron->new({categorycode => $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 ) }; is ( $@, q||, 'AnonymousPatron is set correctly - no error expected'); }; +subtest 'Manually pass a return date' => sub { + + plan tests => 2; + + my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); + my $issue_id; + + eval { $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' ); + +}; + 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 ) }; -- 2.20.1