Bugzilla – Attachment 156530 Details for
Bug 33245
Add $patron->is_active
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33245: Add unit test
Bug-33245-Add-unit-test.patch (text/plain), 4.76 KB, created by
Jonathan Druart
on 2023-10-04 13:03:32 UTC
(
hide
)
Description:
Bug 33245: Add unit test
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-10-04 13:03:32 UTC
Size:
4.76 KB
patch
obsolete
>From 16656f2dd92cdacff30e1696b5e8aca1e5e61223 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 16 Mar 2023 15:41:55 +0000 >Subject: [PATCH] Bug 33245: Add unit test > >Test plan: >Run t/db_dependent/Koha/Patron.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> > >JD amended patch: Adjust number of tests >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Koha/Patron.t | 88 +++++++++++++++++++++++++++++++++++- > 1 file changed, 87 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index c0b00d733ff..f7d9c63ef4d 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 => 25; >+use Test::More tests => 26; > use Test::Exception; > use Test::Warn; > >@@ -37,6 +37,92 @@ use t::lib::Mocks; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >+subtest 'is_active' => sub { >+ plan tests => 19; >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ throws_ok { $patron->is_active } 'Koha::Exceptions::MissingParameter', 'Called without params'; >+ >+ # Check expiry >+ $patron->dateexpiry( dt_from_string->subtract( days => 1 ) )->store; >+ is( $patron->is_active( { days => 1 } ), 0, 'Expired patron is not active' ); >+ $patron->dateexpiry(undef)->store; >+ is( $patron->is_active( { days => 1 } ), 1, 'Expiry date removed' ); >+ >+ # Change enrolled date now >+ $patron->dateenrolled('2020-01-01')->store; >+ >+ # Check lastseen, test days parameter >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); >+ $patron->track_login; >+ is( $patron->is_active( { days => 1 } ), 1, 'Just logged in' ); >+ my $ago = dt_from_string->subtract( days => 2 ); >+ $patron->lastseen($ago)->store; >+ is( $patron->is_active( { days => 1 } ), 0, 'Not active since yesterday' ); >+ is( $patron->is_active( { days => 3 } ), 1, 'Active within last 3 days' ); >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 0 ); >+ is( $patron->is_active( { days => 3 } ), 0, 'Pref disabled' ); >+ >+ # Look at holds, test with weeks >+ $ago = dt_from_string->subtract( weeks => 2 ); >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { borrowernumber => $patron->id, timestamp => $ago }, >+ } >+ ); >+ is( $patron->is_active( { weeks => 1 } ), 0, 'No holds in 1 weeks' ); >+ is( $patron->is_active( { weeks => 3 } ), 1, 'Hold in last 3 weeks' ); >+ $hold->delete; >+ my $old_hold = $builder->build_object( >+ { >+ class => 'Koha::Old::Holds', >+ value => { borrowernumber => $patron->id, timestamp => $ago }, >+ } >+ ); >+ is( $patron->is_active( { weeks => 1 } ), 0, 'No old holds in 1 weeks' ); >+ is( $patron->is_active( { weeks => 3 } ), 1, 'Old hold in last 3 weeks' ); >+ $old_hold->delete; >+ >+ # Look at checkouts, test with months >+ $ago = dt_from_string->subtract( months => 2 ); >+ my $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { borrowernumber => $patron->id, timestamp => $ago }, >+ } >+ ); >+ is( $patron->is_active( { months => 1 } ), 0, 'No checkouts in 1 months' ); >+ is( $patron->is_active( { months => 3 } ), 1, 'Checkout in last 3 months' ); >+ $checkout->delete; >+ my $old_checkout = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { borrowernumber => $patron->id, timestamp => $ago }, >+ } >+ ); >+ is( $patron->is_active( { months => 1 } ), 0, 'No old checkouts in 1 months' ); >+ is( $patron->is_active( { months => 3 } ), 1, 'Old checkout in last 3 months' ); >+ $old_checkout->delete; >+ >+ # Look at article_requests, test with since >+ $ago = dt_from_string->subtract( days => 10 ); >+ my $article_request = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { borrowernumber => $patron->id, updated_on => $ago }, >+ } >+ ); >+ is( $patron->is_active( { days => 9 } ), 0, 'No article requests in 9 days' ); >+ is( $patron->is_active( { days => 10 } ), 1, 'Article requests in 10 days' ); >+ is( $patron->is_active( { since => $ago } ), 1, 'Article requests since ago' ); >+ is( $patron->is_active( { since => $ago->add( days => 1 ) } ), 0, 'No article requests since ago + 1 day' ); >+ $article_request->delete; >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'add_guarantor() tests' => sub { > > plan tests => 6; >-- >2.34.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 33245
:
151800
|
151801
|
151802
|
153435
|
153436
|
153437
|
155050
|
155051
|
155052
|
155161
|
155162
|
155163
|
156528
|
156529
|
156530
|
156541
|
156542
|
156543