From 956c1a2a26f6663e1620492e67c6a9b20ef3fe94 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 13 Jul 2018 10:41:15 -0300 Subject: [PATCH] Bug 20443: Revert some stuffs from 12159 These methods have been added to Koha::Patron::Attribute but are wrong, see bug 18339 We should use ->type->$method instead Moreover the tests exist in another subtest, we do not need them. Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- Koha/Patron/Attribute.pm | 51 ------------------- Koha/Schema/Result/BorrowerAttribute.pm | 15 ++++++ t/db_dependent/Koha/Patron/Attributes.t | 65 +------------------------ t/db_dependent/Koha/Patrons.t | 49 ------------------- 4 files changed, 16 insertions(+), 164 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 1dd98242d1..03bfd91550 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -80,57 +80,6 @@ sub opac_editable { return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable; } -=head3 display_checkout - - my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... }); - if ( $attribute->display_checkout ) { ... } - -=cut - -sub display_checkout { - - my $self = shift; - - return $self->type->display_checkout; -} - -=head3 value_description - - my $description = $attribute->value_description - - Return authorised value description or free text based on attribute type settings - -=cut - -sub value_description { - - my $self = shift; - - if ( $self->type->authorised_value_category ) { - my $av = Koha::AuthorisedValues->search({ - category => $self->type->authorised_value_category, - authorised_value => $self->attribute, - }); - return $av->next->lib if $av->count; - } - return $self->attribute; -} - -=head3 type_description - - my $description = $attribute->type_description - - Return description of attribute type - -=cut - -sub type_description { - - my $self = shift; - - return $self->type->description; -} - =head3 type my $attribute_type = $attribute->type; diff --git a/Koha/Schema/Result/BorrowerAttribute.pm b/Koha/Schema/Result/BorrowerAttribute.pm index 2dc8268c15..2a8398ad68 100644 --- a/Koha/Schema/Result/BorrowerAttribute.pm +++ b/Koha/Schema/Result/BorrowerAttribute.pm @@ -109,6 +109,21 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-08 04:41:27 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EarETnedFsmRmAAJAUrKGg +=head2 borrower_attribute_types + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "borrower_attribute_types", + "Koha::Schema::Result::BorrowerAttributeType", + { "foreign.code" => "self.code" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },); + + sub koha_object_class { 'Koha::Patron::Attribute'; } diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t index 99eaecef39..fbe1190e62 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 => 7; +use Test::More tests => 3; use t::lib::TestBuilder; use Test::Exception; @@ -274,66 +274,3 @@ subtest 'type() tests' => sub { $schema->storage->txn_rollback; }; - -subtest 'display_checkout() tests' => sub { - - plan tests => 2; - - $schema->storage->txn_begin; - - my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; - my $attribute_type_1 = $builder->build( - { source => 'BorrowerAttributeType', - value => { display_checkout => 1 } - } - ); - - my $attribute_1 = Koha::Patron::Attribute->new( - { borrowernumber => $patron, - code => $attribute_type_1->{code}, - attribute => $patron - } - ); - is( $attribute_1->display_checkout, 1, '->display_checkout returns 1' ); - - my $attribute_type_2 = $builder->build( - { source => 'BorrowerAttributeType', - value => { display_checkout => 0 } - } - ); - - my $attribute_2 = Koha::Patron::Attribute->new( - { borrowernumber => $patron, - code => $attribute_type_2->{code}, - attribute => $patron - } - ); - is( $attribute_2->display_checkout, 0, '->display_checkout returns 0' ); - - $schema->storage->txn_rollback; -}; - -subtest 'type_description() and value_description tests' => sub { - - plan tests => 2; - - $schema->storage->txn_begin; - - my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; - my $attribute_type_1 = $builder->build( - { source => 'BorrowerAttributeType', - value => { description => "Type 1" } - } - ); - - my $attribute_1 = Koha::Patron::Attribute->new( - { borrowernumber => $patron, - code => $attribute_type_1->{code}, - attribute => "Attribute 1" - } - ); - is( $attribute_1->type_description, "Type 1" , '->type_description returns right value' ); - is( $attribute_1->value_description, "Attribute 1" , '->value_description returns right value' ); - - $schema->storage->txn_rollback; -}; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 6e9926c2db..662b8524db 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1641,55 +1641,6 @@ subtest 'generate_userid' => sub { $patron_2->delete; }; -subtest 'attributes' => sub { - plan tests => 2; - - my $library1 = Koha::Library->new({ - branchcode => 'LIBPATRON', - branchname => 'Library of testing patron', - })->store; - - my $library2 = Koha::Library->new({ - branchcode => 'LIBATTR', - branchname => 'Library for testing attribute', - })->store; - - my $category = Koha::Patron::Category->new({ - categorycode => 'CAT1', - description => 'Category 1', - })->store; - - my $patron = Koha::Patron->new({ - firstname => 'Patron', - surname => 'with attributes', - branchcode => 'LIBPATRON', - categorycode => 'CAT1', - })->store; - - my $attribute_type1 = Koha::Patron::Attribute::Type->new({ - code => 'CODE_A', - description => 'Code A desciption', - })->store; - - my $attribute_type2 = Koha::Patron::Attribute::Type->new({ - code => 'CODE_B', - description => 'Code A desciption', - })->store; - - $attribute_type2->library_limits ( [ $library2->branchcode ] ); - - Koha::Patron::Attribute->new({ borrowernumber => $patron->borrowernumber, code => $attribute_type1->code, attribute => 'value 1' } )->store(); - Koha::Patron::Attribute->new({ borrowernumber => $patron->borrowernumber, code => $attribute_type2->code, attribute => 'value 2' } )->store(); - - is( $patron->attributes->count, 1, 'There should be one attribute'); - - $attribute_type2->library_limits ( [ $library1->branchcode ] ); - - is( $patron->attributes->count, 2, 'There should be 2 attributes'); - - $patron->delete; -}; - $nb_of_patrons = Koha::Patrons->search->count; $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' ); -- 2.39.5