From 841d9d991c50bcd3dc614f969a1895ba047cc829 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 9 Apr 2021 15:11:39 +0200 Subject: [PATCH] Bug 28031: test remove type from parameter --- Koha/Patron/Attribute.pm | 22 ++++++--------- t/db_dependent/Koha/Patron/Attribute.t | 37 +------------------------- 2 files changed, 9 insertions(+), 50 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 3a5caa84eab..d5592638faa 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -60,10 +60,10 @@ sub store { unless $type; Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) - unless $self->repeatable_ok($type); + unless $self->repeatable_ok(); Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) - unless $self->unique_ok($type); + unless $self->unique_ok(); return $self->SUPER::store(); } @@ -146,7 +146,7 @@ sub to_api_mapping { =head3 repeatable_ok - if ( $attr->repeatable_ok( $type ) ) { ... } + if ( $attr->repeatable_ok() ) { ... } Checks if the attribute type is repeatable and returns a boolean representing whether storing the current object state would break the repeatable constraint. @@ -155,13 +155,10 @@ whether storing the current object state would break the repeatable constraint. sub repeatable_ok { - my ( $self, $type ) = @_; - - Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" ) - unless $type; + my ( $self ) = @_; my $ok = 1; - if ( !$type->repeatable ) { + if ( !$self->type->repeatable ) { my $params = { borrowernumber => $self->borrowernumber, code => $self->code @@ -178,7 +175,7 @@ sub repeatable_ok { =head3 unique_ok - if ( $attr->unique_ok( $type ) ) { ... } + if ( $attr->unique_ok() ) { ... } Checks if the attribute type is marked as unique and returns a boolean representing whether storing the current object state would break the unique constraint. @@ -187,13 +184,10 @@ whether storing the current object state would break the unique constraint. sub unique_ok { - my ( $self, $type ) = @_; - - Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" ) - unless $type; + my ( $self ) = @_; my $ok = 1; - if ( $type->unique_id ) { + if ( $self->type->unique_id ) { my $params = { code => $self->code, attribute => $self->attribute }; $params->{borrowernumber} = { '!=' => $self->borrowernumber } if $self->borrowernumber; diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index a05809c4e14..6faa232a13c 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -19,13 +19,12 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 2; use t::lib::TestBuilder; use Test::Exception; use Koha::Database; -use Koha::Patron::Attribute; use Koha::Patron::Attributes; my $schema = Koha::Database->new->schema; @@ -288,37 +287,3 @@ subtest 'type() tests' => sub { $schema->storage->txn_rollback; }; - -subtest 'repeatable_ok() tests' => sub { - - plan tests => 1; - - my $attr = Koha::Patron::Attribute->new( - { - attribute => 'something', - code => 'some code' - } - ); - - throws_ok - { $attr->repeatable_ok(); } - 'Koha::Exceptions::MissingParameter', - 'Exception on missing type attribute'; -}; - -subtest 'unique_ok() tests' => sub { - - plan tests => 1; - - my $attr = Koha::Patron::Attribute->new( - { - attribute => 'something', - code => 'some code' - } - ); - - throws_ok - { $attr->unique_ok(); } - 'Koha::Exceptions::MissingParameter', - 'Exception on missing type attribute'; -}; -- 2.20.1