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 => 2;
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' => sub {
64 t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
65 my $item = $builder->build_sample_item;
66 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
67 my $checkout = AddIssue( $patron->unblessed, $item->barcode );
69 my $claim = $checkout->claim_returned(
71 created_by => $patron->id,
76 is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
77 is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
78 is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
79 is( $claim->notes, "Test note", "Claim notes match" );
80 is( $claim->created_by, $patron->id, "Claim created_by matches" );
81 ok( $claim->created_on, "Claim created_on is set" );
84 subtest 'Test Koha::Patronn::return_claims' => sub {
87 t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
88 my $item = $builder->build_sample_item;
89 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
90 my $checkout = AddIssue( $patron->unblessed, $item->barcode );
92 $checkout->claim_returned(
94 created_by => $patron->id,
99 my $claims = $patron->return_claims;
101 is( $claims->count, 1, "Got back correct number of claims" );
103 my $claim = $claims->next;
105 is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
106 is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
107 is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
108 is( $claim->notes, "Test note", "Claim notes match" );
109 is( $claim->created_by, $patron->id, "Claim created_by matches" );
110 ok( $claim->created_on, "Claim created_on is set" );
113 $schema->storage->txn_rollback;