Bugzilla – Attachment 183647 Details for
Bug 40275
Add Koha::Patrons->find_by_identifier()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40275: Unit tests
Bug-40275-Unit-tests.patch (text/plain), 4.86 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-06-30 18:30:08 UTC
(
hide
)
Description:
Bug 40275: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-06-30 18:30:08 UTC
Size:
4.86 KB
patch
obsolete
>From c7f9771d5a4c6a336861d87e908e9eebc6a2f01c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 30 Jun 2025 10:51:00 -0300 >Subject: [PATCH] Bug 40275: Unit tests > >--- > t/db_dependent/Koha/Patrons.t | 59 ++++++++++++++++++++++++++++++++--- > 1 file changed, 54 insertions(+), 5 deletions(-) > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index ed7ad7a3516..d2c9bb21f5d 100755 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 46; >+use Test::More tests => 47; > use Test::Warn; > use Test::Exception; > use Test::MockModule; >@@ -500,7 +500,8 @@ subtest 'renew_account' => sub { > dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month, > "$a_month_ago + 12 months must be $a_year_later_minus_a_month" > ); >- my $number_of_logs = $schema->resultset('ActionLog') >+ my $number_of_logs = >+ $schema->resultset('ActionLog') > ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; > is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' ); > >@@ -515,7 +516,8 @@ subtest 'renew_account' => sub { > ); > $retrieved_expiry_date = $retrieved_patron->dateexpiry; > is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" ); >- $number_of_logs = $schema->resultset('ActionLog') >+ $number_of_logs = >+ $schema->resultset('ActionLog') > ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; > is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); > >@@ -650,7 +652,8 @@ subtest "delete" => sub { > q|Koha::Patron->delete should have deleted patron's modifications| > ); > >- my $number_of_logs = $schema->resultset('ActionLog') >+ my $number_of_logs = >+ $schema->resultset('ActionLog') > ->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count; > is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); > >@@ -2468,7 +2471,8 @@ subtest '->set_password' => sub { > ok( checkpw_hash( 'abcd a', $patron->password ), 'Password hash is correct' ); > is( $patron->login_attempts, 0, 'Login attempts have been reset' ); > >- my $number_of_logs = $schema->resultset('ActionLog') >+ my $number_of_logs = >+ $schema->resultset('ActionLog') > ->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; > is( $number_of_logs, 0, 'Without BorrowerLogs, Koha::Patron->set_password doesn\'t log password changes' ); > >@@ -3573,4 +3577,49 @@ subtest 'filter_by_expired_opac_registrations' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'find_by_identifier() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ # Create test patrons with specific userid and cardnumber >+ my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ # Create a patron to delete to >+ my $to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $ne_userid = $to_delete->userid; >+ my $ne_cardnumber = $to_delete->cardnumber; >+ $to_delete->delete(); >+ >+ # Test finding by userid >+ my $found_patron = Koha::Patrons->find_by_identifier( $patron_1->userid ); >+ is( $found_patron->id, $patron_1->id, 'Found patron by userid' ); >+ >+ # Test finding by cardnumber >+ $found_patron = Koha::Patrons->find_by_identifier( $patron_1->cardnumber ); >+ is( $found_patron->id, $patron_1->id, 'Found patron by cardnumber' ); >+ >+ # Test finding by cardnumber when userid doesn't match >+ $found_patron = Koha::Patrons->find_by_identifier( $patron_2->cardnumber ); >+ is( $found_patron->id, $patron_2->id, 'Found patron by cardnumber when userid differs' ); >+ >+ # Test with non-existent identifiers >+ $found_patron = Koha::Patrons->find_by_identifier($ne_cardnumber); >+ is( $found_patron, undef, 'Returns undef for non-existent identifier' ); >+ $found_patron = Koha::Patrons->find_by_identifier($ne_userid); >+ is( $found_patron, undef, 'Returns undef for non-existent identifier' ); >+ >+ # Test with empty identifier >+ $found_patron = Koha::Patrons->find_by_identifier(''); >+ is( $found_patron, undef, 'Returns undef for empty identifier' ); >+ >+ # Test with undef identifier >+ $found_patron = Koha::Patrons->find_by_identifier(undef); >+ is( $found_patron, undef, 'Returns undef for undef identifier' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > $schema->storage->txn_rollback; >-- >2.50.0
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 40275
:
183647
|
183648
|
183649
|
183659
|
183660
|
183661
|
183761
|
183762
|
183763
|
183764
|
183765