]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/live_t/35-lp1955079-send-record-email.t
LP#1955079: Use Email::MIME for emailing records in the OPAC
[working/Evergreen.git] / Open-ILS / src / perlmods / live_t / 35-lp1955079-send-record-email.t
1 #!perl
2
3 use strict; use warnings;
4 use Test::More tests => 6;
5 use Test::MockModule;
6 use OpenILS::Utils::TestUtils;
7 use OpenILS::Utils::CStoreEditor qw/:funcs/;
8 use Apache2::Const -compile => qw(OK);
9 use CGI;
10
11 use_ok('OpenILS::WWW::EGCatLoader');
12 can_ok( 'OpenILS::WWW::EGCatLoader', 'load_print_or_email_preview' );
13 can_ok( 'OpenILS::WWW::EGCatLoader', 'load_email_record' );
14
15 use constant ATEV_ID => '123456789';
16 use constant PATRON_USERNAME  => '99999359616';
17 use constant PATRON_PASSWORD  => 'andreac1234';
18
19 my $script = OpenILS::Utils::TestUtils->new();
20 $script->bootstrap;
21 $script->authenticate({
22         username => PATRON_USERNAME,
23         password => PATRON_PASSWORD,
24         type => 'opac'
25     });
26 ok($script->authtoken, 'Have an authtoken');
27 my $authtoken = $script->authtoken;
28
29 my $loader_mock = Test::MockModule->new('OpenILS::WWW::EGCatLoader');
30 $loader_mock->mock(
31   cgi => sub {
32     my $cgi = CGI->new();
33     $cgi->param('context_org', 1);
34     $cgi->param('redirect_to', '/');
35     return $cgi;},
36 );
37
38 my $email_mock = Test::MockModule->new('Email::Send');
39 $email_mock->mock(
40   send => sub {}
41 );
42
43 my $ctx = {
44   'authtoken' => $authtoken,
45   'page_args' => [254],
46   'get_aou' => sub {
47     my $ou = Fieldmapper::actor::org_unit->new;
48     $ou->id(1);
49     return $ou;}
50 };
51
52 my $loader = new OpenILS::WWW::EGCatLoader(1, $ctx);
53
54 my $preview_response = $loader->load_print_or_email_preview('email');
55 is $preview_response, Apache2::Const::OK, 'Email preview delivers a good response';
56
57 my $event_id = $loader->ctx->{preview_record}->id();
58
59 unshift @{$loader->ctx->{page_args}}, $event_id;
60
61 my $response = $loader->load_email_record();
62 is $response, Apache2::Const::OK, 'Email record from OPAC delivers a good response';
63
64 1;