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