]> git.koha-community.org Git - koha.git/blob - t/db_dependent/Barcodes_ValueBuilder.t
Bug 15081: (followup) Make test files using TestBuilder handle their transactions
[koha.git] / t / db_dependent / Barcodes_ValueBuilder.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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, see <http://www.gnu.org/licenses>.
16
17 use Modern::Perl;
18
19 use Test::More tests => 7;
20 use Test::MockModule;
21 use t::lib::TestBuilder;
22
23 use Koha::Database;
24
25 BEGIN {
26     use_ok('C4::Barcodes::ValueBuilder');
27 };
28
29 my $schema  = Koha::Database->new->schema;
30 $schema->storage->txn_begin;
31
32 my $builder = t::lib::TestBuilder->new;
33
34 my $dbh = C4::Context->dbh;
35 $dbh->do(q|DELETE FROM items|);
36 my $item_1 = $builder->build({
37     source => 'Item',
38     value => {
39         barcode => '33333074344563'
40     }
41 });
42 my $item_2 = $builder->build({
43     source => 'Item',
44     value => {
45         barcode => 'hb12070890'
46     }
47 });
48 my $item_3 = $builder->build({
49     source => 'Item',
50     value => {
51         barcode => '2012-0034'
52     }
53 });
54
55 my %args = (
56     year        => '2012',
57     mon         => '07',
58     day         => '30',
59     tag         => '952',
60     subfield    => 'p',
61     loctag      => '952',
62     locsubfield => 'a'
63 );
64
65 my ($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args);
66 is($nextnum, 33333074344564, 'incremental barcode');
67 is($scr, undef, 'incremental javascript');
68
69 ($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args);
70 is($nextnum, '12070891', 'hbyymmincr barcode');
71 ok(length($scr) > 0, 'hbyymmincr javascript');
72
73 ($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
74 is($nextnum, '2012-0035', 'annual barcode');
75 is($scr, undef, 'annual javascript');
76
77 $schema->storage->txn_rollback;
78
79 1;