Bug 26352: (QA follow-up) Add additional tests

This patch adds additional unit tests for autoMemberNum handling and
corrects the implimentation there.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-11-20 14:13:39 +00:00 committed by Jonathan Druart
parent b00aab7052
commit ec3bce4fa1
3 changed files with 22 additions and 6 deletions

View File

@ -112,7 +112,7 @@ Autogenerate next cardnumber from highest value found in database
sub fixup_cardnumber {
my ( $self ) = @_;
my ( $max ) = Koha::Plugins->call( 'patron_barcode_transform', $self ) || undef;
my ( $max ) = Koha::Plugins->call( 'patron_barcode_transform', $self->cardnumber ) || undef;
$max ||= Koha::Patrons->search({
cardnumber => {-regexp => '^-?[0-9]+$'}

View File

@ -42,7 +42,7 @@ t::lib::Mocks::mock_config( 'enable_plugins', 1 );
subtest '() hook tests' => sub {
plan tests => 2;
plan tests => 4;
$schema->storage->txn_begin;
@ -51,12 +51,27 @@ subtest '() hook tests' => sub {
my $plugin = Koha::Plugin::Test->new->enable;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $cardnumber = $patron->cardnumber;
my $patron = $builder->build_object(
{ class => 'Koha::Patrons', value => { cardnumber => undef } } );
t::lib::Mocks::mock_preference( 'autoMemberNum', 1 );
warnings_like { $patron->store(); }
[
qr/patron_barcode_transform called with parameter: /,
qr/patron_barcode_transform called with parameter: /
],
'Koha::Patron::store calls the patron_barcode_transform hook twice when autoMemberNum is enabled and cardnumber is undefined';
$patron->cardnumber('TEST');
warning_like { $patron->store(); }
qr/patron_barcode_transform called with parameter: $cardnumber/,
'Koha::Patron::store calls the patron_barcode_transform hook';
qr/patron_barcode_transform called with parameter: TEST/,
'Koha::Patron::store calls the patron_barcode_transform hook once when autoMemberNum is enabled and cardnumber is set';
t::lib::Mocks::mock_preference( 'autoMemberNum', 0 );
$patron->cardnumber(undef);
warning_like { $patron->store(); }
qr/patron_barcode_transform called with parameter: /,
'Koha::Patron::store calls the patron_barcode_transform hook once when autoMemberNum is disabled and cardnumber is undefined';
t::lib::Mocks::mock_userenv(
{

View File

@ -100,6 +100,7 @@ sub item_barcode_transform {
sub patron_barcode_transform {
my ( $self, $barcode ) = @_;
$barcode //= '';
Koha::Exceptions::Exception->throw("patron_barcode_transform called with parameter: $barcode");
}