@@ -, +, @@ --- t/db_dependent/Koha/Patron/Attributes.t | 67 ++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/Patron/Attributes.t +++ a/t/db_dependent/Koha/Patron/Attributes.t @@ -19,16 +19,81 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use t::lib::TestBuilder; +use Test::Exception; use Koha::Database; use Koha::Patron::Attribute; +use Koha::Patron::Attributes; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +subtest 'store() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $patron + = $builder->build( { source => 'Borrower' } )->{borrowernumber}; + my $attribute_type_1 = $builder->build( + { source => 'BorrowerAttributeType', + value => { unique_id => 0 } + } + ); + Koha::Patron::Attribute->new( + { borrowernumber => $patron, + code => $attribute_type_1->{code}, + attribute => 'Foo' + } + )->store; + Koha::Patron::Attribute->new( + { borrowernumber => $patron, + code => $attribute_type_1->{code}, + attribute => 'Bar' + } + )->store; + my $attr_count + = Koha::Patron::Attributes->search( + { borrowernumber => $patron, code => $attribute_type_1->{code} } ) + ->count; + is( $attr_count, 2, + '2 non-unique attributes stored and retrieved correcctly' ); + + my $attribute_type_2 = $builder->build( + { source => 'BorrowerAttributeType', + value => { unique_id => 1 } + } + ); + + Koha::Patron::Attribute->new( + { borrowernumber => $patron, + code => $attribute_type_2->{code}, + attribute => 'Foo' + } + )->store; + throws_ok { + Koha::Patron::Attribute->new( + { borrowernumber => $patron, + code => $attribute_type_2->{code}, + attribute => 'Bar' + } + )->store; + } + 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', + 'Exception thrown trying to store more than one unique attribute'; + my $attributes = Koha::Patron::Attributes->search( + { borrowernumber => $patron, code => $attribute_type_2->{code} } ); + is( $attributes->count, 1, '1 Unique attribute stored' ); + is( $attributes->next->attribute, + 'Foo', 'Unique attribute remains unchanged' ); + + $schema->storage->txn_rollback; +}; + subtest 'opac_display() tests' => sub { plan tests => 2; --