Bug 17828: (QA followup) Add ->type and reuse it

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2017-03-27 12:47:14 -03:00 committed by Kyle M Hall
parent 5d6ee0c7a0
commit e610025bab
2 changed files with 58 additions and 3 deletions

View File

@ -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<Koha::Patron::Attribute::Type> 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 } )

View File

@ -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;