Bug 35581: Koha::Illcomment* -> Koha::ILL::Comment*
[koha.git] / t / db_dependent / Koha / ILL / Comments.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use File::Basename qw/basename/;
21 use Koha::Database;
22 use Koha::Illrequests;
23 use Koha::Illrequestattributes;
24 use Koha::Illrequest::Config;
25 use Koha::Patrons;
26 use t::lib::Mocks;
27 use t::lib::TestBuilder;
28 use Test::MockObject;
29 use Test::MockModule;
30
31 use Test::More tests => 9;
32
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');
37
38 $schema->storage->txn_begin;
39
40 Koha::Illrequests->search->delete;
41
42 # Create a patron
43 my $patron = $builder->build( { source => 'Borrower' } );
44
45 # Create an ILL request
46 my $illrq = $builder->build(
47     {
48         source => 'Illrequest',
49         value  => { borrowernumber => $patron->{borrowernumber} }
50     }
51 );
52 my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
53 isa_ok( $illrq_obj, 'Koha::Illrequest' );
54
55 # Create a librarian
56 my $librarian = $builder->build( { source => 'Borrower' } );
57
58 # Create a comment and tie it to the request and the librarian
59 my $comment_text = 'xyz';
60 my $illcomment   = $builder->build(
61     {
62         source => 'Illcomment',
63         value  => {
64             illrequest_id  => $illrq_obj->illrequest_id,
65             borrowernumber => $librarian->{borrowernumber},
66             comment        => $comment_text,
67         }
68     }
69 );
70
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" );
76
77 # Get the first (and only) comment
78 my $comment = $comments->next();
79 isa_ok( $comment, 'Koha::ILL::Comment', "Illcomment" );
80
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' );
85
86 $illrq_obj->delete;
87
88 $schema->storage->txn_rollback;