Bug 22632: Unit Testing of patch 22632

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit ad7b8607ed)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Axel Amghar 2019-04-12 15:59:23 +02:00 committed by Paul Derscheid
parent e8ed7d01f1
commit f0b80e6c79
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,76 @@
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 1;
use C4::Log;
use t::lib::Mocks;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
subtest 'Test Koha::Patrons::merge' => sub {
plan tests => 4;
my $builder = t::lib::TestBuilder->new;
my $keeper = $builder->build_object({ class => 'Koha::Patrons' });
my $borrower1 = $builder->build({source => 'Borrower'});
my $borrower2 = $builder->build({source => 'Borrower'});
my $borrower3 = $builder->build({source => 'Borrower'});
my $borrower4 = $builder->build({source => 'Borrower'});
#test with BorrowersLog on
t::lib::Mocks::mock_preference('BorrowersLog', 1);
my $results = $keeper->merge_with([ $borrower1->{borrowernumber}, $borrower2->{borrowernumber} ]);
my $log=GetLogs("","","",["MEMBERS"],["Merge"],$keeper->id,"");
my $info_borrower1 = $borrower1->{firstname} . " " . $borrower1->{surname} . " (" . $borrower1->{cardnumber} . ") has been merged into " .
$keeper->firstname . " " . $keeper->surname . " (" . $keeper->cardnumber . ")";
my $info_log = $log->[0]{info};
is($info_log,$info_borrower1,"GetLogs returns results in the log viewer for the merge of " . $borrower1->{borrowernumber});
my $info_borrower2 = $borrower2->{firstname} . " " . $borrower2->{surname} . " (" . $borrower2->{cardnumber} . ") has been merged into " .
$keeper->firstname . " " . $keeper->surname . " (" . $keeper->cardnumber . ")";
$info_log = $log->[1]{info};
is($info_log,$info_borrower2,"GetLogs returns results in the log viewer for the merge of " . $borrower2->{borrowernumber});
#test with BorrowersLog off
t::lib::Mocks::mock_preference('BorrowersLog', 0);
$keeper = $builder->build_object({ class => 'Koha::Patrons' });
$results = $keeper->merge_with([ $borrower3->{borrowernumber}, $borrower4->{borrowernumber} ]);
$log=GetLogs("","","",["MEMBERS"],["Merge"],$keeper->id,"");
$info_log = $log->[0]{info};
is($info_log,undef,"GetLogs didn't returns results in the log viewer for the merge of " . $borrower3->{borrowernumber});
$info_log = $log->[1]{info};
is($info_log,undef,"GetLogs didn't returns results in the log viewer for the merge of " . $borrower4->{borrowernumber});
};
$schema->storage->txn_rollback;