Bug 39180: Unit tests

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 117acffacc)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Nick Clemens 2025-05-21 14:21:33 +00:00 committed by Paul Derscheid
parent b9e2aac30a
commit 995e4c0177
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 207 additions and 2 deletions

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use utf8;
use Test::NoWarnings;
use Test::More tests => 76;
use Test::More tests => 77;
use Test::Exception;
use Test::MockModule;
use Test::Deep qw( cmp_deeply );
@ -1902,7 +1902,8 @@ subtest "CanBookBeRenewed | bookings" => sub {
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
t::lib::Mocks::mock_preference( 'RenewalPeriodBase', 'date_due' );
t::lib::Mocks::mock_preference( 'RenewalPeriodBase', 'date_due' );
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 );
my $renewing_patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $booked_patron = $builder->build_object( { class => 'Koha::Patrons' } );
@ -7438,6 +7439,210 @@ subtest 'NoRefundOnLostFinesPaidAge' => sub {
);
};
subtest 'ChildNeedsGuarantor' => sub {
plan tests => 18;
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 );
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $child_category = $builder->build_object(
{
class => 'Koha::Patron::Categories',
value => {
category_type => 'C',
enrolmentfee => 0,
}
}
);
my $guarantee_category = $builder->build_object(
{
class => 'Koha::Patron::Categories',
value => {
category_type => 'P',
enrolmentfee => 0,
can_be_guarantee => 1,
}
}
);
my $guarantor_category = $builder->build_object(
{
class => 'Koha::Patron::Categories',
value => {
category_type => 'P',
enrolmentfee => 0,
can_be_guarantee => 0,
}
}
);
my $child_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { categorycode => $child_category->categorycode, contactname => '' }
}
);
my $guarantee_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { categorycode => $guarantee_category->categorycode, contactname => '' }
}
);
my $guarantor_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { categorycode => $guarantee_category->categorycode, contactname => '' }
}
);
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 );
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'check_in,check_out,renewal' );
my $biblionumber = $builder->build_sample_biblio(
{
branchcode => $library->branchcode,
}
)->biblionumber;
Koha::CirculationRules->set_rules(
{
categorycode => undef,
itemtype => undef,
branchcode => $library->branchcode,
rules => {
issuelength => 14,
lengthunit => 'days',
}
}
);
my $item = $builder->build_sample_item(
{
biblionumber => $biblionumber,
library => $library->branchcode,
}
);
warnings_like {
AddIssue( $child_patron, $item->barcode, undef );
}
qr/Problem updating lastseen/,
"AddIssue generates a warning when Child type patron is missing a guarantor and ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $child_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
qr/Problem updating lastseen/,
"AddRenewal generates a warning when Child type patron is missing a guarantor and ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
qr/Problem updating lastseen/,
"AddReturn generates a warning when Child type patron is missing a guarantor and ChildNeedsGuarantor";
warnings_like {
AddIssue( $guarantee_patron, $item->barcode, undef );
}
qr/Problem updating lastseen/,
"AddIssue generates a warning when can_be_guarantee type patron is missing a guarantor and ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $guarantee_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
qr/Problem updating lastseen/,
"AddRenewal generates a warning when can_be_guarantee type patron is missing a guarantor and ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
qr/Problem updating lastseen/,
"AddReturn generates a warning when can_be_guarantee type patron is missing a guarantor and ChildNeedsGuarantor";
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 );
warnings_like {
AddIssue( $child_patron, $item->barcode, undef );
}
undef, "AddIssue generates no warning when Child type patron is missing a guarantor and not ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $child_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
undef, "AddRenewal generates no warning when Child type patron is missing a guarantor and not ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
undef, "AddReturn generates no warning when Child type patron is missing a guarantor and not ChildNeedsGuarantor";
warnings_like {
AddIssue( $guarantee_patron, $item->barcode, undef );
}
undef,
"AddIssue generates no warning when can_be_guarantee type patron is missing a guarantor and not ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $guarantee_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
undef,
"AddRenewal generates no warning when can_be_guarantee type patron is missing a guarantor and not ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
undef,
"AddReturn generates no warning when can_be_guarantee type patron is missing a guarantor and not ChildNeedsGuarantor";
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 );
$child_patron->contactname("Anybody")->store;
warnings_like {
AddIssue( $child_patron, $item->barcode, undef );
}
undef, "AddIssue generates no warning when Child type patron has a guarantor and ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $child_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
undef, "AddRenewal generates no warning when Child type patron has a guarantor and not ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
undef, "AddReturn generates no warning when Child type patron has a guarantor and not ChildNeedsGuarantor";
$guarantee_patron->add_guarantor( { guarantor_id => $guarantor_patron->borrowernumber, relationship => 'father' } );
warnings_like {
AddIssue( $guarantee_patron, $item->barcode, undef );
}
undef,
"AddIssue generates no warning when can_be_guarantee type patron has a guarantor and not ChildsNeedsGuarantor";
warnings_like {
AddRenewal(
{
borrowernumber => $guarantee_patron->borrowernumber, itemnumber => $item->itemnumber,
branch => $library->branchcode
}
);
}
undef,
"AddRenewal generates no warning when can_be_guarantee type patron has a guarantor and not ChildNeedsGuarantor";
warnings_like {
AddReturn( $item->barcode, $library->branchcode, undef, undef );
}
undef,
"AddReturn generates no warning when can_be_guarantee type patron has a guarantor and not ChildNeedsGuarantor";
};
$schema->storage->txn_rollback;
C4::Context->clear_syspref_cache();
$branches = Koha::Libraries->search();