|
Lines 428-434
subtest 'add() tests' => sub {
Link Here
|
| 428 |
$schema->storage->txn_rollback; |
428 |
$schema->storage->txn_rollback; |
| 429 |
|
429 |
|
| 430 |
subtest 'librarian access tests' => sub { |
430 |
subtest 'librarian access tests' => sub { |
| 431 |
plan tests => 40; |
431 |
plan tests => 41; |
| 432 |
|
432 |
|
| 433 |
$schema->storage->txn_begin; |
433 |
$schema->storage->txn_begin; |
| 434 |
|
434 |
|
|
Lines 438-444
subtest 'add() tests' => sub {
Link Here
|
| 438 |
my $attr = "Let's go"; |
438 |
my $attr = "Let's go"; |
| 439 |
|
439 |
|
| 440 |
# Disable trigger to notify patrons of password changes for these tests |
440 |
# Disable trigger to notify patrons of password changes for these tests |
| 441 |
t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 0 ); |
441 |
t::lib::Mocks::mock_preference( 'NotifyPasswordChange', 0 ); |
|
|
442 |
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 0 ); |
| 442 |
|
443 |
|
| 443 |
# Mock early, so existing mandatory attributes don't break all the tests |
444 |
# Mock early, so existing mandatory attributes don't break all the tests |
| 444 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
445 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
|
Lines 584-589
subtest 'add() tests' => sub {
Link Here
|
| 584 |
is( $letter_enqueued, 0, "Welcome not sent as it would be empty" ); |
585 |
is( $letter_enqueued, 0, "Welcome not sent as it would be empty" ); |
| 585 |
$message_has_content = 1; |
586 |
$message_has_content = 1; |
| 586 |
|
587 |
|
|
|
588 |
subtest 'EmailPatronRegistrations' => sub { |
| 589 |
plan tests => 20; |
| 590 |
t::lib::Mocks::mock_preference( 'AutoEmailNewUser', 0 ); |
| 591 |
t::lib::Mocks::mock_preference( 'EmailAddressForPatronRegistrations', 'test@example.org' ); |
| 592 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
| 593 |
$mocked_patron->mock( |
| 594 |
'GetPreparedLetter', |
| 595 |
sub { |
| 596 |
return 1; |
| 597 |
} |
| 598 |
); |
| 599 |
my $message_has_content = 1; |
| 600 |
my $letter_enqueued; |
| 601 |
$mocked_patron->mock( |
| 602 |
'EnqueueLetter', |
| 603 |
sub { |
| 604 |
$letter_enqueued = $message_has_content ? 1 : 0; |
| 605 |
|
| 606 |
# return a 'message_id' |
| 607 |
return $message_has_content ? 42 : undef; |
| 608 |
} |
| 609 |
); |
| 610 |
my $patron_to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 611 |
$newpatron = $patron_to_delete->to_api( { user => $librarian } ); |
| 612 |
|
| 613 |
# delete RO attributes |
| 614 |
delete $newpatron->{patron_id}; |
| 615 |
delete $newpatron->{restricted}; |
| 616 |
delete $newpatron->{expired}; |
| 617 |
delete $newpatron->{anonymized}; |
| 618 |
$patron_to_delete->delete; |
| 619 |
|
| 620 |
# Set a date field |
| 621 |
$newpatron->{date_of_birth} = '1980-06-18'; |
| 622 |
|
| 623 |
# Set a date-time field |
| 624 |
$newpatron->{last_seen} = |
| 625 |
output_pref( { dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' } ); |
| 626 |
|
| 627 |
# Test welcome email sending with EmailPatronRegistrations = 0 but opac_reg_yes override |
| 628 |
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 0 ); |
| 629 |
$letter_enqueued = 0; |
| 630 |
$t->post_ok( |
| 631 |
"//$userid:$password@/api/v1/patrons" => { 'x-koha-override' => 'opac_reg_yes' } => json => $newpatron ) |
| 632 |
->status_is( 201, 'Patron created successfully' )->header_like( |
| 633 |
Location => qr|^\/api\/v1\/patrons/\d*|, |
| 634 |
'REST3.4.1' |
| 635 |
)->json_has( '/patron_id', 'got a patron_id' )->json_is( '/cardnumber' => $newpatron->{cardnumber} ) |
| 636 |
->json_is( '/surname' => $newpatron->{surname} )->json_is( '/firstname' => $newpatron->{firstname} ) |
| 637 |
->json_is( '/date_of_birth' => $newpatron->{date_of_birth}, 'Date field set (Bug 28585)' ) |
| 638 |
->json_is( '/last_seen' => $newpatron->{last_seen}, 'Date-time field set (Bug 28585)' ); |
| 639 |
|
| 640 |
my $p = Koha::Patrons->find( { cardnumber => $newpatron->{cardnumber} } ); |
| 641 |
is( $letter_enqueued, 1, "Enqueued a registration notice due to opac_reg_yes override" ); |
| 642 |
|
| 643 |
# Test when EmailPatronRegistrations = EmailAddressForPatronRegistrations but opac_reg_no override |
| 644 |
$newpatron->{cardnumber} = "NewCard123456"; |
| 645 |
$newpatron->{userid} = "newuserid6"; |
| 646 |
$letter_enqueued = 0; |
| 647 |
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'EmailAddressForPatronRegistrations' ); |
| 648 |
$t->post_ok( "//$userid:$password@/api/v1/patrons" => |
| 649 |
{ 'x-koha-override' => 'opac_reg_no', 'x-confirm-not-duplicate' => 1 } => json => $newpatron ) |
| 650 |
->status_is( 201, 'Patron created successfully with opac_reg_no override' ); |
| 651 |
is( $letter_enqueued, 0, "No registration notice enqueued due to opac_reg_no override" ); |
| 652 |
|
| 653 |
# Test when EmailPatronRegistrations = EmailAddressForPatronRegistrations with no overrides |
| 654 |
$newpatron->{cardnumber} = "NewCard654321"; |
| 655 |
$newpatron->{userid} = "newuserid7"; |
| 656 |
$letter_enqueued = 0; |
| 657 |
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'EmailAddressForPatronRegistrations' ); |
| 658 |
$t->post_ok( |
| 659 |
"//$userid:$password@/api/v1/patrons" => { 'x-confirm-not-duplicate' => 1 } => json => $newpatron ) |
| 660 |
->status_is( |
| 661 |
201, |
| 662 |
'Patron created successfully with EmailPatronRegistrations = EmailAddressForPatronRegistrations' |
| 663 |
); |
| 664 |
is( |
| 665 |
$letter_enqueued, 1, |
| 666 |
"Patron registration notice enqueued due to EmailPatronRegistrations = EmailAddressForPatronRegistrations" |
| 667 |
); |
| 668 |
|
| 669 |
# Test case when notice template returns an empty string |
| 670 |
$newpatron->{cardnumber} = "NewCardPidgeon2"; |
| 671 |
$newpatron->{userid} = "newuserid9"; |
| 672 |
$letter_enqueued = 0; |
| 673 |
$message_has_content = 0; |
| 674 |
t::lib::Mocks::mock_preference( 'EmailPatronRegistrations', 'EmailAddressForPatronRegistrations' ); |
| 675 |
t::lib::Mocks::mock_preference( 'EmailAddressForPatronRegistrations', 'test@example.org' ); |
| 676 |
warning_like { |
| 677 |
$t->post_ok( |
| 678 |
"//$userid:$password@/api/v1/patrons" => { 'x-confirm-not-duplicate' => 1 } => json => $newpatron ) |
| 679 |
->status_is( |
| 680 |
201, |
| 681 |
'Patron created successfully with EmailPatronRegistrations = 1 and empty OPAC_REG notice' |
| 682 |
); |
| 683 |
} |
| 684 |
qr/can't enqueue letter/; |
| 685 |
is( $letter_enqueued, 0, "Registration notice not sent as it would be empty" ); |
| 686 |
$message_has_content = 1; |
| 687 |
}; |
| 688 |
|
| 587 |
subtest 'extended_attributes handling tests' => sub { |
689 |
subtest 'extended_attributes handling tests' => sub { |
| 588 |
|
690 |
|
| 589 |
plan tests => 29; |
691 |
plan tests => 29; |
| 590 |
- |
|
|