From a7bb42bd44faa5c7787482c12a410b6099ca2e2b Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Fri, 16 Mar 2018 11:03:23 +0000 Subject: [PATCH] Bug 12159: Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: prove t/db_dependent/Koha/Patron/Attributes.t t/db_dependent/Koha/Patrons.t Signed-off-by: Séverine QUEUNE --- t/db_dependent/Koha/Patron/Attributes.t | 64 ++++++++++++++++++++++++++++++++- t/db_dependent/Koha/Patrons.t | 50 +++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t index 044f317..99eaece 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 => 5; +use Test::More tests => 7; use t::lib::TestBuilder; use Test::Exception; @@ -275,3 +275,65 @@ 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 bb6e2bc..56b1f6e 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 31; +use Test::More tests => 32; use Test::Warn; use Time::Fake; use DateTime; @@ -1356,6 +1356,54 @@ 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; +}; $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); -- 2.1.4