3 # Copyright 2017 BibLibre
5 # This file is part of Koha
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.
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.
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>.
22 use t::lib::TestBuilder;
23 use Test::More tests => 6;
26 use_ok('Koha::Subscription::Numberpatterns');
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
30 my $builder = t::lib::TestBuilder->new;
32 my $dbh = C4::Context->dbh;
33 $dbh->do('DELETE FROM subscription_numberpatterns');
35 my $numberpattern = $builder->build({
36 source => 'SubscriptionNumberpattern',
38 label => 'Volume, Number, Issue',
39 description => 'Volume Number Issue 1',
40 numberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
44 whenmorethan1 => '99999',
50 whenmorethan2 => '12',
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'
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');
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');
80 patternname => 'Number',
81 sndescription => 'Simple Numbering method',
82 numberingmethod => 'No.{X}',
86 whenmorethan1 => 99999,
88 numbering_pattern => 'mana'
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}');
97 $schema->storage->txn_rollback;