From f0c9315f81d9ae22f9905459a2a90ce2ef84bdf6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 26 Sep 2024 16:08:07 -0400 Subject: [PATCH] Bug 33462: (QA follow-up) Tidy code Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- Koha/Schema/Result/Category.pm | 2 +- t/db_dependent/Koha/Patron.t | 157 +++++++++++++++----------- t/db_dependent/Koha/Patron/Category.t | 66 +++++++---- 3 files changed, 137 insertions(+), 88 deletions(-) diff --git a/Koha/Schema/Result/Category.pm b/Koha/Schema/Result/Category.pm index 30a67d5d0e..616677608d 100644 --- a/Koha/Schema/Result/Category.pm +++ b/Koha/Schema/Result/Category.pm @@ -403,12 +403,12 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-09-17 17:34:19 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SZoU95HraPfIzszljOSHyQ - # You can replace this text with custom code or comments, and it will be preserved on regeneration sub koha_object_class { 'Koha::Patron::Category'; } + sub koha_objects_class { 'Koha::Patron::Categories'; } diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 45fe96aa2c..d433bfb0d3 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -1441,39 +1441,58 @@ subtest 'password expiration tests' => sub { plan tests => 5; $schema->storage->txn_begin; - my $date = dt_from_string(); - my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { - password_expiry_days => 10, - require_strong_password => 0, - force_password_reset_when_set_by_staff => 0, + my $date = dt_from_string(); + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { + password_expiry_days => 10, + require_strong_password => 0, + force_password_reset_when_set_by_staff => 0, + } } - }); - my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => { - categorycode => $category->categorycode, - password => 'hats' + ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode, + password => 'hats' + } } - }); + ); - $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron + $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron - is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation"); + is( + $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), + "Password expiration date set correctly on patron creation" + ); - $patron = $builder->build_object({ class => 'Koha::Patrons', value => { - categorycode => $category->categorycode, - password => undef + $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode, + password => undef + } } - }); + ); $patron->delete()->store()->discard_changes(); - is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password"); + is( + $patron->password_expiration_date(), undef, + "Password expiration date is not set if patron does not have a password" + ); $category->password_expiry_days(undef)->store(); - $patron = $builder->build_object({ class => 'Koha::Patrons', value => { - categorycode => $category->categorycode - } - }); + $patron = + $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); $patron->delete()->store()->discard_changes(); - is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set"); + is( + $patron->password_expiration_date(), undef, + "Password expiration date is not set if category does not have expiry days set" + ); $schema->storage->txn_rollback; @@ -1483,18 +1502,16 @@ subtest 'password expiration tests' => sub { $schema->storage->txn_begin; my $date = dt_from_string(); - $patron = $builder->build_object({ class => 'Koha::Patrons', value => { - password_expiration_date => undef - } - }); - is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired"); - $patron->password_expiration_date( $date )->store; + $patron = + $builder->build_object( { class => 'Koha::Patrons', value => { password_expiration_date => undef } } ); + is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired" ); + $patron->password_expiration_date($date)->store; $patron->discard_changes(); - is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired"); + is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired" ); $date->subtract( days => 1 ); - $patron->password_expiration_date( $date )->store; + $patron->password_expiration_date($date)->store; $patron->discard_changes(); - is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired"); + is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired" ); $schema->storage->txn_rollback; }; @@ -1506,26 +1523,33 @@ subtest 'password expiration tests' => sub { $schema->storage->txn_begin; my $date = dt_from_string(); - my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { - password_expiry_days => 10 - } - }); - my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { - categorycode => $category->categorycode, - password_expiration_date => $date->subtract( days => 1 ) + my $category = + $builder->build_object( { class => 'Koha::Patron::Categories', value => { password_expiry_days => 10 } } ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode, + password_expiration_date => $date->subtract( days => 1 ) + } } - }); - is( $patron->password_expired, 1, "Patron password is expired"); + ); + is( $patron->password_expired, 1, "Patron password is expired" ); $date = dt_from_string(); - $patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes(); - is( $patron->password_expired, 0, "Patron password no longer expired when new password set"); - is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation"); - + $patron->set_password( { password => "kitten", skip_validation => 1 } )->discard_changes(); + is( $patron->password_expired, 0, "Patron password no longer expired when new password set" ); + is( + $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), + "Password expiration date set correctly on patron creation" + ); - $category->password_expiry_days( undef )->store(); - $patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes(); - is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days"); + $category->password_expiry_days(undef)->store(); + $patron->set_password( { password => "puppies", skip_validation => 1 } )->discard_changes(); + is( + $patron->password_expiration_date(), undef, + "Password expiration date is unset if category does not have expiry days" + ); $schema->storage->txn_rollback; }; @@ -1537,33 +1561,40 @@ subtest 'force_password_reset_when_set_by_staff tests' => sub { $schema->storage->txn_begin; - my $category = $builder->build_object({ - class => 'Koha::Patron::Categories', - value => { - force_password_reset_when_set_by_staff => 1, - require_strong_password => 0, + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { + force_password_reset_when_set_by_staff => 1, + require_strong_password => 0, + } } - }); + ); - my $patron = $builder->build_object({ - class => 'Koha::Patrons', - value => { - categorycode => $category->categorycode, - password => 'hats' + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode, + password => 'hats' + } } - }); + ); $patron->delete()->store()->discard_changes(); - is($patron->password_expired, 1, "Patron forced into changing password, password expired."); + is( $patron->password_expired, 1, "Patron forced into changing password, password expired." ); $patron->category->force_password_reset_when_set_by_staff(0)->store(); $patron->delete()->store()->discard_changes(); - is($patron->password_expired, 0, "Patron not forced into changing password, password not expired."); + is( $patron->password_expired, 0, "Patron not forced into changing password, password not expired." ); $patron->category->force_password_reset_when_set_by_staff(1)->store(); - t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $patron->categorycode); + t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $patron->categorycode ); $patron->delete()->store()->discard_changes(); - is($patron->password_expired, 0, "Patron forced into changing password but patron is self registered, password not expired."); + is( + $patron->password_expired, 0, + "Patron forced into changing password but patron is self registered, password not expired." + ); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Patron/Category.t b/t/db_dependent/Koha/Patron/Category.t index 4e3670b78a..0d7f42fa38 100755 --- a/t/db_dependent/Koha/Patron/Category.t +++ b/t/db_dependent/Koha/Patron/Category.t @@ -212,27 +212,39 @@ subtest 'effective_force_password_reset_when_set_by_staff() tests' => sub { $schema->storage->txn_begin; - my $category = $builder->build_object({ - class => 'Koha::Patron::Categories', - value => { - force_password_reset_when_set_by_staff => 1 + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { force_password_reset_when_set_by_staff => 1 } } - }); + ); - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0); - ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 1'); + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 ); + ok( + $category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 1' + ); - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1); - ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 1'); + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 ); + ok( + $category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 1' + ); # disable $category->force_password_reset_when_set_by_staff(0)->store->discard_changes; - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0); - ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 0'); + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 ); + ok( + !$category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff unset, but category has the flag set to 0' + ); - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1); - ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 0'); + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 ); + ok( + !$category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff set and category has the flag set to 0' + ); $schema->storage->txn_rollback; }; @@ -242,18 +254,24 @@ subtest 'effective_force_password_reset_when_set_by_staff() tests' => sub { $schema->storage->txn_begin; - my $category = $builder->build_object({ - class => 'Koha::Patron::Categories', - value => { - force_password_reset_when_set_by_staff => undef + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { force_password_reset_when_set_by_staff => undef } } - }); - - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 0); - ok(!$category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 0 used'); - - t::lib::Mocks::mock_preference('ForcePasswordResetWhenSetByStaff', 1); - ok($category->effective_force_password_reset_when_set_by_staff, 'ForcePasswordResetWhenSetByStaff set to 1 used'); + ); + + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 0 ); + ok( + !$category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff set to 0 used' + ); + + t::lib::Mocks::mock_preference( 'ForcePasswordResetWhenSetByStaff', 1 ); + ok( + $category->effective_force_password_reset_when_set_by_staff, + 'ForcePasswordResetWhenSetByStaff set to 1 used' + ); $schema->storage->txn_rollback; }; -- 2.39.5