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

(-)a/t/db_dependent/Koha/Account/Lines.t (-25 / +55 lines)
Lines 1209-1254 subtest "reduce() tests" => sub { Link Here
1209
};
1209
};
1210
1210
1211
subtest 'checkout' => sub {
1211
subtest 'checkout' => sub {
1212
    plan tests => 1;
1212
    plan tests => 5;
1213
1213
1214
    $schema->storage->txn_begin;
1214
    $schema->storage->txn_begin;
1215
1215
1216
    my $library    = $builder->build( { source => 'Branch' } );
1216
    my $library = $builder->build_object({ class => 'Koha::Libraries' } );
1217
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1217
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' } );
1218
    my $patron     = $builder->build( { source => 'Borrower' } );
1218
    my $item_1  = $builder->build_sample_item({ library => $library->branchcode });
1219
    my $item       = Koha::Item->new(
1220
        {
1221
            biblionumber     => $biblioitem->{biblionumber},
1222
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1223
            homebranch       => $library->{branchcode},
1224
            holdingbranch    => $library->{branchcode},
1225
            barcode          => 'some_barcode_13',
1226
            itype            => 'BK',
1227
        }
1228
    )->store;
1229
1219
1230
    my $checkout = Koha::Checkout->new(
1220
    my $checkout = Koha::Checkout->new(
1231
        {
1221
        {
1232
            borrowernumber => $patron->{borrowernumber},
1222
            borrowernumber => $patron->borrowernumber,
1233
            itemnumber     => $item->itemnumber,
1223
            itemnumber     => $item_1->itemnumber,
1234
            branchcode     => $library->{branchcode},
1224
            branchcode     => $library->branchcode,
1235
        }
1225
        }
1236
    )->store;
1226
    )->store;
1237
1227
1238
    my $line = Koha::Account::Line->new(
1228
    my $line = $builder->build_object(
1239
        {
1229
        {
1240
            borrowernumber => $patron->{borrowernumber},
1230
            class => 'Koha::Account::Lines',
1241
            itemnumber     => $item->itemnumber,
1231
            value => {
1242
            issue_id       => $checkout->id,
1232
                borrowernumber => $patron->borrowernumber,
1243
            accounttype    => "F",
1233
                itemnumber     => $item_1->itemnumber,
1244
            amount         => 10,
1234
                issue_id       => $checkout->id,
1245
            interface      => 'commandline',
1235
            }
1246
        }
1236
        }
1247
    )->store;
1237
    );
1248
1238
1239
    is( ref($line->checkout), 'Koha::Checkout', 'Object type is correct' );
1249
    is( $line->checkout->id, $checkout->id,
1240
    is( $line->checkout->id, $checkout->id,
1250
        'Koha::Account::Line->checkout should return the correct checkout' );
1241
        'Koha::Account::Line->checkout should return the correct checkout' );
1251
1242
1243
    my $item_2 = $builder->build_sample_item({ library => $library->branchcode });
1244
    my $old_checkout = $builder->build_object(
1245
        {
1246
            class => 'Koha::Old::Checkouts',
1247
            value => {
1248
                borrowernumber => $patron->borrowernumber,
1249
                itemnumber     => $item_2->itemnumber,
1250
                branchcode     => $library->branchcode
1251
            }
1252
        }
1253
    );
1254
1255
    my $old_checkout_line = $builder->build_object(
1256
        {
1257
            class => 'Koha::Account::Lines',
1258
            value => {
1259
                borrowernumber => $patron->borrowernumber,
1260
                itemnumber     => $item_2->itemnumber,
1261
                issue_id       => $old_checkout->id,
1262
            }
1263
        }
1264
    );
1265
1266
    is( ref($old_checkout_line->checkout), 'Koha::Old::Checkout', 'Object type is correct' );
1267
    is( $old_checkout_line->checkout->id, $old_checkout->id,
1268
        'Koha::Account::Line->checkout should return the correct (old) checkout' );
1269
1270
    my $no_checkout_line = $builder->build_object(
1271
        {
1272
            class => 'Koha::Account::Lines',
1273
            value => {
1274
                itemnumber => $item_2->itemnumber,
1275
                issue_id   => undef
1276
            }
1277
        }
1278
    );
1279
1280
    is( $no_checkout_line->checkout, undef, 'No issue_id makes it return undef' );
1281
1252
    $schema->storage->txn_rollback;
1282
    $schema->storage->txn_rollback;
1253
};
1283
};
1254
1284
(-)a/t/db_dependent/Koha/Checkout.t (-1 / +50 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2020 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 => 1;
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 'library() tests' => sub {
31
32
    plan tests => 2;
33
34
    $schema->storage->txn_begin;
35
36
    my $library  = $builder->build_object({ class => 'Koha::Libraries' }); 
37
    my $checkout = $builder->build_object(
38
        {
39
            class => 'Koha::Checkouts',
40
            value => {
41
                branchcode => $library->branchcode
42
            }
43
        }
44
    );
45
46
    is( ref($checkout->library), 'Koha::Library', 'Object type is correct' );
47
    is( $checkout->library->branchcode, $library->branchcode, 'Right library linked' );
48
49
    $schema->storage->txn_rollback;
50
};

Return to bug 15985