Bug 23538: Unit tests

Test plan:
1. Run unit tests:
sudo koha-shell <instance>
cd t/db_dependent/Koha
prove -v Patron.t

Sponsored-by: Catalyst IT

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Alex Buckley 2022-04-06 10:38:38 +00:00 committed by Tomas Cohen Arazi
parent 1c0a187968
commit 3f70c9d6bc
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 18;
use Test::More tests => 19;
use Test::Exception;
use Test::Warn;
@ -1292,3 +1292,59 @@ subtest 'encode_secret and decoded_secret' => sub {
$schema->storage->txn_rollback;
};
subtest 'notify_library_of_registration()' => sub {
plan tests => 6;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
my $library = $builder->build_object(
{
class => 'Koha::Libraries',
value => {
branchemail => 'from@mybranch.com',
branchreplyto => 'to@mybranch.com'
}
}
);
my $patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => {
branchcode => $library->branchcode
}
}
);
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'root@localhost' );
t::lib::Mocks::mock_preference( 'EmailAddressForPatronRegistrations', 'library@localhost' );
# Test when EmailPatronRegistrations equals BranchEmailAddress
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'BranchEmailAddress' );
is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals BranchEmailAddress');
my $sth = $dbh->prepare("SELECT to_address FROM message_queue where borrowernumber = ?");
$sth->execute( $patron->borrowernumber );
my $to_address = $sth->fetchrow_array;
is( $to_address, 'to@mybranch.com', 'OPAC_REG email queued to go to branchreplyto address when EmailPatronRegistration equals BranchEmailAddress' );
$dbh->do(q|DELETE FROM message_queue|);
# Test when EmailPatronRegistrations equals EmailAddressForPatronRegistrations
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'EmailAddressForPatronRegistrations' );
is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals EmailAddressForPatronRegistrations');
$sth->execute( $patron->borrowernumber );
$to_address = $sth->fetchrow_array;
is( $to_address, 'library@localhost', 'OPAC_REG email queued to go to EmailAddressForPatronRegistrations syspref when EmailPatronRegistration equals EmailAddressForPatronRegistrations' );
$dbh->do(q|DELETE FROM message_queue|);
# Test when EmailPatronRegistrations equals KohaAdminEmailAddress
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'KohaAdminEmailAddress' );
is( $patron->notify_library_of_registration(C4::Context->preference('EmailPatronRegistrations')), 1, 'OPAC_REG email is queued if EmailPatronRegistration syspref equals KohaAdminEmailAddress');
$sth->execute( $patron->borrowernumber );
$to_address = $sth->fetchrow_array;
is( $to_address, 'root@localhost', 'OPAC_REG email queued to go to KohaAdminEmailAddress syspref when EmailPatronRegistration equals KohaAdminEmailAddress' );
$dbh->do(q|DELETE FROM message_queue|);
$schema->storage->txn_rollback;
};