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::Illcomment');
36 use_ok
('Koha::Illcomments');
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({
47 source
=> 'Illrequest',
48 value
=> { borrowernumber
=> $patron->{borrowernumber
} }
50 my $illrq_obj = Koha
::Illrequests
->find($illrq->{illrequest_id
});
51 isa_ok
( $illrq_obj, 'Koha::Illrequest' );
54 my $librarian = $builder->build({ source
=> 'Borrower' });
56 # Create a comment and tie it to the request and the librarian
57 my $comment_text = 'xyz';
58 my $illcomment = $builder->build({
59 source
=> 'Illcomment',
61 illrequest_id
=> $illrq_obj->illrequest_id,
62 borrowernumber
=> $librarian->{borrowernumber
},
63 comment
=> $comment_text,
67 # Get all the comments
68 my $comments = $illrq_obj->illcomments;
69 isa_ok
( $comments, 'Koha::Illcomments', "Illcomments" );
70 my @comments_list = $comments->as_list();
71 is
( scalar @comments_list, 1, "We have 1 comment" );
73 # Get the first (and only) comment
74 my $comment = $comments->next();
75 isa_ok
( $comment, 'Koha::Illcomment', "Illcomment" );
77 # Check the different data in the comment
78 is
( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' );
79 is
( $comment->borrowernumber, $librarian->{borrowernumber
}, 'borrowernumber getter works');
80 is
( $comment->comment, $comment_text, 'comment getter works');
84 $schema->storage->txn_rollback;