Bugzilla – Attachment 192610 Details for
Bug 20956
BorrowersLog is not logging permission changes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20956: Fix test failures
da394bd.patch (text/plain), 7.70 KB, created by
David Nind
on 2026-02-06 10:39:09 UTC
(
hide
)
Description:
Bug 20956: Fix test failures
Filename:
MIME Type:
Creator:
David Nind
Created:
2026-02-06 10:39:09 UTC
Size:
7.70 KB
patch
obsolete
>From da394bda3947a1584520e0b1bf9c2399c310aed9 Mon Sep 17 00:00:00 2001 >From: Ayoub Glizi-Vicioso <ayoub.glizi-vicioso@inLibro.com> >Date: Wed, 4 Feb 2026 17:07:08 -0500 >Subject: [PATCH] Bug 20956: Fix test failures > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/Koha/Patron.t | 88 ++++++++++++++++++++++++++---------- > 1 file changed, 65 insertions(+), 23 deletions(-) > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 865bef3051..9c256b95df 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 46; >+use Test::More tests => 47; > use Test::NoWarnings; > use Test::Exception; > use Test::Warn; >@@ -41,6 +41,7 @@ use C4::Circulation qw( AddIssue AddReturn ); > > use t::lib::TestBuilder; > use t::lib::Mocks; >+use Test::MockModule; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -816,14 +817,17 @@ subtest 'is_superlibrarian() tests' => sub { > { > class => 'Koha::Patrons', > >- value => { flags => 4 } >+ value => { flags => 16 } > } > ); > >- my %permissions = $patron->permissions; >+ my $permissions = $patron->permissions; >+ is( $permissions->{superlibrarian}, undef, 'Patron does not have superlibrarian permission' ); >+ >+ $patron->flags(1)->store->discard_changes; > >- is( scalar keys %permissions, 1, "Patron has one module permission" ); >- is( $permissions{catalogue}, 1, "Patron has catalogue permission" ); >+ $permissions = $patron->permissions; >+ is( $permissions->{superlibrarian}, 1, 'Patron has superlibrarian permission' ); > > $schema->storage->txn_rollback; > }; >@@ -2382,10 +2386,21 @@ subtest 'alert_subscriptions tests' => sub { > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > >- my $subscription1 = $builder->build_object( { class => 'Koha::Subscriptions' } ); >+ my $subscription1 = $builder->build_object( { >+ class => 'Koha::Subscriptions', >+ value => { >+ librarian => $patron->borrowernumber, >+ } >+ }); > $subscription1->add_subscriber($patron); > >- my $subscription2 = $builder->build_object( { class => 'Koha::Subscriptions' } ); >+ >+ my $subscription2 = $builder->build_object( { >+ class => 'Koha::Subscriptions', >+ value => { >+ librarian => $patron->borrowernumber, >+ } >+ }); > $subscription2->add_subscriber($patron); > > my @subscriptions = $patron->alert_subscriptions->as_list; >@@ -2421,6 +2436,20 @@ subtest 'update_lastseen tests' => sub { > plan tests => 26; > $schema->storage->txn_begin; > >+ my $mock_cache = Test::MockModule->new('Koha::Cache'); >+ my %fake_cache; >+ >+ $mock_cache->mock('set_in_cache', sub { >+ my ( $self, $key, $value ) = @_; >+ $fake_cache{$key} = $value; >+ return; >+ }); >+ >+ $mock_cache->mock('get_from_cache', sub { >+ my ( $self, $key ) = @_; >+ return $fake_cache{$key}; >+ }); >+ > my $cache = Koha::Caches->get_instance(); > > t::lib::Mocks::mock_preference( >@@ -2429,12 +2458,12 @@ subtest 'update_lastseen tests' => sub { > ); > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >- my $userid = $patron->userid; >- $patron->lastseen(undef); > my $patron_info = $patron->unblessed; > delete $patron_info->{borrowernumber}; > $patron->delete(); > $patron = Koha::Patron->new($patron_info)->store(); >+ $patron->update_lastseen({ activity => 'creation' }); >+ $patron->discard_changes(); > > my $now = dt_from_string(); > my $today = $now->ymd(); >@@ -2444,21 +2473,32 @@ subtest 'update_lastseen tests' => sub { > 'Patron should have last seen when newly created if requested' > ); > >- my $cache_key = "track_activity_" . $patron->borrowernumber; >- my $cache_value = $cache->get_from_cache($cache_key); >- is( $cache_value, $today, "Cache was updated as expected" ); >+ my $cache_key = "track_activity_" . $patron->borrowernumber; >+ is( $cache->get_from_cache($cache_key), $today, "Cache was updated as expected" ); > > $patron->delete(); > > t::lib::Mocks::mock_preference( > 'TrackLastPatronActivityTriggers', >- 'login,connection,check_in,check_out,renewal,hold,article' >+ '' > ); >+ my $patron_no_trigger = $builder->build_object( { class => 'Koha::Patrons' } ); > >- $patron = Koha::Patron->new($patron_info)->store(); >- $cache_key = "track_activity_" . $patron->borrowernumber; >+ $patron_no_trigger->lastseen(undef)->store(); >+ >+ $patron_no_trigger->update_lastseen({ activity => 'login' }); >+ $patron_no_trigger->discard_changes(); >+ >+ is( $patron_no_trigger->lastseen, undef, >+ 'Patron should have not last seen when newly created if trigger not set' >+ ); >+ >+ >+ t::lib::Mocks::mock_preference( >+ 'TrackLastPatronActivityTriggers', >+ 'login,connection,check_in,check_out,renewal,hold,article' >+ ); > >- is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); > > $now = dt_from_string(); > Time::Fake->offset( $now->epoch ); >@@ -2553,12 +2593,12 @@ subtest 'update_lastseen tests' => sub { > 'login,connection,check_in,check_out,renewal,hold,article' > ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('login'); > $patron->_result()->discard_changes(); > isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('connection'); > $patron->_result()->discard_changes(); > isnt( >@@ -2566,7 +2606,7 @@ subtest 'update_lastseen tests' => sub { > 'Patron last seen should be changed after a connection if we cleared the cache' > ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('check_out'); > $patron->_result()->discard_changes(); > isnt( >@@ -2574,7 +2614,7 @@ subtest 'update_lastseen tests' => sub { > 'Patron last seen should be changed after a check_out if we cleared the cache' > ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('check_in'); > $patron->_result()->discard_changes(); > isnt( >@@ -2582,13 +2622,15 @@ subtest 'update_lastseen tests' => sub { > 'Patron last seen should be changed after a check_in if we cleared the cache' > ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('hold'); > $patron->_result()->discard_changes(); > isnt( > $patron->lastseen, $last_seen, > 'Patron last seen should be changed after a hold if we cleared the cache' > ); >+ >+ %fake_cache = (); > $patron->update_lastseen('article'); > $patron->_result()->discard_changes(); > isnt( >@@ -2596,7 +2638,7 @@ subtest 'update_lastseen tests' => sub { > 'Patron last seen should be changed after a article if we cleared the cache' > ); > >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('renewal'); > $patron->_result()->discard_changes(); > isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); >@@ -2604,7 +2646,7 @@ subtest 'update_lastseen tests' => sub { > # Check that the preference takes effect > t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); > $patron->lastseen(undef)->store; >- $cache->clear_from_cache($cache_key); >+ %fake_cache = (); > $patron->update_lastseen('login'); > $patron->_result()->discard_changes(); > is( >-- >2.39.5 >
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 20956
:
182955
|
185483
|
185491
|
186388
|
187592
|
187593
|
187594
|
188260
|
188261
|
188262
|
188263
|
190686
|
190687
|
190688
|
190689
|
190690
|
191472
|
191473
|
191474
|
191475
|
191476
|
191477
|
191478
|
192506
|
192507
|
192508
|
192509
|
192510
|
192511
|
192512
|
192604
|
192605
|
192606
|
192607
|
192608
|
192609
| 192610