5 use Test
::More tests
=> 10;
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";
20 my $incrementaldata = [
21 ['max(abs(barcode))'],
26 my $dbh = C4
::Context
->dbh();
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 = [
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') ;
65 ['max(cast( substring_index(barcode, \'-\',-1) as signed))'],
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') ;