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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +46 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 25;
22
use Test::More tests => 26;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 518-523 subtest 'checkouts + get_overdues + old_checkouts' => sub { Link Here
518
    $module->unmock('userenv');
518
    $module->unmock('userenv');
519
};
519
};
520
520
521
subtest 'get_routinglists' => sub {
522
    plan tests => 5;
523
    
524
    my $biblio = Koha::Biblio->new()->store();
525
    my $subscription = Koha::Subscription->new({
526
        biblionumber => $biblio->biblionumber,
527
        }
528
    )->store;
529
530
    my $patron = $builder->build( { source => 'Borrower' } );
531
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
532
533
    is( $patron->get_routinglists, 0, 'Retrieves correct number of routing lists: 0' );
534
535
    my $routinglist_count = Koha::Subscription::Routinglists->count;
536
    my $routinglist = Koha::Subscription::Routinglist->new({
537
        borrowernumber   => $patron->borrowernumber,
538
        ranking          => 5,
539
        subscriptionid   => $subscription->subscriptionid
540
    })->store;
541
542
    is ($patron->get_routinglists, 1, "Retrieves correct number of routing lists: 1");
543
    
544
    my @routinglists = $patron->get_routinglists;
545
    is ($routinglists[0]->ranking, 5, "Retrieves ranking: 5");
546
    is( ref($routinglists[0]),   'Koha::Subscription::Routinglist', 'get_routinglists returns Koha::Subscription::Routinglist objects' );
547
548
    my $subscription2 = Koha::Subscription->new({
549
        biblionumber => $biblio->biblionumber,
550
        }
551
    )->store;
552
    my $routinglist2 = Koha::Subscription::Routinglist->new({
553
        borrowernumber   => $patron->borrowernumber,
554
        ranking          => 1,
555
        subscriptionid   => $subscription2->subscriptionid
556
    })->store;
557
558
    is ($patron->get_routinglists, 2, "Retrieves correct number of routing lists: 2");
559
560
561
    
562
    $patron->delete; # Clean up for later tests
563
564
};
565
521
subtest 'get_age' => sub {
566
subtest 'get_age' => sub {
522
    plan tests => 7;
567
    plan tests => 7;
523
568
(-)a/t/db_dependent/Koha/Subscription/Routinglists.t (-1 / +69 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WIT HOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You vcshould have received a copy of the GNU General Public License
16
# al           ong with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use t::lib::TestBuilder;
22
23
use C4::Biblio;
24
25
use Koha::Database;
26
use Koha::Patrons;
27
use Koha::Subscriptions;
28
use Koha::Subscription::Routinglists;
29
30
my $schema  = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
33
my $biblio = Koha::Biblio->new()->store();
34
my $subscription = Koha::Subscription->new({
35
    biblionumber => $biblio->biblionumber,
36
    }
37
)->store;
38
39
my $builder = t::lib::TestBuilder->new;
40
my $library = $builder->build({source => 'Branch' });
41
my $category = $builder->build({source => 'Category' });
42
43
my $patron = $builder->build( { source => 'Borrower' } );
44
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
45
46
subtest 'new() tests' => sub {
47
    plan tests => 4;
48
49
    my $routinglist_count = Koha::Subscription::Routinglists->count;
50
    my $routinglist = Koha::Subscription::Routinglist->new({
51
        borrowernumber   => $patron->borrowernumber,
52
        ranking          => 1,
53
        subscriptionid   => $subscription->subscriptionid
54
    })->store;
55
    
56
    is( Koha::Subscription::Routinglists->search->count, $routinglist_count +1, 'One routing list added' );
57
58
    my $retrieved_routinglist = Koha::Subscription::Routinglists->find( $routinglist->routingid );
59
    is ( $retrieved_routinglist->routingid, $routinglist->routingid, "Find a routing list by id returns the correct routing list");
60
    
61
    $routinglist->ranking(4)->update;
62
    is ( $routinglist->ranking, 4, "Routing list ranking has been updated");
63
64
    $routinglist->delete;
65
    is ( Koha::Subscription::Routinglists->search->count, $routinglist_count, 'One subscription list deleted' );
66
    
67
};
68
69
$schema->storage->txn_rollback;

Return to bug 20400