Link Here
|
30 |
|
30 |
|
31 |
use Test::More tests => 9; |
31 |
use Test::More tests => 9; |
32 |
|
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
34 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
35 |
use_ok('Koha::Illcomment'); |
35 |
use_ok('Koha::ILL::Comment'); |
36 |
use_ok('Koha::Illcomments'); |
36 |
use_ok('Koha::ILL::Comments'); |
37 |
|
37 |
|
38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
39 |
|
39 |
|
40 |
Koha::Illrequests->search->delete; |
40 |
Koha::Illrequests->search->delete; |
41 |
|
41 |
|
42 |
# Create a patron |
42 |
# Create a patron |
43 |
my $patron = $builder->build({ source => 'Borrower' }); |
43 |
my $patron = $builder->build( { source => 'Borrower' } ); |
44 |
|
44 |
|
45 |
# Create an ILL request |
45 |
# Create an ILL request |
46 |
my $illrq = $builder->build({ |
46 |
my $illrq = $builder->build( |
47 |
source => 'Illrequest', |
47 |
{ |
48 |
value => { borrowernumber => $patron->{borrowernumber} } |
48 |
source => 'Illrequest', |
49 |
}); |
49 |
value => { borrowernumber => $patron->{borrowernumber} } |
50 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
50 |
} |
|
|
51 |
); |
52 |
my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} ); |
51 |
isa_ok( $illrq_obj, 'Koha::Illrequest' ); |
53 |
isa_ok( $illrq_obj, 'Koha::Illrequest' ); |
52 |
|
54 |
|
53 |
# Create a librarian |
55 |
# Create a librarian |
54 |
my $librarian = $builder->build({ source => 'Borrower' }); |
56 |
my $librarian = $builder->build( { source => 'Borrower' } ); |
55 |
|
57 |
|
56 |
# Create a comment and tie it to the request and the librarian |
58 |
# Create a comment and tie it to the request and the librarian |
57 |
my $comment_text = 'xyz'; |
59 |
my $comment_text = 'xyz'; |
58 |
my $illcomment = $builder->build({ |
60 |
my $illcomment = $builder->build( |
59 |
source => 'Illcomment', |
61 |
{ |
60 |
value => { |
62 |
source => 'Illcomment', |
61 |
illrequest_id => $illrq_obj->illrequest_id, |
63 |
value => { |
62 |
borrowernumber => $librarian->{borrowernumber}, |
64 |
illrequest_id => $illrq_obj->illrequest_id, |
63 |
comment => $comment_text, |
65 |
borrowernumber => $librarian->{borrowernumber}, |
|
|
66 |
comment => $comment_text, |
67 |
} |
64 |
} |
68 |
} |
65 |
}); |
69 |
); |
66 |
|
70 |
|
67 |
# Get all the comments |
71 |
# Get all the comments |
68 |
my $comments = $illrq_obj->illcomments; |
72 |
my $comments = $illrq_obj->illcomments; |
69 |
isa_ok( $comments, 'Koha::Illcomments', "Illcomments" ); |
73 |
isa_ok( $comments, 'Koha::ILL::Comments', "Illcomments" ); |
70 |
my @comments_list = $comments->as_list(); |
74 |
my @comments_list = $comments->as_list(); |
71 |
is( scalar @comments_list, 1, "We have 1 comment" ); |
75 |
is( scalar @comments_list, 1, "We have 1 comment" ); |
72 |
|
76 |
|
73 |
# Get the first (and only) comment |
77 |
# Get the first (and only) comment |
74 |
my $comment = $comments->next(); |
78 |
my $comment = $comments->next(); |
75 |
isa_ok( $comment, 'Koha::Illcomment', "Illcomment" ); |
79 |
isa_ok( $comment, 'Koha::ILL::Comment', "Illcomment" ); |
76 |
|
80 |
|
77 |
# Check the different data in the comment |
81 |
# Check the different data in the comment |
78 |
is( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' ); |
82 |
is( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' ); |
79 |
is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works'); |
83 |
is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works' ); |
80 |
is( $comment->comment, $comment_text, 'comment getter works'); |
84 |
is( $comment->comment, $comment_text, 'comment getter works' ); |
81 |
|
85 |
|
82 |
$illrq_obj->delete; |
86 |
$illrq_obj->delete; |
83 |
|
87 |
|