|
Lines 272-296
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 272 |
|
272 |
|
| 273 |
my $patron_1 |
273 |
my $patron_1 |
| 274 |
= $builder->build( |
274 |
= $builder->build( |
| 275 |
{ source => 'Borrower', value => { branchcode => $library_1 } } ) |
275 |
{ source => 'Borrower', value => { branchcode => $library_1 } } ); |
| 276 |
->{borrowernumber}; |
|
|
| 277 |
my $patron_2 |
276 |
my $patron_2 |
| 278 |
= $builder->build( |
277 |
= $builder->build( |
| 279 |
{ source => 'Borrower', value => { branchcode => $library_2 } } ) |
278 |
{ source => 'Borrower', value => { branchcode => $library_2 } } ); |
| 280 |
->{borrowernumber}; |
|
|
| 281 |
my $patron_3 |
279 |
my $patron_3 |
| 282 |
= $builder->build( |
280 |
= $builder->build( |
| 283 |
{ source => 'Borrower', value => { branchcode => $library_2 } } ) |
281 |
{ source => 'Borrower', value => { branchcode => $library_2 } } ); |
| 284 |
->{borrowernumber}; |
282 |
$patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} ); |
|
|
283 |
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); |
| 284 |
$patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); |
| 285 |
my $verification_token_1 = md5_hex( time().{}.rand().{}.$$ ); |
285 |
my $verification_token_1 = md5_hex( time().{}.rand().{}.$$ ); |
| 286 |
my $verification_token_2 = md5_hex( time().{}.rand().{}.$$ ); |
286 |
my $verification_token_2 = md5_hex( time().{}.rand().{}.$$ ); |
| 287 |
my $verification_token_3 = md5_hex( time().{}.rand().{}.$$ ); |
287 |
my $verification_token_3 = md5_hex( time().{}.rand().{}.$$ ); |
| 288 |
|
288 |
|
| 289 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_1, code => 'CODE_1', attribute => 'hello' } )->store(); |
289 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_1->borrowernumber, code => 'CODE_1', attribute => 'hello' } )->store(); |
| 290 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_2, code => 'CODE_2', attribute => 'bye' } )->store(); |
290 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_2->borrowernumber, code => 'CODE_2', attribute => 'bye' } )->store(); |
| 291 |
|
291 |
|
| 292 |
my $modification_1 = Koha::Patron::Modification->new( |
292 |
my $modification_1 = Koha::Patron::Modification->new( |
| 293 |
{ borrowernumber => $patron_1, |
293 |
{ borrowernumber => $patron_1->borrowernumber, |
| 294 |
surname => 'Hall', |
294 |
surname => 'Hall', |
| 295 |
firstname => 'Kyle', |
295 |
firstname => 'Kyle', |
| 296 |
verification_token => $verification_token_1, |
296 |
verification_token => $verification_token_1, |
|
Lines 302-308
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 302 |
1, 'pending_count() correctly returns 1' ); |
302 |
1, 'pending_count() correctly returns 1' ); |
| 303 |
|
303 |
|
| 304 |
my $modification_2 = Koha::Patron::Modification->new( |
304 |
my $modification_2 = Koha::Patron::Modification->new( |
| 305 |
{ borrowernumber => $patron_2, |
305 |
{ borrowernumber => $patron_2->borrowernumber, |
| 306 |
surname => 'Smith', |
306 |
surname => 'Smith', |
| 307 |
firstname => 'Sandy', |
307 |
firstname => 'Sandy', |
| 308 |
verification_token => $verification_token_2, |
308 |
verification_token => $verification_token_2, |
|
Lines 311-317
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 311 |
)->store(); |
311 |
)->store(); |
| 312 |
|
312 |
|
| 313 |
my $modification_3 = Koha::Patron::Modification->new( |
313 |
my $modification_3 = Koha::Patron::Modification->new( |
| 314 |
{ borrowernumber => $patron_3, |
314 |
{ borrowernumber => $patron_3->borrowernumber, |
| 315 |
surname => 'Smithy', |
315 |
surname => 'Smithy', |
| 316 |
firstname => 'Sandy', |
316 |
firstname => 'Sandy', |
| 317 |
verification_token => $verification_token_3 |
317 |
verification_token => $verification_token_3 |
|
Lines 324-330
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 324 |
my $pending = Koha::Patron::Modifications->pending(); |
324 |
my $pending = Koha::Patron::Modifications->pending(); |
| 325 |
is( scalar @{$pending}, 3, 'pending() returns an array with 3 elements' ); |
325 |
is( scalar @{$pending}, 3, 'pending() returns an array with 3 elements' ); |
| 326 |
|
326 |
|
| 327 |
my @filtered_modifications = grep { $_->{borrowernumber} eq $patron_1 } @{$pending}; |
327 |
my @filtered_modifications = grep { $_->{borrowernumber} eq $patron_1->borrowernumber } @{$pending}; |
| 328 |
my $p1_pm = $filtered_modifications[0]; |
328 |
my $p1_pm = $filtered_modifications[0]; |
| 329 |
my $p1_pm_attribute_1 = $p1_pm->{extended_attributes}->[0]; |
329 |
my $p1_pm_attribute_1 = $p1_pm->{extended_attributes}->[0]; |
| 330 |
|
330 |
|
|
Lines 332-338
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 332 |
is( ref($p1_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); |
332 |
is( ref($p1_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); |
| 333 |
is( $p1_pm_attribute_1->attribute, '', 'patron 1 has an empty value for the attribute' ); |
333 |
is( $p1_pm_attribute_1->attribute, '', 'patron 1 has an empty value for the attribute' ); |
| 334 |
|
334 |
|
| 335 |
@filtered_modifications = grep { $_->{borrowernumber} eq $patron_2 } @{$pending}; |
335 |
@filtered_modifications = grep { $_->{borrowernumber} eq $patron_2->borrowernumber } @{$pending}; |
| 336 |
my $p2_pm = $filtered_modifications[0]; |
336 |
my $p2_pm = $filtered_modifications[0]; |
| 337 |
|
337 |
|
| 338 |
is( scalar @{$p2_pm->{extended_attributes}}, 2 , 'patron 2 has 2 attribute modifications' ); |
338 |
is( scalar @{$p2_pm->{extended_attributes}}, 2 , 'patron 2 has 2 attribute modifications' ); |
|
Lines 346-351
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 346 |
is( $p2_pm_attribute_1->attribute, 'año', 'patron modification has the right attribute change' ); |
346 |
is( $p2_pm_attribute_1->attribute, 'año', 'patron modification has the right attribute change' ); |
| 347 |
is( $p2_pm_attribute_2->attribute, 'ciao', 'patron modification has the right attribute change' ); |
347 |
is( $p2_pm_attribute_2->attribute, 'ciao', 'patron modification has the right attribute change' ); |
| 348 |
|
348 |
|
|
|
349 |
|
| 350 |
C4::Context->_new_userenv('xxx'); |
| 351 |
set_logged_in_user( $patron_1 ); |
| 349 |
is( Koha::Patron::Modifications->pending_count($library_1), |
352 |
is( Koha::Patron::Modifications->pending_count($library_1), |
| 350 |
1, 'pending_count() correctly returns 1 if filtered by library' ); |
353 |
1, 'pending_count() correctly returns 1 if filtered by library' ); |
| 351 |
|
354 |
|
|
Lines 370-372
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 370 |
$schema->storage->txn_rollback; |
373 |
$schema->storage->txn_rollback; |
| 371 |
}; |
374 |
}; |
| 372 |
|
375 |
|
| 373 |
- |
376 |
sub set_logged_in_user { |
|
|
377 |
my ($patron) = @_; |
| 378 |
C4::Context->set_userenv( |
| 379 |
$patron->borrowernumber, $patron->userid, |
| 380 |
$patron->cardnumber, 'firstname', |
| 381 |
'surname', $patron->library->branchcode, |
| 382 |
'Midway Public Library', $patron->flags, |
| 383 |
'', '' |
| 384 |
); |
| 385 |
} |