Bug 34932: Patron.t - Pass borrowernumber of manager to userenv
[koha.git] / t / db_dependent / Koha / Ticket / Update.t
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 => 2;
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 'ticket() tests' => sub {
31
32     plan tests => 2;
33
34     $schema->storage->txn_begin;
35
36     my $ticket  = $builder->build_object({ class => 'Koha::Tickets' });
37     my $update = $builder->build_object(
38         {
39             class => 'Koha::Ticket::Updates',
40             value => {
41                 ticket_id => $ticket->id
42             }
43         }
44     );
45
46     my $linked_ticket = $update->ticket;
47     is( ref($linked_ticket), 'Koha::Ticket', 'Koha::Ticket::Update->ticket returns a Koha::Ticket object' );
48     is( $linked_ticket->id, $ticket->id, 'Koha::Ticket::Update->ticket returns the right Koha::Ticket' );
49
50     $schema->storage->txn_rollback;
51 };
52
53 subtest 'user() tests' => sub {
54
55     plan tests => 2;
56
57     $schema->storage->txn_begin;
58
59     my $user  = $builder->build_object({ class => 'Koha::Patrons' });
60     my $update = $builder->build_object(
61         {
62             class => 'Koha::Ticket::Updates',
63             value => {
64                 user_id => $user->id
65             }
66         }
67     );
68
69     my $linked_user = $update->user;
70     is( ref($linked_user), 'Koha::Patron', 'Koha::Ticket::Update->user returns a Koha::Patron object' );
71     is( $linked_user->id, $user->id, 'Koha::Ticket::Update->user returns the right Koha::Patron' );
72
73     $schema->storage->txn_rollback;
74 };