Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
use strict; |
2 |
|
3 |
use warnings; |
3 |
use Modern::Perl; |
4 |
use DBI; |
|
|
5 |
use Test::More tests => 10; |
4 |
use Test::More tests => 10; |
6 |
use Test::MockModule; |
5 |
use Test::MockModule; |
7 |
|
6 |
|
Lines 9-29
BEGIN {
Link Here
|
9 |
use_ok('C4::Barcodes::ValueBuilder'); |
8 |
use_ok('C4::Barcodes::ValueBuilder'); |
10 |
} |
9 |
} |
11 |
|
10 |
|
|
|
11 |
use Test::DBIx::Class { |
12 |
schema_class => 'Koha::Schema', |
13 |
connect_info => ['dbi:SQLite:dbname=:memory:','',''], |
14 |
connect_opts => { name_sep => '.', quote_char => '`', }, |
15 |
fixture_class => '::Populate', |
16 |
}, 'Biblio' ; |
17 |
|
18 |
sub fixtures { |
19 |
my ( $data ) = @_; |
20 |
fixtures_ok [ |
21 |
Item => [ |
22 |
@$data |
23 |
], |
24 |
], 'add fixtures'; |
25 |
} |
12 |
|
26 |
|
13 |
my $module = new Test::MockModule('C4::Context'); |
27 |
my $db = Test::MockModule->new('Koha::Database'); |
14 |
$module->mock('_new_dbh', sub { |
28 |
$db->mock( |
15 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
29 |
_new_schema => sub { return Schema(); } |
16 |
|| die "Cannot create handle: $DBI::errstr\n"; |
30 |
); |
17 |
return $dbh }); |
|
|
18 |
|
19 |
# Mock data |
20 |
my $incrementaldata = [ |
21 |
['max(abs(barcode))'], |
22 |
['33333074344563'], |
23 |
]; |
24 |
|
25 |
|
31 |
|
26 |
my $dbh = C4::Context->dbh(); |
|
|
27 |
|
32 |
|
28 |
my %args = ( |
33 |
my %args = ( |
29 |
year => '2012', |
34 |
year => '2012', |
Lines 35-77
my %args = (
Link Here
|
35 |
locsubfield => 'a' |
40 |
locsubfield => 'a' |
36 |
); |
41 |
); |
37 |
|
42 |
|
38 |
$dbh->{mock_add_resultset} = $incrementaldata; |
43 |
fixtures([ |
39 |
my ($nextnum, $scr, $history); |
44 |
[ qw/ itemnumber barcode / ], |
40 |
|
45 |
[ 1, 33333074344563 ] |
41 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args); |
46 |
]); |
|
|
47 |
my ($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args); |
42 |
is($nextnum, 33333074344564, 'incremental barcode'); |
48 |
is($nextnum, 33333074344564, 'incremental barcode'); |
43 |
is($scr, undef, 'incremental javascript'); |
49 |
is($scr, undef, 'incremental javascript'); |
44 |
|
50 |
|
45 |
# This should run exactly one query so we can test |
51 |
fixtures([ |
46 |
$history = $dbh->{mock_all_history}; |
52 |
['barcode'], |
47 |
is(scalar(@{$history}), 1, 'Correct number of statements executed for incremental barcode') ; |
|
|
48 |
|
49 |
my $hbyymmincrdata = [ |
50 |
['number'], |
51 |
['890'], |
53 |
['890'], |
52 |
]; |
54 |
]); |
53 |
|
55 |
|
54 |
$dbh->{mock_add_resultset} = $hbyymmincrdata; |
|
|
55 |
$dbh->{mock_clear_history} = 1; |
56 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args); |
56 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args); |
57 |
is($nextnum, '12070891', 'hbyymmincr barcode'); |
57 |
is($nextnum, '12070891', 'hbyymmincr barcode'); |
58 |
ok(length($scr) > 0, 'hbyymmincr javascript'); |
58 |
ok(length($scr) > 0, 'hbyymmincr javascript'); |
59 |
|
59 |
|
60 |
# This should run exactly one query so we can test |
60 |
fixtures([ |
61 |
$history = $dbh->{mock_all_history}; |
61 |
['barcode'], |
62 |
is(scalar(@{$history}), 1, 'Correct number of statements executed for hbyymmincr barcode') ; |
62 |
#max(cast( substring_index(barcode, \'-\',-1) as signed))'], |
63 |
|
|
|
64 |
my $annualdata = [ |
65 |
['max(cast( substring_index(barcode, \'-\',-1) as signed))'], |
66 |
['34'], |
63 |
['34'], |
67 |
]; |
64 |
]); |
68 |
|
65 |
|
69 |
$dbh->{mock_add_resultset} = $annualdata; |
|
|
70 |
$dbh->{mock_clear_history} = 1; |
71 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args); |
66 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args); |
72 |
is($nextnum, '2012-0035', 'annual barcode'); |
67 |
is($nextnum, '2012-0035', 'annual barcode'); |
73 |
is($scr, undef, 'annual javascript'); |
68 |
is($scr, undef, 'annual javascript'); |
74 |
|
|
|
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') ; |