|
Lines 22-27
use Koha::Database;
Link Here
|
| 22 |
use Koha::Illrequestattributes; |
22 |
use Koha::Illrequestattributes; |
| 23 |
use Koha::Illrequest::Config; |
23 |
use Koha::Illrequest::Config; |
| 24 |
use Koha::Patrons; |
24 |
use Koha::Patrons; |
|
|
25 |
use Koha::MessageAttributes; |
| 26 |
use Koha::MessageAttribute; |
| 27 |
use Koha::Notice::Templates; |
| 25 |
use Koha::AuthorisedValueCategories; |
28 |
use Koha::AuthorisedValueCategories; |
| 26 |
use Koha::AuthorisedValues; |
29 |
use Koha::AuthorisedValues; |
| 27 |
use t::lib::Mocks; |
30 |
use t::lib::Mocks; |
|
Lines 376-382
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 376 |
|
379 |
|
| 377 |
subtest 'Backend core methods' => sub { |
380 |
subtest 'Backend core methods' => sub { |
| 378 |
|
381 |
|
| 379 |
plan tests => 19; |
382 |
plan tests => 18; |
| 380 |
|
383 |
|
| 381 |
$schema->storage->txn_begin; |
384 |
$schema->storage->txn_begin; |
| 382 |
|
385 |
|
|
Lines 567-586
subtest 'Backend core methods' => sub {
Link Here
|
| 567 |
}) } |
570 |
}) } |
| 568 |
"Generic confirm: missing to dies OK."; |
571 |
"Generic confirm: missing to dies OK."; |
| 569 |
|
572 |
|
| 570 |
dies_ok { $illrq->generic_confirm({ |
|
|
| 571 |
current_branchcode => $illbrn->{branchcode}, |
| 572 |
partners => $partner1->{email}, |
| 573 |
stage => 'draft' |
| 574 |
}) } |
| 575 |
"Generic confirm: missing from dies OK."; |
| 576 |
|
| 577 |
$schema->storage->txn_rollback; |
573 |
$schema->storage->txn_rollback; |
| 578 |
}; |
574 |
}; |
| 579 |
|
575 |
|
| 580 |
|
576 |
|
| 581 |
subtest 'Helpers' => sub { |
577 |
subtest 'Helpers' => sub { |
| 582 |
|
578 |
|
| 583 |
plan tests => 7; |
579 |
plan tests => 21; |
| 584 |
|
580 |
|
| 585 |
$schema->storage->txn_begin; |
581 |
$schema->storage->txn_begin; |
| 586 |
|
582 |
|
|
Lines 588-593
subtest 'Helpers' => sub {
Link Here
|
| 588 |
my $backend = Test::MockObject->new; |
584 |
my $backend = Test::MockObject->new; |
| 589 |
$backend->set_isa('Koha::Illbackends::Mock'); |
585 |
$backend->set_isa('Koha::Illbackends::Mock'); |
| 590 |
$backend->set_always('name', 'Mock'); |
586 |
$backend->set_always('name', 'Mock'); |
|
|
587 |
$backend->mock( |
| 588 |
'metadata', |
| 589 |
sub { |
| 590 |
my ( $self, $rq ) = @_; |
| 591 |
return { |
| 592 |
title => 'mytitle', |
| 593 |
author => 'myauthor' |
| 594 |
} |
| 595 |
} |
| 596 |
); |
| 591 |
|
597 |
|
| 592 |
my $config = Test::MockObject->new; |
598 |
my $config = Test::MockObject->new; |
| 593 |
$config->set_always('backend_dir', "/tmp"); |
599 |
$config->set_always('backend_dir', "/tmp"); |
|
Lines 596-604
subtest 'Helpers' => sub {
Link Here
|
| 596 |
source => 'Borrower', |
602 |
source => 'Borrower', |
| 597 |
value => { categorycode => "A" } |
603 |
value => { categorycode => "A" } |
| 598 |
}); |
604 |
}); |
|
|
605 |
# Create a mocked branch with no email addressed defined |
| 606 |
my $illbrn = $builder->build({ |
| 607 |
source => 'Branch', |
| 608 |
value => { |
| 609 |
branchcode => 'HDE', |
| 610 |
branchemail => "", |
| 611 |
branchillemail => "", |
| 612 |
branchreplyto => "" |
| 613 |
} |
| 614 |
}); |
| 599 |
my $illrq = $builder->build({ |
615 |
my $illrq = $builder->build({ |
| 600 |
source => 'Illrequest', |
616 |
source => 'Illrequest', |
| 601 |
value => { branchcode => "CPL", borrowernumber => $patron->{borrowernumber} } |
617 |
value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} } |
| 602 |
}); |
618 |
}); |
| 603 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
619 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
| 604 |
$illrq_obj->_config($config); |
620 |
$illrq_obj->_config($config); |
|
Lines 606-617
subtest 'Helpers' => sub {
Link Here
|
| 606 |
|
622 |
|
| 607 |
# getPrefix |
623 |
# getPrefix |
| 608 |
$config->set_series('getPrefixes', |
624 |
$config->set_series('getPrefixes', |
| 609 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
625 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 610 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
626 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 611 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
627 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "HDE" }), "TEST", |
| 612 |
"getPrefix: branch"); |
628 |
"getPrefix: branch"); |
| 613 |
$config->set_series('getPrefixes', |
629 |
$config->set_series('getPrefixes', |
| 614 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
630 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 615 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
631 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 616 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
632 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
| 617 |
"getPrefix: default"); |
633 |
"getPrefix: default"); |
|
Lines 621-631
subtest 'Helpers' => sub {
Link Here
|
| 621 |
|
637 |
|
| 622 |
# id_prefix |
638 |
# id_prefix |
| 623 |
$config->set_series('getPrefixes', |
639 |
$config->set_series('getPrefixes', |
| 624 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
640 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 625 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
641 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 626 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
642 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
| 627 |
$config->set_series('getPrefixes', |
643 |
$config->set_series('getPrefixes', |
| 628 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
644 |
{ HDET => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
| 629 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
645 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 630 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
646 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
| 631 |
|
647 |
|
|
Lines 635-640
subtest 'Helpers' => sub {
Link Here
|
| 635 |
$illrq_obj->status('CANCREQ')->store; |
651 |
$illrq_obj->status('CANCREQ')->store; |
| 636 |
is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); |
652 |
is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); |
| 637 |
|
653 |
|
|
|
654 |
#send_patron_notice |
| 655 |
my $attr = Koha::MessageAttributes->find({ message_name => 'Ill_ready' }); |
| 656 |
C4::Members::Messaging::SetMessagingPreference({ |
| 657 |
borrowernumber => $patron->{borrowernumber}, |
| 658 |
message_attribute_id => $attr->message_attribute_id, |
| 659 |
message_transport_types => ['email'] |
| 660 |
}); |
| 661 |
my $return_patron = $illrq_obj->send_patron_notice('ILL_PICKUP_READY'); |
| 662 |
my $notice = $schema->resultset('MessageQueue')->search({ |
| 663 |
letter_code => 'ILL_PICKUP_READY', |
| 664 |
message_transport_type => 'email', |
| 665 |
borrowernumber => $illrq_obj->borrowernumber |
| 666 |
})->next()->letter_code; |
| 667 |
is_deeply( |
| 668 |
$return_patron, |
| 669 |
{ result => { success => ['email'], fail => [] } }, |
| 670 |
"Correct return when notice created" |
| 671 |
); |
| 672 |
is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created"); |
| 673 |
|
| 674 |
my $return_patron_fail = $illrq_obj->send_patron_notice(); |
| 675 |
is_deeply( |
| 676 |
$return_patron_fail, |
| 677 |
{ error => 'notice_no_type' }, |
| 678 |
"Correct error when missing type" |
| 679 |
); |
| 680 |
|
| 681 |
#get_staff_to_address |
| 682 |
# Mock a KohaAdminEmailAddress syspref |
| 683 |
t::lib::Mocks::mock_preference( |
| 684 |
'KohaAdminEmailAddress', |
| 685 |
'kohaadmin@nowhere.com' |
| 686 |
); |
| 687 |
# No branch addresses defined and no ILLDefaultStaffEmail, so should |
| 688 |
# fall back to Koha admin address |
| 689 |
my $email_kohaadmin = $illrq_obj->get_staff_to_address; |
| 690 |
ok( |
| 691 |
$email_kohaadmin eq 'kohaadmin@nowhere.com', |
| 692 |
'get_staff_to_address falls back to Koha admin in the absence of other alternatives' |
| 693 |
); |
| 694 |
# General branch address defined, should fall back to that |
| 695 |
$builder->delete({ source => 'Branch', records => $illbrn }); |
| 696 |
$illbrn = $builder->build({ |
| 697 |
source => 'Branch', |
| 698 |
value => { |
| 699 |
branchcode => 'HDE', |
| 700 |
branchemail => 'branch@nowhere.com', |
| 701 |
branchillemail => "", |
| 702 |
branchreplyto => "" |
| 703 |
} |
| 704 |
}); |
| 705 |
my $email_gen_branch = $illrq_obj->get_staff_to_address; |
| 706 |
ok( |
| 707 |
$email_gen_branch eq 'branch@nowhere.com', |
| 708 |
'get_staff_to_address falls back to general branch address when defined' |
| 709 |
); |
| 710 |
# ILL staff syspref address defined, should fall back to that |
| 711 |
t::lib::Mocks::mock_preference( |
| 712 |
'ILLDefaultStaffEmail', |
| 713 |
'illstaff@nowhere.com' |
| 714 |
); |
| 715 |
my $email_syspref = $illrq_obj->get_staff_to_address; |
| 716 |
ok( |
| 717 |
$email_syspref eq 'illstaff@nowhere.com', |
| 718 |
'get_staff_to_address falls back to ILLDefaultStaffEmail when defined' |
| 719 |
); |
| 720 |
# Branch ILL address defined, should use that |
| 721 |
$builder->delete({ source => 'Branch', records => $illbrn }); |
| 722 |
$illbrn = $builder->build({ |
| 723 |
source => 'Branch', |
| 724 |
value => { |
| 725 |
branchcode => 'HDE', |
| 726 |
branchemail => 'branch@nowhere.com', |
| 727 |
branchillemail => 'branchill@nowhere.com', |
| 728 |
branchreplyto => "" |
| 729 |
} |
| 730 |
}); |
| 731 |
my $email_branch = $illrq_obj->get_staff_to_address; |
| 732 |
ok( |
| 733 |
$email_branch eq 'branchill@nowhere.com', |
| 734 |
'get_staff_to_address uses branch ILL address when defined' |
| 735 |
); |
| 736 |
|
| 737 |
#send_staff_notice |
| 738 |
# Specify that no staff notices should be send |
| 739 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', ''); |
| 740 |
my $return_staff_cancel_fail = |
| 741 |
$illrq_obj->send_staff_notice('ILL_REQUEST_CANCEL'); |
| 742 |
is_deeply( |
| 743 |
$return_staff_cancel_fail, |
| 744 |
{ error => 'notice_not_enabled' }, |
| 745 |
"Does not send notices that are not enabled" |
| 746 |
); |
| 747 |
# Specify that the cancel notice can be sent |
| 748 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL'); |
| 749 |
my $return_staff_cancel = $illrq_obj->send_staff_notice( |
| 750 |
'ILL_REQUEST_CANCEL' |
| 751 |
); |
| 752 |
my $cancel = $schema->resultset('MessageQueue')->search({ |
| 753 |
letter_code => 'ILL_REQUEST_CANCEL', |
| 754 |
message_transport_type => 'email', |
| 755 |
to_address => 'branchill@nowhere.com' |
| 756 |
})->next()->letter_code; |
| 757 |
is_deeply( |
| 758 |
$return_staff_cancel, |
| 759 |
{ success => 'notice_queued' }, |
| 760 |
"Correct return when staff notice created" |
| 761 |
); |
| 762 |
|
| 763 |
my $return_staff_fail = $illrq_obj->send_staff_notice(); |
| 764 |
is_deeply( |
| 765 |
$return_staff_fail, |
| 766 |
{ error => 'notice_no_type' }, |
| 767 |
"Correct error when missing type" |
| 768 |
); |
| 769 |
|
| 770 |
#get_notice |
| 771 |
my $not = $illrq_obj->get_notice({ |
| 772 |
notice_code => 'ILL_REQUEST_CANCEL', |
| 773 |
transport => 'email' |
| 774 |
}); |
| 775 |
|
| 776 |
# We test the properties of the hashref separately because the random |
| 777 |
# hash ordering of the metadata means we can't test the entire thing |
| 778 |
# with is_deeply |
| 779 |
ok( |
| 780 |
$not->{module} eq 'ill', |
| 781 |
'Correct module return from get_notice' |
| 782 |
); |
| 783 |
ok( |
| 784 |
$not->{name} eq 'ILL request cancelled', |
| 785 |
'Correct name return from get_notice' |
| 786 |
); |
| 787 |
ok( |
| 788 |
$not->{message_transport_type} eq 'email', |
| 789 |
'Correct message_transport_type return from get_notice' |
| 790 |
); |
| 791 |
ok( |
| 792 |
$not->{title} eq 'Interlibrary loan request cancelled', |
| 793 |
'Correct title return from get_notice' |
| 794 |
); |
| 795 |
|
| 638 |
$schema->storage->txn_rollback; |
796 |
$schema->storage->txn_rollback; |
| 639 |
}; |
797 |
}; |
| 640 |
|
798 |
|
| 641 |
- |
|
|