Line 0
Link Here
|
0 |
- |
1 |
# This file is part of Koha |
|
|
2 |
# |
3 |
# Koha is free software; you can redistribute it and/or modify it |
4 |
# under the terms of the GNU General Public License as published by |
5 |
# the Free Software Foundation; either version 3 of the License, or |
6 |
# (at your option) any later version. |
7 |
# |
8 |
# Koha is distributed in the hope that it will be useful, but |
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
# GNU General Public License for more details. |
12 |
# |
13 |
# You should have received a copy of the GNU General Public License |
14 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
15 |
|
16 |
use Modern::Perl; |
17 |
use Test::More tests => 1; |
18 |
|
19 |
use C4::Log; |
20 |
|
21 |
use t::lib::Mocks; |
22 |
use t::lib::TestBuilder; |
23 |
|
24 |
my $schema = Koha::Database->new->schema; |
25 |
$schema->storage->txn_begin; |
26 |
|
27 |
subtest 'Test Koha::Patrons::merge' => sub { |
28 |
|
29 |
plan tests => 4; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
my $keeper = $builder->build_object({ class => 'Koha::Patrons' }); |
33 |
|
34 |
my $borrower1 = $builder->build({source => 'Borrower'}); |
35 |
my $borrower2 = $builder->build({source => 'Borrower'}); |
36 |
my $borrower3 = $builder->build({source => 'Borrower'}); |
37 |
my $borrower4 = $builder->build({source => 'Borrower'}); |
38 |
|
39 |
#test with BorrowersLog on |
40 |
t::lib::Mocks::mock_preference('BorrowersLog', 1); |
41 |
|
42 |
my $results = $keeper->merge_with([ $borrower1->{borrowernumber}, $borrower2->{borrowernumber} ]); |
43 |
|
44 |
my $log=GetLogs("","","",["Patrons"],["Merge"],$borrower1->{borrowernumber},""); |
45 |
|
46 |
my $info_borrower1 = $borrower1->{firstname} . " " . $borrower1->{surname} . " (" . $borrower1->{cardnumber} . ") has been merged into " . |
47 |
$keeper->firstname . " " . $keeper->surname . " (" . $keeper->cardnumber . ")"; |
48 |
my $info_log = $log->[0]{info}; |
49 |
|
50 |
is($info_log,$info_borrower1,"GetLogs returns results in the log viewer for the merge of " . $borrower1->{borrowernumber}); |
51 |
|
52 |
$log=GetLogs("","","",["Patrons"],["Merge"],$borrower2->{borrowernumber},""); |
53 |
|
54 |
my $info_borrower2 = $borrower2->{firstname} . " " . $borrower2->{surname} . " (" . $borrower2->{cardnumber} . ") has been merged into " . |
55 |
$keeper->firstname . " " . $keeper->surname . " (" . $keeper->cardnumber . ")"; |
56 |
$info_log = $log->[0]{info}; |
57 |
|
58 |
is($info_log,$info_borrower2,"GetLogs returns results in the log viewer for the merge of " . $borrower2->{borrowernumber}); |
59 |
|
60 |
|
61 |
#test with BorrowersLog off |
62 |
t::lib::Mocks::mock_preference('BorrowersLog', 0); |
63 |
|
64 |
$results = $keeper->merge_with([ $borrower3->{borrowernumber}, $borrower4->{borrowernumber} ]); |
65 |
|
66 |
$log=GetLogs("","","",["Patrons"],["Merge"],$borrower3->{borrowernumber},""); |
67 |
$info_log = $log->[0]{info}; |
68 |
|
69 |
is($info_log,undef,"GetLogs didn't returns results in the log viewer for the merge of " . $borrower3->{borrowernumber}); |
70 |
|
71 |
$log=GetLogs("","","",["Patrons"],["Merge"],$borrower4->{borrowernumber},""); |
72 |
$info_log = $log->[0]{info}; |
73 |
|
74 |
is($info_log,undef,"GetLogs didn't returns results in the log viewer for the merge of " . $borrower4->{borrowernumber}); |
75 |
}; |
76 |
|
77 |
$schema->storage->txn_rollback; |