View | Details | Raw Unified | Return to bug 35248
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Booking.t (-1 / +97 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2024 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
use utf8;
22
23
use Test::More tests => 1;
24
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
27
28
my $schema  = Koha::Database->new->schema;
29
my $builder = t::lib::TestBuilder->new;
30
31
subtest 'Relation accessor tests' => sub {
32
    plan tests => 3;
33
34
    subtest 'biblio relation tests' => sub {
35
        plan tests => 3;
36
        $schema->storage->txn_begin;
37
38
        my $biblio = $builder->build_sample_biblio;
39
        my $booking =
40
            $builder->build_object( { class => 'Koha::Bookings', value => { biblio_id => $biblio->biblionumber } } );
41
42
        my $THE_biblio = $booking->biblio;
43
        is( ref($THE_biblio),          'Koha::Biblio',        "Koha::Booking->biblio returns a Koha::Biblio object" );
44
        is( $THE_biblio->biblionumber, $biblio->biblionumber, "Koha::Booking->biblio returns the links biblio object" );
45
46
        $THE_biblio->delete;
47
        $booking = Koha::Bookings->find( $booking->booking_id );
48
        is( $booking, undef, "The booking is deleted when the biblio it's attached to is deleted" );
49
50
        $schema->storage->txn_rollback;
51
    };
52
53
    subtest 'patron relation tests' => sub {
54
        plan tests => 3;
55
        $schema->storage->txn_begin;
56
57
        my $patron = $builder->build_object( { class => "Koha::Patrons" } );
58
        my $booking =
59
            $builder->build_object( { class => 'Koha::Bookings', value => { patron_id => $patron->borrowernumber } } );
60
61
        my $THE_patron = $booking->patron;
62
        is( ref($THE_patron), 'Koha::Patron', "Koha::Booking->patron returns a Koha::Patron object" );
63
        is(
64
            $THE_patron->borrowernumber, $patron->borrowernumber,
65
            "Koha::Booking->patron returns the links patron object"
66
        );
67
68
        $THE_patron->delete;
69
        $booking = Koha::Bookings->find( $booking->booking_id );
70
        is( $booking, undef, "The booking is deleted when the patron it's attached to is deleted" );
71
72
        $schema->storage->txn_rollback;
73
    };
74
75
    subtest 'item relation tests' => sub {
76
        plan tests => 3;
77
        $schema->storage->txn_begin;
78
79
        my $item = $builder->build_object( { class => "Koha::Items" } );
80
        my $booking =
81
            $builder->build_object( { class => 'Koha::Bookings', value => { item_id => $item->itemnumber } } );
82
83
        my $THE_item = $booking->item;
84
        is( ref($THE_item), 'Koha::Item', "Koha::Booking->item returns a Koha::Item object" );
85
        is(
86
            $THE_item->itemnumber, $item->itemnumber,
87
            "Koha::Booking->item returns the links item object"
88
        );
89
90
        $THE_item->delete;
91
        $booking = Koha::Bookings->find( $booking->booking_id );
92
        is( $booking, undef, "The booking is deleted when the item it's attached to is deleted" );
93
94
        $schema->storage->txn_rollback;
95
    };
96
97
};

Return to bug 35248