From f0ab8108ab0a324d715951fc924b7370db236519 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 Jul 2020 14:32:43 +0200 Subject: [PATCH] Bug 26035: Add tests to highlight the problem --- t/db_dependent/Koha/Patrons.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 4f434adc3c..6520691dc7 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 41; +use Test::More tests => 42; use Test::Warn; use Test::Exception; use Test::MockModule; @@ -2204,3 +2204,34 @@ subtest 'extended_attributes' => sub { $schema->storage->txn_rollback; }; + +subtest 'fixup_cardnumber' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + Koha::Holds->search->delete; + Koha::Checkouts->search->delete; + Koha::Patrons->search->delete; + + my $new_patron = Koha::Patron->new->fixup_cardnumber; + is( $new_patron->cardnumber, 1, "NULL+1=1" ); + + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => "a string"} }); + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => 10} }); + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => 100} }); + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => 20} }); + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => "a big 9999 string"} }); + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => "P13000"} }); + + $new_patron = Koha::Patron->new->fixup_cardnumber; + is( $new_patron->cardnumber, 101, "100+1=101" ); + + $builder->build_object({ class => 'Koha::Patrons', value => {cardnumber => 603628999632182575912} }); + + $new_patron = Koha::Patron->new->fixup_cardnumber; + is( $new_patron->cardnumber, 603628999632182575914, "603628999632182575912+1=603628999632182575913" ); + + $schema->storage->txn_rollback; +}; -- 2.20.1