Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Koha / Subscription / Routinglists.t
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 should have received a copy of the GNU General Public License
16 # along 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 my $builder = t::lib::TestBuilder->new;
32
33 subtest 'new() tests' => sub {
34     plan tests => 4;
35
36     $schema->storage->txn_begin;
37
38     my $biblio = Koha::Biblio->new()->store();
39     my $subscription = Koha::Subscription->new({
40         biblionumber => $biblio->biblionumber,
41         }
42     )->store;
43
44     my $library = $builder->build_object({ class => 'Koha::Libraries' });
45     my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->id } });
46
47     my $routinglist_count = Koha::Subscription::Routinglists->count;
48     my $routinglist = Koha::Subscription::Routinglist->new({
49         borrowernumber   => $patron->borrowernumber,
50         ranking          => 1,
51         subscriptionid   => $subscription->subscriptionid
52     })->store;
53
54     is( Koha::Subscription::Routinglists->search->count, $routinglist_count +1, 'One routing list added' );
55
56     my $retrieved_routinglist = Koha::Subscription::Routinglists->find( $routinglist->routingid );
57     is ( $retrieved_routinglist->routingid, $routinglist->routingid, "Find a routing list by id returns the correct routing list");
58
59     $routinglist->ranking(4)->update;
60     is ( $routinglist->ranking, 4, "Routing list ranking has been updated");
61
62     $routinglist->delete;
63     is ( Koha::Subscription::Routinglists->search->count, $routinglist_count, 'One subscription list deleted' );
64
65 };
66
67 $schema->storage->txn_rollback;