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
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,
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 } )
use Modern::Perl;
-use Test::More tests => 4;
+use Test::More tests => 5;
use t::lib::TestBuilder;
use Test::Exception;
$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;