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 => 1;
24 use Koha::Checkouts::ReturnClaims;
26 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new;
31 subtest "store() tests" => sub {
35 $schema->storage->txn_begin;
37 my $librarian = $builder->build_object({ class => 'Koha::Patrons' });
38 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
39 my $item = $builder->build_sample_item;
41 my $checkout = $builder->build_object(
43 class => 'Koha::Checkouts',
45 borrowernumber => $patron->borrowernumber,
46 itemnumber => $item->itemnumber,
47 branchcode => $patron->branchcode
53 { Koha::Checkouts::ReturnClaim->new(
55 issue_id => $checkout->id,
56 itemnumber => $checkout->itemnumber,
57 borrowernumber => $checkout->borrowernumber,
61 'Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy',
62 'Exception thrown correctly';
64 is( Koha::Checkouts::ReturnClaims->search({ issue_id => $checkout->id })->count, 0, 'No claims stored' );
66 my $claim = Koha::Checkouts::ReturnClaim->new(
68 issue_id => $checkout->id,
69 itemnumber => $checkout->itemnumber,
70 borrowernumber => $checkout->borrowernumber,
71 notes => 'Some notes',
72 created_by => $librarian->borrowernumber
76 is( ref($claim), 'Koha::Checkouts::ReturnClaim', 'Object type is correct' );
77 is( Koha::Checkouts::ReturnClaims->search( { issue_id => $checkout->id } )->count, 1, 'Claim stored on the DB');
79 { # hide useless warnings
81 open STDERR, '>', '/dev/null';
83 Koha::Checkouts::ReturnClaim->new(
85 issue_id => $checkout->id,
86 itemnumber => $checkout->itemnumber,
87 borrowernumber => $checkout->borrowernumber,
88 notes => 'Some notes',
89 created_by => $librarian->borrowernumber
93 'Koha::Exceptions::Object::DuplicateID',
94 'An exception is thrown on duplicate issue_id';
99 qr/(return_claims\.)?issue_id/,
100 'Exception field is correct'
104 { # hide useless warnings
106 open STDERR, '>', '/dev/null';
108 my $another_checkout = $builder->build_object({ class => 'Koha::Checkouts' });
109 my $checkout_id = $another_checkout->id;
110 $another_checkout->delete;
115 $THE_claim = Koha::Checkouts::ReturnClaim->new(
117 issue_id => $checkout_id,
118 itemnumber => $checkout->itemnumber,
119 borrowernumber => $checkout->borrowernumber,
120 notes => 'Some notes',
121 created_by => $librarian->borrowernumber
125 'Koha::Exceptions::Object::FKConstraint',
126 'An exception is thrown on invalid issue_id';
129 is( $@->broken_fk, 'issue_id', 'Exception field is correct' );
132 $schema->storage->txn_rollback;