Bug 27858: Unit tests

This patch introduces unit tests for the new exception to be thrown.
It generates a new extended attribute type, keeps the randomly generated
'code' and deletes the object. This way we can be sure the code doesn't
exist on the DB. It then tries to generate an attribute of that type, to
force the exception to be thrown.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-03-04 08:23:09 -03:00 committed by Jonathan Druart
parent e2fe2d217f
commit 032c66bfc9
1 changed files with 38 additions and 1 deletions

View File

@ -33,7 +33,7 @@ my $builder = t::lib::TestBuilder->new;
subtest 'store() tests' => sub {
plan tests => 2;
plan tests => 3;
subtest 'repeatable attributes tests' => sub {
@ -178,6 +178,43 @@ subtest 'store() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'invalid type tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $attribute_type = $builder->build_object(
{
class => 'Koha::Patron::Attribute::Types',
value => {
unique_id => 0,
repeatable => 0
}
}
);
my $code = $attribute_type->code;
$attribute_type->delete;
throws_ok
{ Koha::Patron::Attribute->new(
{
borrowernumber => $patron->borrowernumber,
code => $code,
attribute => 'Who knows'
})->store;
}
'Koha::Exceptions::Patron::Attribute::InvalidType',
'Exception thrown on invalid attribute code';
is( $@->type, $code, 'type exception parameter passed' );
$schema->storage->txn_rollback;
};
};
subtest 'type() tests' => sub {