Bugzilla – Attachment 165282 Details for
Bug 25996
Changes to restrictions should be logged
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25996: Unit tests
Bug-25996-Unit-tests.patch (text/plain), 4.92 KB, created by
ByWater Sandboxes
on 2024-04-22 13:17:47 UTC
(
hide
)
Description:
Bug 25996: Unit tests
Filename:
MIME Type:
Creator:
ByWater Sandboxes
Created:
2024-04-22 13:17:47 UTC
Size:
4.92 KB
patch
obsolete
>From 6d8ba46b94e8932cbfa170c8159ff90dc873b114 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 22 Apr 2024 01:03:54 -0300 >Subject: [PATCH] Bug 25996: Unit tests > >Sponsored-by: Karlsruhe Institute of Technology (KIT) >Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> >--- > t/db_dependent/Patron/Borrower_Debarments.t | 118 +++++++++++++++++++- > 1 file changed, 117 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t >index 7887332f09..84d3250cdc 100755 >--- a/t/db_dependent/Patron/Borrower_Debarments.t >+++ b/t/db_dependent/Patron/Borrower_Debarments.t >@@ -3,13 +3,17 @@ > use Modern::Perl; > > use C4::Context; >+ > use Koha::Database; >+use Koha::DateUtils qw(dt_from_string); > use Koha::Patrons; > use Koha::Account; >+use Koha::ActionLogs; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > >-use Test::More tests => 38; >+use Test::More tests => 39; > > use_ok('Koha::Patron::Debarments'); > >@@ -294,3 +298,115 @@ is( $restrictions->next->type->code, "TEST2", "Restriction left has type value ' > $account->pay( { amount => 5 } ); > $restrictions = $patron4->restrictions; > is( $restrictions->count, 0, "->restrictions returns 0 restrictions after paying all fees" ); >+ >+$schema->storage->txn_rollback; >+ >+subtest 'BorrowersLog tests' => sub { >+ >+ plan tests => 16; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { debarred => undef, debarredcomment => undef, } >+ } >+ ); >+ >+ my $type = $builder->build_object( { class => 'Koha::Patron::Restriction::Types' } ); >+ >+ foreach my $type (qw{CREATE_RESTRICTION MODIFY_RESTRICTION DELETE_RESTRICTION}) { >+ is( >+ Koha::ActionLogs->search( { module => 'MEMBERS', action => $type, object => $patron->id } )->count, 0, >+ "No prior '$type' logs" >+ ); >+ } >+ >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); >+ >+ my $add_comment = 'AddDebarment comment'; >+ my $add_expiration = dt_from_string()->add( days => 1 ); >+ >+ Koha::Patron::Debarments::AddDebarment( >+ { >+ borrowernumber => $patron->id, >+ expiration => $add_expiration, >+ type => $type->code, >+ comment => $add_comment, >+ } >+ ); >+ >+ my $restrictions = $patron->restrictions; >+ is( $restrictions->count, 1, 'Only one restriction present' ); >+ >+ my $restriction = $restrictions->next; >+ >+ my $mod_comment = 'ModDebarment comment'; >+ my $mod_expiration = dt_from_string()->add( days => 5 ); >+ >+ Koha::Patron::Debarments::ModDebarment( >+ { >+ borrower_debarment_id => $restriction->id, >+ comment => $mod_comment, >+ expiration => $mod_expiration, >+ } >+ ); >+ >+ Koha::Patron::Debarments::DelDebarment( $restriction->id ); >+ >+ is( $patron->restrictions->count, 0, 'No restrictions present' ); >+ >+ foreach my $type (qw{CREATE_RESTRICTION MODIFY_RESTRICTION DELETE_RESTRICTION}) { >+ is( >+ Koha::ActionLogs->search( { module => 'MEMBERS', action => $type, object => $patron->id } )->count, 0, >+ "No added '$type' logs" >+ ); >+ } >+ >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); >+ >+ Koha::Patron::Debarments::AddDebarment( >+ { >+ borrowernumber => $patron->id, >+ expiration => $add_expiration, >+ type => $type->code, >+ comment => $add_comment, >+ } >+ ); >+ >+ $restrictions = $patron->restrictions; >+ is( $restrictions->count, 1, 'Only one restriction present' ); >+ >+ $restriction = $restrictions->next; >+ >+ Koha::Patron::Debarments::ModDebarment( >+ { >+ borrower_debarment_id => $restriction->id, >+ comment => $mod_comment, >+ expiration => $mod_expiration, >+ } >+ ); >+ >+ Koha::Patron::Debarments::DelDebarment( $restriction->id ); >+ >+ is( $patron->restrictions->count, 0, 'No restrictions present' ); >+ >+ my $add_logs = >+ Koha::ActionLogs->search( { module => 'MEMBERS', action => 'CREATE_RESTRICTION', object => $patron->id } ); >+ my $mod_logs = >+ Koha::ActionLogs->search( { module => 'MEMBERS', action => 'MODIFY_RESTRICTION', object => $patron->id } ); >+ my $del_logs = >+ Koha::ActionLogs->search( { module => 'MEMBERS', action => 'DELETE_RESTRICTION', object => $patron->id } ); >+ >+ is( $add_logs->count, 1, 'Restriction creation logged' ); >+ like( $add_logs->next->info, qr/$add_comment/ ); >+ >+ is( $mod_logs->count, 1, 'Restriction modification logged' ); >+ like( $mod_logs->next->info, qr/$mod_comment/ ); >+ >+ is( $del_logs->count, 1, 'Restriction deletion logged' ); >+ is( $del_logs->next->info, q{}, 'Empty info field on deletion' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.39.2
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 25996
:
165244
|
165245
|
165246
|
165247
|
165267
|
165281
|
165282
|
165283
|
165284
|
165285
|
166056
|
166057
|
166058
|
166059
|
166060