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 File::Basename qw/basename/;
22 use Koha::Illrequests;
23 use Koha::Illrequestattributes;
24 use Koha::Illrequest::Config;
27 use t::lib::TestBuilder;
31 use Test::More tests => 9;
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
35 use_ok('Koha::ILL::Comment');
36 use_ok('Koha::ILL::Comments');
38 $schema->storage->txn_begin;
40 Koha::Illrequests->search->delete;
43 my $patron = $builder->build( { source => 'Borrower' } );
45 # Create an ILL request
46 my $illrq = $builder->build(
48 source => 'Illrequest',
49 value => { borrowernumber => $patron->{borrowernumber} }
52 my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
53 isa_ok( $illrq_obj, 'Koha::Illrequest' );
56 my $librarian = $builder->build( { source => 'Borrower' } );
58 # Create a comment and tie it to the request and the librarian
59 my $comment_text = 'xyz';
60 my $illcomment = $builder->build(
62 source => 'Illcomment',
64 illrequest_id => $illrq_obj->illrequest_id,
65 borrowernumber => $librarian->{borrowernumber},
66 comment => $comment_text,
71 # Get all the comments
72 my $comments = $illrq_obj->illcomments;
73 isa_ok( $comments, 'Koha::ILL::Comments', "Illcomments" );
74 my @comments_list = $comments->as_list();
75 is( scalar @comments_list, 1, "We have 1 comment" );
77 # Get the first (and only) comment
78 my $comment = $comments->next();
79 isa_ok( $comment, 'Koha::ILL::Comment', "Illcomment" );
81 # Check the different data in the comment
82 is( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' );
83 is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works' );
84 is( $comment->comment, $comment_text, 'comment getter works' );
88 $schema->storage->txn_rollback;