3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 3;
25 use t::lib::TestBuilder;
29 # Mock userenv, used by AddIssue
32 my $context = Test::MockModule->new('C4::Context');
38 number => $manager_id,
45 my $schema = Koha::Database->schema;
46 $schema->storage->txn_begin;
48 my $builder = t::lib::TestBuilder->new();
49 Koha::CirculationRules->set_rule(
52 categorycode => undef,
54 rule_name => 'issuelength',
59 $branch = $builder->build( { source => 'Branch' } )->{branchcode};
61 subtest 'Test Koha::Checkout::claim_returned, do not mark as returned' => sub {
64 t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
65 t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{} );
66 my $item = $builder->build_sample_item;
67 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
68 my $checkout = AddIssue( $patron->unblessed, $item->barcode );
70 my $claim = $checkout->claim_returned(
72 created_by => $patron->id,
77 is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
78 is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
79 is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
80 is( $claim->notes, "Test note", "Claim notes match" );
81 is( $claim->created_by, $patron->id, "Claim created_by matches" );
82 ok( $claim->created_on, "Claim created_on is set" );
84 my $checkout2 = Koha::Checkouts->find( $checkout->id );
85 is( $checkout2->id, $checkout->id, "Item is still checked out to patron")
88 subtest 'Test Koha::Patronn::return_claims' => sub {
91 t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
92 my $item = $builder->build_sample_item;
93 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
94 my $checkout = AddIssue( $patron->unblessed, $item->barcode );
96 $checkout->claim_returned(
98 created_by => $patron->id,
103 my $claims = $patron->return_claims;
105 is( $claims->count, 1, "Got back correct number of claims" );
107 my $claim = $claims->next;
109 is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
110 is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
111 is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
112 is( $claim->notes, "Test note", "Claim notes match" );
113 is( $claim->created_by, $patron->id, "Claim created_by matches" );
114 ok( $claim->created_on, "Claim created_on is set" );
117 subtest 'Test Koha::Checkout::claim_returned, mark as returned' => sub {
120 t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
121 t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} );
122 my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
123 my $item = $builder->build_object(
125 class => 'Koha::Items',
127 biblionumber => $biblio->biblionumber,
134 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
135 my $checkout = AddIssue( $patron->unblessed, $item->barcode );
137 my $claim = $checkout->claim_returned(
139 created_by => $patron->id,
140 notes => "Test note",
144 is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
145 is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
146 is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
147 is( $claim->notes, "Test note", "Claim notes match" );
148 is( $claim->created_by, $patron->id, "Claim created_by matches" );
149 ok( $claim->created_on, "Claim created_on is set" );
151 my $checkout2 = Koha::Checkouts->find( $checkout->id );
152 is( $checkout2, undef, "Checkout is not longer in the issues table");
153 $checkout2 = Koha::Old::Checkouts->find( $checkout->id );
154 is( $checkout2->id, $checkout->id, "Checkout was foudn in the old_issues table");
157 $schema->storage->txn_rollback;