Bug 11876 [Follow-up] Add a diff view to staged MARC Records
[koha.git] / t / Barcodes_ValueBuilder.t
blob64d7fae65335143ac9c80085196279cb73ccee42
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use DBI;
5 use Test::More tests => 10;
6 use Test::MockModule;
8 BEGIN {
9 use_ok('C4::Barcodes::ValueBuilder');
13 my $module = new Test::MockModule('C4::Context');
14 $module->mock('_new_dbh', sub {
15 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
16 || die "Cannot create handle: $DBI::errstr\n";
17 return $dbh });
19 # Mock data
20 my $incrementaldata = [
21 ['max(abs(barcode))'],
22 ['33333074344563'],
26 my $dbh = C4::Context->dbh();
28 my %args = (
29 year => '2012',
30 mon => '07',
31 day => '30',
32 tag => '952',
33 subfield => 'p',
34 loctag => '952',
35 locsubfield => 'a'
38 $dbh->{mock_add_resultset} = $incrementaldata;
39 my ($nextnum, $scr, $history);
41 ($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args);
42 is($nextnum, 33333074344564, 'incremental barcode');
43 is($scr, undef, 'incremental javascript');
45 # This should run exactly one query so we can test
46 $history = $dbh->{mock_all_history};
47 is(scalar(@{$history}), 1, 'Correct number of statements executed for incremental barcode') ;
49 my $hbyymmincrdata = [
50 ['number'],
51 ['890'],
54 $dbh->{mock_add_resultset} = $hbyymmincrdata;
55 $dbh->{mock_clear_history} = 1;
56 ($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args);
57 is($nextnum, '12070891', 'hbyymmincr barcode');
58 ok(length($scr) > 0, 'hbyymmincr javascript');
60 # This should run exactly one query so we can test
61 $history = $dbh->{mock_all_history};
62 is(scalar(@{$history}), 1, 'Correct number of statements executed for hbyymmincr barcode') ;
64 my $annualdata = [
65 ['max(cast( substring_index(barcode, \'-\',-1) as signed))'],
66 ['34'],
69 $dbh->{mock_add_resultset} = $annualdata;
70 $dbh->{mock_clear_history} = 1;
71 ($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
72 is($nextnum, '2012-0035', 'annual barcode');
73 is($scr, undef, 'annual javascript');
75 # This should run exactly one query so we can test
76 $history = $dbh->{mock_all_history};
77 is(scalar(@{$history}), 1, 'Correct number of statements executed for hbyymmincr barcode') ;