From cbe3dedc4f91a91e40f9e648c9de2358c68379cb Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 24 Feb 2016 17:56:23 +0000 Subject: [PATCH] Bug 15877 - Unit tests Signed-off-by: Srdjan Signed-off-by: Jonathan Druart Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- t/db_dependent/Barcodes.t | 61 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Barcodes.t b/t/db_dependent/Barcodes.t index d987bd56a1..9ea13af605 100755 --- a/t/db_dependent/Barcodes.t +++ b/t/db_dependent/Barcodes.t @@ -17,8 +17,12 @@ use Modern::Perl; -use Test::More tests => 73; +use Test::More tests => 74; use Test::Warn; +use Test::MockModule; +use t::lib::TestBuilder; + +use Koha::Database; $| = 1; @@ -28,6 +32,61 @@ BEGIN { use_ok('C4::Barcodes'); } +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; + +my $dbh = C4::Context->dbh; + +subtest 'Test generation of annual barcodes from DB values' => sub { + + plan tests => 4; + + $builder->clear( { source => 'Issue' } ); + $builder->clear( { source => 'Item' } ); + + my $barcodeobj; + + warning_like { $barcodeobj = C4::Barcodes->new('annual'); } [ qr/No max barcode (.*) found\. Using initial value\./ ], "(annual) Expected complaint regarding no max barcode found"; + + my $barcodevalue = $barcodeobj->value(); + + my $item_1 = $builder->build({ + source => 'Item', + value => { + barcode => $barcodevalue + } + }); + + is($barcodevalue,$barcodeobj->db_max(), "(annual) First barcode saved to db is equal to db_max" ); + + #This is just setting the value ahead an arbitrary amount before adding a second barcode to db + $barcodevalue = $barcodeobj->next_value(); + $barcodevalue = $barcodeobj->next_value($barcodevalue); + $barcodevalue = $barcodeobj->next_value($barcodevalue); + $barcodevalue = $barcodeobj->next_value($barcodevalue); + $barcodevalue = $barcodeobj->next_value($barcodevalue); + + my $item_2 = $builder->build({ + source => 'Item', + value => { + barcode => $barcodevalue + } + }); + + $barcodeobj = C4::Barcodes->new('annual'); + + is($barcodevalue,$barcodeobj->db_max(), '(annual) db_max should equal the greatest barcode in the db when more than 1 present'); + ok($barcodeobj->value() gt $barcodevalue, '(annual) new barcode object should be created with value greater and last value inserted into db'); + + $schema->storage->txn_rollback; +}; + + +$builder->clear( { source => 'Issue' } ); +$builder->clear( { source => 'Item' } ); + my %thash = ( incremental => [], annual => [], -- 2.39.5