Koha/t/Barcodes_ValueBuilder.t
Jared Camins-Esakov a2186855b3 Bug 8524: Add a non-automatic barcode plugin
In addition to adding a new barcode plugin, this commit begins
refactoring the barcode generation code using a new module,
C4::Barcodes::ValueBuilder. From the POD:
    This module is intended as a shim to ease the eventual transition
    from having all barcode-related code in the value builder plugin
    barcode.pl file to using C4::Barcodes. Since the shift will require
    a rather significant amount of refactoring, this module will return
    value builder-formatted results, at first by merely running the
    code that was formerly in the barcodes.pl value builder, but later
    by using C4::Barcodes.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2012-08-31 17:42:26 +02:00

77 lines
2.2 KiB
Perl

#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Test::More tests => 15;
use Test::MockModule;
BEGIN {
use_ok('C4::Barcodes::ValueBuilder');
}
my $module = new Test::MockModule('C4::Context');
$module->mock('_new_dbh', sub {
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|| die "Cannot create handle: $DBI::errstr\n";
return $dbh });
# Mock data
my $incrementaldata = [
['max(abs(barcode))'],
['33333074344563'],
];
my $dbh = C4::Context->dbh();
my %args = (
year => '2012',
mon => '07',
day => '30',
tag => '952',
subfield => 'p',
loctag => '952',
locsubfield => 'a'
);
$dbh->{mock_add_resultset} = $incrementaldata;
my ($nextnum, $scr, $history);
($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args);
is($nextnum, 33333074344564, 'incremental barcode');
ok(length($scr) == 0, 'incremental javascript');
# This should run exactly one query so we can test
$history = $dbh->{mock_all_history};
is(scalar(@{$history}), 1, 'Correct number of statements executed for incremental barcode') ;
my $hbyymmincrdata = [
['number'],
['890'],
];
$dbh->{mock_add_resultset} = $hbyymmincrdata;
$dbh->{mock_clear_history} = 1;
($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args);
is($nextnum, '12070891', 'hbyymmincr barcode');
ok(length($scr) > 0, 'hbyymmincr javascript');
# This should run exactly one query so we can test
$history = $dbh->{mock_all_history};
is(scalar(@{$history}), 1, 'Correct number of statements executed for hbyymmincr barcode') ;
my $annualdata = [
['max(cast( substring_index(barcode, \'-\',-1) as signed))'],
['34'],
];
$dbh->{mock_add_resultset} = $annualdata;
$dbh->{mock_clear_history} = 1;
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
is($nextnum, '2012-0035', 'annual barcode');
ok(length($scr) == 0, 'annual javascript');
# This should run exactly one query so we can test
$history = $dbh->{mock_all_history};
is(scalar(@{$history}), 1, 'Correct number of statements executed for hbyymmincr barcode') ;