From 558147281371da446196a62a912123cd6fe3dac2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Mar 2021 08:24:54 -0300 Subject: [PATCH] Bug 27858: Make Koha::Patron::Attribute->store raise an exception on invalid type/code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds type validation to the ->store method. And exception should be thrown if the type is invalid. Things currently explode in such situations, so this doesn't change the behavior (just adding more informative failure information). To test: 1. Apply the previous patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron/Attribute.t => FAIL: No exception is thrown on the bad case, weird error 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Exception thrown! 5. Sign off :-D Signed-off-by: Martin Renvoize Signed-off-by: Joonas Kylmälä --- Koha/Patron/Attribute.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index dc97aa8cc9..26fffeb788 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -46,6 +46,9 @@ sub store { my $self = shift; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless Koha::Patron::Attribute::Types->find( $self->code ); + $self->_check_repeatable; $self->check_unique_id; -- 2.11.0