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