From 0f3d1f3daf9521984e44cf430a01a928659f462a Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 11 Oct 2024 19:12:18 +0000 Subject: [PATCH] Bug 38005: (follow-up) Add/adjust tests NC amended patch, tidied Bug 38005: (QA follow-up) Tidy Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Patron.t | 61 +++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 970235ecc5..3e19279f76 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -1024,12 +1024,14 @@ subtest 'extended_attributes' => sub { subtest 'globally mandatory attributes tests' => sub { - plan tests => 5; + plan tests => 8; $schema->storage->txn_begin; Koha::Patron::Attribute::Types->search->delete; - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $context = Test::MockModule->new('C4::Context'); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $attribute_type_1 = $builder->build_object( { @@ -1045,17 +1047,33 @@ subtest 'extended_attributes' => sub { } ); - is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' ); + my $attribute_type_3 = $builder->build_object( + { + class => 'Koha::Patron::Attribute::Types', + value => { mandatory => 1, class => 'a', category_code => undef, opac_editable => 1 } + } + ); - throws_ok + my $attribute_type_4 = $builder->build_object( { - $patron->extended_attributes( - [ - { code => $attribute_type_2->code, attribute => 'b' } - ] - ); + class => 'Koha::Patron::Attribute::Types', + value => { mandatory => 0, class => 'a', category_code => undef, opac_editable => 1 } } - 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', + ); + + #Staff interface tests + $context->mock( 'interface', sub { return "intranet" } ); + is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' ); + + throws_ok { + $patron->extended_attributes( + [ + { code => $attribute_type_2->code, attribute => 'b' }, + { code => $attribute_type_3->code, attribute => 'b' }, + ] + ); + } + 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', 'Exception thrown on missing mandatory attribute type'; is( $@->type, $attribute_type_1->code, 'Exception parameters are correct' ); @@ -1064,11 +1082,30 @@ subtest 'extended_attributes' => sub { $patron->extended_attributes( [ - { code => $attribute_type_1->code, attribute => 'b' } + { code => $attribute_type_1->code, attribute => 'b' }, + { code => $attribute_type_3->code, attribute => 'b' }, ] ); - is( $patron->extended_attributes->count, 1, 'Extended attributes succeeded' ); + is( $patron->extended_attributes->count, 2, 'Extended attributes succeeded' ); + + # OPAC interface tests + $context->mock( 'interface', sub { return "opac" } ); + + is( $patron->extended_attributes->count, 2, 'Patron still has 2 extended attributes in OPAC' ); + + throws_ok { + $patron->extended_attributes( + [ + { code => $attribute_type_1->code, attribute => 'b' }, + { code => $attribute_type_2->code, attribute => 'b' }, + ] + ); + } + 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', + 'Exception thrown on missing mandatory OPAC-editable attribute'; + + is( $@->type, $attribute_type_3->code, 'Exception parameters are correct for OPAC-editable attribute' ); $schema->storage->txn_rollback; -- 2.39.5