Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 17; |
20 |
use Test::More tests => 18; |
21 |
use Test::Warn; |
21 |
use Test::Warn; |
22 |
|
22 |
|
23 |
use C4::Context; |
23 |
use C4::Context; |
Lines 103-107
foreach my $b ( $patrons->as_list() ) {
Link Here
|
103 |
is( $b->categorycode(), $categorycode, "Iteration returns a patron object" ); |
103 |
is( $b->categorycode(), $categorycode, "Iteration returns a patron object" ); |
104 |
} |
104 |
} |
105 |
|
105 |
|
|
|
106 |
subtest 'Test Koha::Patrons::merge' => sub { |
107 |
plan tests => 98; |
108 |
|
109 |
my $schema = Koha::Database->new()->schema(); |
110 |
|
111 |
my $resultsets = { |
112 |
Accountline => 'borrowernumber', |
113 |
ArticleRequest => 'borrowernumber', |
114 |
BorrowerAttribute => 'borrowernumber', |
115 |
BorrowerDebarment => 'borrowernumber', |
116 |
BorrowerFile => 'borrowernumber', |
117 |
BorrowerModification => 'borrowernumber', |
118 |
ClubEnrollment => 'borrowernumber', |
119 |
Issue => 'borrowernumber', |
120 |
ItemsLastBorrower => 'borrowernumber', |
121 |
Linktracker => 'borrowernumber', |
122 |
Message => 'borrowernumber', |
123 |
MessageQueue => 'borrowernumber', |
124 |
OldIssue => 'borrowernumber', |
125 |
OldReserve => 'borrowernumber', |
126 |
Rating => 'borrowernumber', |
127 |
Reserve => 'borrowernumber', |
128 |
Review => 'borrowernumber', |
129 |
Statistic => 'borrowernumber', |
130 |
SearchHistory => 'userid', |
131 |
Suggestion => 'suggestedby', |
132 |
TagAll => 'borrowernumber', |
133 |
Virtualshelfcontent => 'borrowernumber', |
134 |
Virtualshelfshare => 'borrowernumber', |
135 |
Virtualshelve => 'owner', |
136 |
}; |
137 |
|
138 |
my $keeper = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
139 |
my $loser_1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
140 |
my $loser_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
141 |
|
142 |
while (my ($r, $field) = each(%$resultsets)) { |
143 |
$builder->build( { source => $r, value => { $field => $keeper } } ); |
144 |
$builder->build( { source => $r, value => { $field => $loser_1 } } ); |
145 |
$builder->build( { source => $r, value => { $field => $loser_2 } } ); |
146 |
|
147 |
my $keeper_rs = |
148 |
$schema->resultset($r)->search( { $field => $keeper } ); |
149 |
is( $keeper_rs->count(), 1, "Found 1 $r rows for keeper" ); |
150 |
|
151 |
my $loser_1_rs = |
152 |
$schema->resultset($r)->search( { $field => $loser_1 } ); |
153 |
is( $loser_1_rs->count(), 1, "Found 1 $r rows for loser_1" ); |
154 |
|
155 |
my $loser_2_rs = |
156 |
$schema->resultset($r)->search( { $field => $loser_2 } ); |
157 |
is( $loser_2_rs->count(), 1, "Found 1 $r rows for loser_2" ); |
158 |
} |
159 |
|
160 |
my $results = Koha::Patrons->merge( |
161 |
{ |
162 |
keeper => $keeper, |
163 |
patrons => [ $loser_1, $loser_2 ], |
164 |
} |
165 |
); |
166 |
|
167 |
while (my ($r, $field) = each(%$resultsets)) { |
168 |
my $keeper_rs = |
169 |
$schema->resultset($r)->search( {$field => $keeper } ); |
170 |
is( $keeper_rs->count(), 3, "Found 2 $r rows for keeper" ); |
171 |
} |
172 |
|
173 |
is( Koha::Patrons->find($loser_1), undef, 'Loser 1 has been deleted' ); |
174 |
is( Koha::Patrons->find($loser_2), undef, 'Loser 2 has been deleted' ); |
175 |
}; |
176 |
|
106 |
$schema->storage->txn_rollback(); |
177 |
$schema->storage->txn_rollback(); |
107 |
|
178 |
|
108 |
- |
|
|