Bugzilla – Attachment 117713 Details for
Bug 27858
Make Koha::Patron::Attribute->store raise an exception on invalid type/code
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27858: Reorganize tests
Bug-27858-Reorganize-tests.patch (text/plain), 15.20 KB, created by
Martin Renvoize (ashimema)
on 2021-03-04 12:46:13 UTC
(
hide
)
Description:
Bug 27858: Reorganize tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-03-04 12:46:13 UTC
Size:
15.20 KB
patch
obsolete
>From e024066b5fd1ee7cf4d863b58842b4489f17a4fb Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 4 Mar 2021 08:10:51 -0300 >Subject: [PATCH] Bug 27858: Reorganize tests > >This patch renames the tests file, and also groups subtests by method. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Patron/Attribute.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Patron/Attribute.t | 221 ++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Attributes.t | 216 ----------------------- > 2 files changed, 221 insertions(+), 216 deletions(-) > create mode 100755 t/db_dependent/Koha/Patron/Attribute.t > delete mode 100755 t/db_dependent/Koha/Patron/Attributes.t > >diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t >new file mode 100755 >index 0000000000..f4bec78d4c >--- /dev/null >+++ b/t/db_dependent/Koha/Patron/Attribute.t >@@ -0,0 +1,221 @@ >+#!/usr/bin/perl >+ >+# Copyright 2016 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+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 => 2; >+ >+ subtest 'repeatable attributes tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $attribute_type_1 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { repeatable => 1 } >+ } >+ ); >+ 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 repeatable attributes stored and retrieved correcctly' ); >+ >+ my $attribute_type_2 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { repeatable => 0 } >+ } >+ ); >+ >+ 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::NonRepeatable', >+ 'Exception thrown trying to store more than one non-repeatable attribute'; >+ >+ is( >+ "$@", >+ "Tried to add more than one non-repeatable attributes. code=" >+ . $attribute_type_2->{code} >+ . " attribute=Bar", >+ 'Exception stringified correctly, attribute passed correctly' >+ ); >+ >+ my $attributes = Koha::Patron::Attributes->search( >+ { borrowernumber => $patron, code => $attribute_type_2->{code} } ); >+ is( $attributes->count, 1, '1 non-repeatable attribute stored' ); >+ is( $attributes->next->attribute, >+ 'Foo', 'Non-repeatable attribute remains unchanged' ); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'unique_id attributes tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron_1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ >+ my $attribute_type_1 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { unique_id => 0 } >+ } >+ ); >+ Koha::Patron::Attribute->new( >+ { borrowernumber => $patron_1, >+ code => $attribute_type_1->{code}, >+ attribute => 'Foo' >+ } >+ )->store; >+ Koha::Patron::Attribute->new( >+ { borrowernumber => $patron_2, >+ code => $attribute_type_1->{code}, >+ attribute => 'Bar' >+ } >+ )->store; >+ my $attr_count >+ = Koha::Patron::Attributes->search( >+ { 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_1, >+ code => $attribute_type_2->{code}, >+ attribute => 'Foo' >+ } >+ )->store; >+ throws_ok { >+ Koha::Patron::Attribute->new( >+ { borrowernumber => $patron_2, >+ code => $attribute_type_2->{code}, >+ attribute => 'Foo' >+ } >+ )->store; >+ } >+ 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', >+ 'Exception thrown trying to store more than one unique attribute'; >+ >+ is( >+ "$@", >+ "Your action breaks a unique constraint on the attribute. code=" >+ . $attribute_type_2->{code} >+ . " attribute=Foo", >+ 'Exception stringified correctly, attribute passed correctly' >+ ); >+ >+ my $attributes = Koha::Patron::Attributes->search( >+ { borrowernumber => $patron_1, 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 'type() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron >+ = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $attr_type = $builder->build( { source => 'BorrowerAttributeType' } ); >+ my $attribute = Koha::Patron::Attribute->new( >+ { borrowernumber => $patron, >+ code => $attr_type->{code}, >+ attribute => $patron >+ } >+ ); >+ >+ my $attribute_type = $attribute->type; >+ >+ is( ref($attribute_type), >+ 'Koha::Patron::Attribute::Type', >+ '->type returns a Koha::Patron::Attribute::Type object' >+ ); >+ >+ is( $attribute_type->code, >+ $attr_type->{code}, >+ '->type returns the right Koha::Patron::Attribute::Type object' ); >+ >+ is( $attribute_type->opac_editable, >+ $attr_type->{opac_editable}, >+ '->type returns the right Koha::Patron::Attribute::Type object' >+ ); >+ >+ is( $attribute_type->opac_display, >+ $attr_type->{opac_display}, >+ '->type returns the right Koha::Patron::Attribute::Type object' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t >deleted file mode 100755 >index 92e5cd05fb..0000000000 >--- a/t/db_dependent/Koha/Patron/Attributes.t >+++ /dev/null >@@ -1,216 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2016 Koha Development team >-# >-# This file is part of Koha >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-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() repeatable attributes tests' => sub { >- >- plan tests => 5; >- >- $schema->storage->txn_begin; >- >- my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >- my $attribute_type_1 = $builder->build( >- { source => 'BorrowerAttributeType', >- value => { repeatable => 1 } >- } >- ); >- 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 repeatable attributes stored and retrieved correcctly' ); >- >- my $attribute_type_2 = $builder->build( >- { source => 'BorrowerAttributeType', >- value => { repeatable => 0 } >- } >- ); >- >- 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::NonRepeatable', >- 'Exception thrown trying to store more than one non-repeatable attribute'; >- >- is( >- "$@", >- "Tried to add more than one non-repeatable attributes. code=" >- . $attribute_type_2->{code} >- . " attribute=Bar", >- 'Exception stringified correctly, attribute passed correctly' >- ); >- >- my $attributes = Koha::Patron::Attributes->search( >- { borrowernumber => $patron, code => $attribute_type_2->{code} } ); >- is( $attributes->count, 1, '1 non-repeatable attribute stored' ); >- is( $attributes->next->attribute, >- 'Foo', 'Non-repeatable attribute remains unchanged' ); >- >- $schema->storage->txn_rollback; >-}; >- >-subtest 'store() unique_id attributes tests' => sub { >- >- plan tests => 5; >- >- $schema->storage->txn_begin; >- >- my $patron_1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >- my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >- >- my $attribute_type_1 = $builder->build( >- { source => 'BorrowerAttributeType', >- value => { unique_id => 0 } >- } >- ); >- Koha::Patron::Attribute->new( >- { borrowernumber => $patron_1, >- code => $attribute_type_1->{code}, >- attribute => 'Foo' >- } >- )->store; >- Koha::Patron::Attribute->new( >- { borrowernumber => $patron_2, >- code => $attribute_type_1->{code}, >- attribute => 'Bar' >- } >- )->store; >- my $attr_count >- = Koha::Patron::Attributes->search( >- { 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_1, >- code => $attribute_type_2->{code}, >- attribute => 'Foo' >- } >- )->store; >- throws_ok { >- Koha::Patron::Attribute->new( >- { borrowernumber => $patron_2, >- code => $attribute_type_2->{code}, >- attribute => 'Foo' >- } >- )->store; >- } >- 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', >- 'Exception thrown trying to store more than one unique attribute'; >- >- is( >- "$@", >- "Your action breaks a unique constraint on the attribute. code=" >- . $attribute_type_2->{code} >- . " attribute=Foo", >- 'Exception stringified correctly, attribute passed correctly' >- ); >- >- my $attributes = Koha::Patron::Attributes->search( >- { borrowernumber => $patron_1, 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 'type() tests' => sub { >- >- plan tests => 4; >- >- $schema->storage->txn_begin; >- >- my $patron >- = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >- my $attr_type = $builder->build( { source => 'BorrowerAttributeType' } ); >- my $attribute = Koha::Patron::Attribute->new( >- { borrowernumber => $patron, >- code => $attr_type->{code}, >- attribute => $patron >- } >- ); >- >- my $attribute_type = $attribute->type; >- >- is( ref($attribute_type), >- 'Koha::Patron::Attribute::Type', >- '->type returns a Koha::Patron::Attribute::Type object' >- ); >- >- is( $attribute_type->code, >- $attr_type->{code}, >- '->type returns the right Koha::Patron::Attribute::Type object' ); >- >- is( $attribute_type->opac_editable, >- $attr_type->{opac_editable}, >- '->type returns the right Koha::Patron::Attribute::Type object' >- ); >- >- is( $attribute_type->opac_display, >- $attr_type->{opac_display}, >- '->type returns the right Koha::Patron::Attribute::Type object' >- ); >- >- $schema->storage->txn_rollback; >-}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27858
:
117678
|
117679
|
117680
|
117713
|
117714
|
117715
|
118465
|
118596
|
118597
|
118598
|
118599
|
118600