3 # Copyright 2023 Koha Development team
5 # This file is part of Koha
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.
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.
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>.
22 use Test::More tests => 5;
23 use t::lib::TestBuilder;
27 my $builder = t::lib::TestBuilder->new;
28 my $schema = Koha::Database->new->schema;
30 subtest 'reporter() tests' => sub {
34 $schema->storage->txn_begin;
36 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
37 my $ticket = $builder->build_object(
39 class => 'Koha::Tickets',
41 reporter_id => $patron->id
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' );
50 $schema->storage->txn_rollback;
53 subtest 'resolver() tests' => sub {
57 $schema->storage->txn_begin;
59 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
60 my $ticket = $builder->build_object(
62 class => 'Koha::Tickets',
64 resolver_id => $patron->id
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' );
73 $schema->storage->txn_rollback;
76 subtest 'biblio() tests' => sub {
80 $schema->storage->txn_begin;
82 my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
83 my $ticket = $builder->build_object(
85 class => 'Koha::Tickets',
87 biblio_id => $biblio->id
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' );
96 $schema->storage->txn_rollback;
99 subtest 'updates() tests' => sub {
103 $schema->storage->txn_begin;
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' );
112 $builder->build_object(
114 class => 'Koha::Ticket::Updates',
115 value => { ticket_id => $ticket->id }
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' );
124 $schema->storage->txn_rollback;
127 subtest 'add_update() tests' => sub {
130 $schema->storage->txn_begin;
132 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
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'
141 my $updates = $ticket->updates;
142 is( $updates->count, 1,
143 'Koha::Ticket->add_update should have added 1 update linked to this ticket'
146 $schema->storage->txn_rollback;