From cbe15d47d28f100b1b50c408b84fc46e12920142 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Jul 2024 16:43:53 +0100 Subject: [PATCH] Bug 30657: Unit tests This patch adds some basic unit tests for dynamically added accessors based on extended patron attributes. Signed-off-by: Brendan Lawlor --- t/db_dependent/Koha/Patron.t | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index bad1cc1bfa..90de5c21bd 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -757,7 +757,7 @@ subtest 'is_superlibrarian() tests' => sub { subtest 'extended_attributes' => sub { - plan tests => 16; + plan tests => 17; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -1104,11 +1104,37 @@ subtest 'extended_attributes' => sub { ok( $patron->extended_attributes([]), "We can set no attributes, mandatory attribute for other category not required"); - + $schema->storage->txn_rollback; }; + subtest 'attribute accessor tests' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + Koha::Patron::Attribute::Types->search->delete; + + my $attribute_type_1 = $builder->build_object( + { + class => 'Koha::Patron::Attribute::Types', + value => { code => 'smartnumber', repeatable => 0 } + } + ); + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + + is( $patron->smartnumber, undef, 'smartnumber accessor returns undef when not set'); + + $patron->extended_attributes( + [ + { code => 'smartnumber', attribute => 'SM1234' } + ] + ); + is( $patron->smartnumber, 'SM1234', 'smartnumber accessor returns value when set'); + $schema->storage->txn_rollback; + }; }; subtest 'can_log_into() tests' => sub { -- 2.39.2