Bug 12159: Add tests

Test plan:
prove t/db_dependent/Koha/Patron/Attributes.t t/db_dependent/Koha/Patrons.t

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Josef Moravec 2018-03-16 11:03:23 +00:00 committed by Nick Clemens
parent 4fe300dec1
commit 1218364dbe
2 changed files with 113 additions and 2 deletions

View File

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

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 33;
use Test::More tests => 34;
use Test::Warn;
use Test::Exception;
use Test::MockModule;
@ -1395,6 +1395,55 @@ 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' );