From af9e710ab1b988fe3c9e655bae40706a517a1c47 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 27 Mar 2017 12:47:14 -0300 Subject: [PATCH] Bug 17828: (QA followup) Add ->type and reuse it Signed-off-by: Tomas Cohen Arazi --- Koha/Patron/Attribute.pm | 19 +++++++++++++-- t/db_dependent/Koha/Patron/Attributes.t | 42 ++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index fe62dfa..52eb9c1 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -79,6 +79,21 @@ sub opac_editable { return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable; } +=head3 type + + my $attribute_type = $attribute->type; + +Returns a C object corresponding to the current patron attribute + +=cut + +sub type { + + my $self = shift; + + return Koha::Patron::Attribute::Types->find( $self->code ); +} + =head2 Internal methods =head3 _check_repeatable @@ -93,7 +108,7 @@ sub _check_repeatable { my $self = shift; - if ( !Koha::Patron::Attribute::Types->find( $self->code )->repeatable ) { + if ( !$self->type->repeatable ) { my $attr_count = Koha::Database->new->schema->resultset( $self->_type )->search( { borrowernumber => $self->borrowernumber, @@ -119,7 +134,7 @@ sub _check_unique_id { my $self = shift; - if ( Koha::Patron::Attribute::Types->find( $self->code )->unique_id ) { + if ( $self->type->unique_id ) { my $unique_count = Koha::Database->new->schema->resultset( $self->_type ) ->search( { code => $self->code, attribute => $self->attribute } ) diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t index 36b04df..cbb02b9 100644 --- a/t/db_dependent/Koha/Patron/Attributes.t +++ b/t/db_dependent/Koha/Patron/Attributes.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use t::lib::TestBuilder; use Test::Exception; @@ -235,4 +235,44 @@ subtest 'opac_editable() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'type() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $patron + = $builder->build( { source => 'Borrower' } )->{borrowernumber}; + my $attr_type = $builder->build( { source => 'BorrowerAttributeType' } ); + my $attribute = Koha::Patron::Attribute->new( + { borrowernumber => $patron, + code => $attr_type->{code}, + attribute => $patron + } + ); + + my $attribute_type = $attribute->type; + + is( ref($attribute_type), + 'Koha::Patron::Attribute::Type', + '->type returns a Koha::Patron::Attribute::Type object' + ); + + is( $attribute_type->code, + $attr_type->{code}, + '->type returns the right Koha::Patron::Attribute::Type object' ); + + is( $attribute_type->opac_editable, + $attr_type->{opac_editable}, + '->type returns the right Koha::Patron::Attribute::Type object' + ); + + is( $attribute_type->opac_display, + $attr_type->{opac_display}, + '->type returns the right Koha::Patron::Attribute::Type object' + ); + + $schema->storage->txn_rollback; +}; + 1; -- 2.7.4