From 1045e717124f5e5c8f72166a5e3de717766f92cb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 30 Apr 2024 12:40:14 +0100 Subject: [PATCH] Bug 32610: (QA follow-up) Fix unit tests With the introduction of data type checking based on the is_date flag we need to update the tests to ensure we're setting the attribute types consistently to not date when we're testing for other flags. Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Patron/Attribute.t | 71 ++++++++++++++++---------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index 3caccd0b96..f68692e57b 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -43,8 +43,9 @@ subtest 'store() tests' => sub { my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; my $attribute_type_1 = $builder->build( - { source => 'BorrowerAttributeType', - value => { repeatable => 1 } + { + source => 'BorrowerAttributeType', + value => { repeatable => 1, is_date => 0 } } ); Koha::Patron::Attribute->new( @@ -67,8 +68,9 @@ subtest 'store() tests' => sub { '2 repeatable attributes stored and retrieved correcctly' ); my $attribute_type_2 = $builder->build( - { source => 'BorrowerAttributeType', - value => { repeatable => 0 } + { + source => 'BorrowerAttributeType', + value => { repeatable => 0, is_date => 0 } } ); @@ -107,20 +109,22 @@ subtest 'store() tests' => sub { }; subtest 'is_date attributes tests' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; - my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; + my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; my $attribute_type_1 = $builder->build( - { source => 'BorrowerAttributeType', + { + source => 'BorrowerAttributeType', value => { is_date => 1 } } ); throws_ok { Koha::Patron::Attribute->new( - { borrowernumber => $patron, + { + borrowernumber => $patron, code => $attribute_type_1->{code}, attribute => 'not_a_date' } @@ -131,25 +135,24 @@ subtest 'store() tests' => sub { is( "$@", - "Tried to use an invalid value for attribute type. type=" - . $attribute_type_1->{code} - . " value=not_a_date", + "Tried to use an invalid value for attribute type. type=" . $attribute_type_1->{code} . " value=not_a_date", 'Exception stringified correctly, attribute passed correctly' ); Koha::Patron::Attribute->new( - { borrowernumber => $patron, + { + borrowernumber => $patron, code => $attribute_type_1->{code}, attribute => '2024-03-04' } )->store; - my $attr_count - = Koha::Patron::Attributes->search( - { borrowernumber => $patron, code => $attribute_type_1->{code} } ) - ->count; - is( $attr_count, 1, - '1 date attribute stored and retrieved correctly' ); + my $attr_count = + Koha::Patron::Attributes->search( { borrowernumber => $patron, code => $attribute_type_1->{code} } )->count; + is( + $attr_count, 1, + '1 date attribute stored and retrieved correctly' + ); $schema->storage->txn_rollback; }; @@ -164,8 +167,9 @@ subtest 'store() tests' => sub { my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; my $attribute_type_1 = $builder->build( - { source => 'BorrowerAttributeType', - value => { unique_id => 0 } + { + source => 'BorrowerAttributeType', + value => { unique_id => 0, is_date => 0 } } ); Koha::Patron::Attribute->new( @@ -188,8 +192,9 @@ subtest 'store() tests' => sub { '2 non-unique attributes stored and retrieved correcctly' ); my $attribute_type_2 = $builder->build( - { source => 'BorrowerAttributeType', - value => { unique_id => 1 } + { + source => 'BorrowerAttributeType', + value => { unique_id => 1, is_date => 0 } } ); @@ -239,7 +244,8 @@ subtest 'store() tests' => sub { class => 'Koha::Patron::Attribute::Types', value => { unique_id => 0, - repeatable => 0 + repeatable => 0, + is_date => 0 } } ); @@ -278,6 +284,7 @@ subtest 'store() tests' => sub { mandatory => 0, repeatable => 0, unique_id => 1, + is_date => 0, category_code => undef } } @@ -352,19 +359,31 @@ subtest 'merge_and_replace_with' => sub { my $unique_attribute_type = $builder->build_object( { class => 'Koha::Patron::Attribute::Types', - value => { unique_id=> 1, repeatable => 0 } + value => { + unique_id => 1, + repeatable => 0, + is_date => 0 + } } ); my $repeatable_attribute_type = $builder->build_object( { class => 'Koha::Patron::Attribute::Types', - value => { unique_id => 0, repeatable => 1 } + value => { + unique_id => 0, + repeatable => 1, + is_date => 0 + } } ); my $normal_attribute_type = $builder->build_object( { class => 'Koha::Patron::Attribute::Types', - value => { unique_id => 0, repeatable => 0 } + value => { + unique_id => 0, + repeatable => 0, + is_date => 0 + } } ); my $non_existent_attribute_type = $builder->build_object( -- 2.39.5