|
Lines 6-26
use Template;
Link Here
|
| 6 |
|
6 |
|
| 7 |
use Test::More tests => 1; |
7 |
use Test::More tests => 1; |
| 8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
|
|
9 |
|
| 9 |
#use Test::NoWarnings; |
10 |
#use Test::NoWarnings; |
|
|
11 |
use t::lib::TestBuilder; |
| 12 |
use t::lib::Mocks; |
| 10 |
|
13 |
|
| 11 |
use C4::Form::MessagingPreferences; |
14 |
use C4::Form::MessagingPreferences; |
| 12 |
|
15 |
|
| 13 |
subtest 'restore_values' => sub { |
16 |
my $builder = t::lib::TestBuilder->new; |
| 14 |
plan tests => 1; |
17 |
my $schema = Koha::Database->new->schema; |
| 15 |
my $cgi = CGI->new; |
18 |
|
| 16 |
my $template_module = Test::MockModule->new( 'Template' ); |
19 |
subtest 'restore_form_values' => sub { |
| 17 |
my $vars = {}; |
20 |
|
|
|
21 |
plan tests => 2; |
| 22 |
|
| 23 |
my $cgi = CGI->new; |
| 24 |
my $template_module = Test::MockModule->new('Template'); |
| 25 |
my $vars = {}; |
| 18 |
$template_module->mock( 'param', sub { my ( $self, $key, $val ) = @_; $vars->{$key} = $val; } ); |
26 |
$template_module->mock( 'param', sub { my ( $self, $key, $val ) = @_; $vars->{$key} = $val; } ); |
| 19 |
my $template = Template->new( ENCODING => 'UTF-8' ); |
27 |
my $template = Template->new( ENCODING => 'UTF-8' ); |
| 20 |
|
28 |
|
|
|
29 |
$schema->storage->txn_begin; |
| 30 |
|
| 31 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 32 |
t::lib::Mocks::mock_preference( 'EnhancedMessagingPreferences', 1 ); |
| 33 |
|
| 34 |
C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $patron->id }, $template ); |
| 35 |
my $set_form_values_vars = { %$vars }; |
| 36 |
$vars = {}; |
| 37 |
|
| 21 |
C4::Form::MessagingPreferences::restore_form_values( $cgi, $template ); |
38 |
C4::Form::MessagingPreferences::restore_form_values( $cgi, $template ); |
| 22 |
require Data::Dumper; warn Data::Dumper::Dumper( $vars ); #FIXME Remove debugging |
39 |
my $restore_form_values_vars = { %$vars }; |
| 23 |
# TODO Add some checking on $vars->{messaging_preferences} here |
40 |
|
|
|
41 |
is_deeply( |
| 42 |
$set_form_values_vars, $restore_form_values_vars, |
| 43 |
"Default messaging preferences don't change when handled with restore_form_values." |
| 44 |
); |
| 45 |
|
| 46 |
C4::Members::Messaging::SetMessagingPreference( |
| 47 |
{ |
| 48 |
borrowernumber => $patron->id, |
| 49 |
message_transport_types => ['email'], |
| 50 |
message_attribute_id => 2, |
| 51 |
days_in_advance => 10, |
| 52 |
wants_digest => 1 |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $patron->id }, $template ); |
| 57 |
$set_form_values_vars = { %$vars }; |
| 58 |
$vars = {}; |
| 59 |
|
| 60 |
$cgi->param( -name => '2', -value => 'email' ); |
| 61 |
$cgi->param( -name => '2-DAYS', -value => '10' ); |
| 62 |
$cgi->param( -name => 'digest', -value => '2' ); |
| 63 |
|
| 64 |
C4::Form::MessagingPreferences::restore_form_values( $cgi, $template ); |
| 65 |
$restore_form_values_vars = { %$vars }; |
| 66 |
|
| 67 |
is_deeply( |
| 68 |
$set_form_values_vars, $restore_form_values_vars, |
| 69 |
"Patrons messaging preferences don't change when handled with restore_form_values." |
| 70 |
); |
| 24 |
|
71 |
|
| 25 |
ok(1); # FIXME Replace |
72 |
$schema->storage->txn_rollback; |
| 26 |
}; |
73 |
}; |
| 27 |
- |
|
|