Bugzilla – Attachment 153437 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.23 KB, created by
Matt Blenkinsop
on 2023-07-14 08:15:22 UTC
(
hide
)
Description:
Bug 33245: Add unit test
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-07-14 08:15:22 UTC
Size:
4.23 KB
patch
obsolete
>From 9d73adcbb392d0b7aea709754796c040f01db885 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> >--- > t/db_dependent/Koha/Patron.t | 71 +++++++++++++++++++++++++++++++++++- > 1 file changed, 70 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 5d05a16efd..127ecedb8a 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 => 24; >+use Test::More tests => 25; > use Test::Exception; > use Test::Warn; > >@@ -37,6 +37,75 @@ use t::lib::Mocks; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >+subtest 'is_active' => sub { >+ plan tests => 18; >+ $schema->storage->txn_begin; >+ >+ # Check expiry >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ $patron->dateexpiry( dt_from_string->subtract( days => 1) )->store; >+ is( $patron->is_active, 0, 'Expired patron is not active' ); >+ $patron->dateexpiry(undef)->store; >+ is( $patron->is_active, 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, 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.37.1 (Apple Git-137.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