Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2023 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 5; |
23 |
use t::lib::TestBuilder; |
24 |
|
25 |
use Koha::Database; |
26 |
|
27 |
my $builder = t::lib::TestBuilder->new; |
28 |
my $schema = Koha::Database->new->schema; |
29 |
|
30 |
subtest 'reporter() tests' => sub { |
31 |
|
32 |
plan tests => 2; |
33 |
|
34 |
$schema->storage->txn_begin; |
35 |
|
36 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
37 |
my $ticket = $builder->build_object( |
38 |
{ |
39 |
class => 'Koha::Tickets', |
40 |
value => { |
41 |
reporter_id => $patron->id |
42 |
} |
43 |
} |
44 |
); |
45 |
|
46 |
my $reporter = $ticket->reporter; |
47 |
is( ref($reporter), 'Koha::Patron', 'Koha::Ticket->reporter returns a Koha::Patron object' ); |
48 |
is( $reporter->id, $patron->id, 'Koha::Ticket->reporter returns the right Koha::Patron' ); |
49 |
|
50 |
$schema->storage->txn_rollback; |
51 |
}; |
52 |
|
53 |
subtest 'resolver() tests' => sub { |
54 |
|
55 |
plan tests => 2; |
56 |
|
57 |
$schema->storage->txn_begin; |
58 |
|
59 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
60 |
my $ticket = $builder->build_object( |
61 |
{ |
62 |
class => 'Koha::Tickets', |
63 |
value => { |
64 |
resolver_id => $patron->id |
65 |
} |
66 |
} |
67 |
); |
68 |
|
69 |
my $resolver = $ticket->resolver; |
70 |
is( ref($resolver), 'Koha::Patron', 'Koha::Ticket->resolver returns a Koha::Patron object' ); |
71 |
is( $resolver->id, $patron->id, 'Koha::Ticket->resolver returns the right Koha::Patron' ); |
72 |
|
73 |
$schema->storage->txn_rollback; |
74 |
}; |
75 |
|
76 |
subtest 'biblio() tests' => sub { |
77 |
|
78 |
plan tests => 2; |
79 |
|
80 |
$schema->storage->txn_begin; |
81 |
|
82 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
83 |
my $ticket = $builder->build_object( |
84 |
{ |
85 |
class => 'Koha::Tickets', |
86 |
value => { |
87 |
biblio_id => $biblio->id |
88 |
} |
89 |
} |
90 |
); |
91 |
|
92 |
my $related_biblio = $ticket->biblio; |
93 |
is( ref($related_biblio), 'Koha::Biblio', 'Koha::Ticket->biblio returns a Koha::Biblio object' ); |
94 |
is( $related_biblio->id, $biblio->id, 'Koha::Ticket->biblio returns the right Koha::Biblio' ); |
95 |
|
96 |
$schema->storage->txn_rollback; |
97 |
}; |
98 |
|
99 |
subtest 'updates() tests' => sub { |
100 |
|
101 |
plan tests => 4; |
102 |
|
103 |
$schema->storage->txn_begin; |
104 |
|
105 |
my $ticket = $builder->build_object( { class => 'Koha::Tickets' } ); |
106 |
my $updates = $ticket->updates; |
107 |
is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' ); |
108 |
is( $updates->count, 0, 'Koha::Ticket->updates should return a count of 0 when there are no related updates' ); |
109 |
|
110 |
# Add two updates |
111 |
foreach (1..2) { |
112 |
$builder->build_object( |
113 |
{ |
114 |
class => 'Koha::Ticket::Updates', |
115 |
value => { ticket_id => $ticket->id } |
116 |
} |
117 |
); |
118 |
} |
119 |
|
120 |
$updates = $ticket->updates; |
121 |
is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' ); |
122 |
is( $updates->count, 2, 'Koha::Ticket->updates should return the correct number of updates' ); |
123 |
|
124 |
$schema->storage->txn_rollback; |
125 |
}; |
126 |
|
127 |
subtest 'add_update() tests' => sub { |
128 |
plan tests => 2; |
129 |
|
130 |
$schema->storage->txn_begin; |
131 |
|
132 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
133 |
|
134 |
my $ticket = $builder->build_object( { class => 'Koha::Tickets' } ); |
135 |
my $update = $ticket->add_update( |
136 |
{ user_id => $patron->id, public => 1, message => "Some message" } ); |
137 |
is( ref($update), 'Koha::Ticket::Update', |
138 |
'Koha::Ticket->add_update should return a Koha::Ticket::Update object' |
139 |
); |
140 |
|
141 |
my $updates = $ticket->updates; |
142 |
is( $updates->count, 1, |
143 |
'Koha::Ticket->add_update should have added 1 update linked to this ticket' |
144 |
); |
145 |
|
146 |
$schema->storage->txn_rollback; |
147 |
}; |