Bug 29387: (QA follow-up) Fix modules in test
[koha.git] / t / db_dependent / Koha / Subscription / Numberpatterns.t
1 #!/usr/bin/perl
2
3 # Copyright 2017 BibLibre
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 t::lib::TestBuilder;
23 use Test::More tests => 6;
24 use Koha::Database;
25
26 use_ok('Koha::Subscription::Numberpatterns');
27
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
30 my $builder = t::lib::TestBuilder->new;
31
32 my $dbh = C4::Context->dbh;
33 $dbh->do('DELETE FROM subscription_numberpatterns');
34
35 my $numberpattern = $builder->build({
36     source => 'SubscriptionNumberpattern',
37     value => {
38         label => 'Volume, Number, Issue',
39         description => 'Volume Number Issue 1',
40         numberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
41         label1 => 'Volume',
42         add1 => '1',
43         every1 => '48',
44         whenmorethan1 => '99999',
45         setto1 => '1',
46         numbering1 => undef,
47         label2 => 'Number',
48         add2 => '1',
49         every2 => '4',
50         whenmorethan2 => '12',
51         setto2 => '1',
52         numbering2 => undef,
53         label3 => 'Issue',
54         add3 => '1',
55         every3 => '1',
56         whenmorethan3 => '4',
57         setto3 => '1',
58         numbering3 => undef
59     }
60 });
61
62 my $search_ok = {
63     umberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
64     label1 => 'Volume', add1 => '1', every1 => '48',
65     whenmorethan1 => '99999', setto1 => '1',
66     label2 => 'Number', add2 => '1', every2 => '4',
67     whenmorethan2 => '12', setto2 => '1',
68     label3 => 'Issue', add3 => '1', every3 => '1',
69     whenmorethan3 => '4', setto3 => '1',
70     numbering_pattern => 'mana'
71 };
72
73 my $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_ok);
74 is($number_pattern_id, $numberpattern->{id}, 'new_or_existing method should find the existing number pattern');
75
76 $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing({numbering_pattern => 1});
77 is($number_pattern_id, 1, 'new_or_existing method should return passed numbering_pattern');
78
79 my $search_not_ok = {
80     patternname => 'Number',
81     sndescription => 'Simple Numbering method',
82     numberingmethod => 'No.{X}',
83     label1 => 'Number',
84     add1 => 1,
85     every1 => 1,
86     whenmorethan1 => 99999,
87     setto1 => 1,
88     numbering_pattern => 'mana'
89 };
90
91 $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_not_ok);
92 my $new_number_pattern = Koha::Subscription::Numberpatterns->find($number_pattern_id);
93 is($new_number_pattern->label, 'Number');
94 is($new_number_pattern->description, 'Simple Numbering method');
95 is($new_number_pattern->numberingmethod, 'No.{X}');
96
97 $schema->storage->txn_rollback;