View | Details | Raw Unified | Return to bug 34776
Collapse All | Expand All

(-)a/t/Form_MessagingPreferences.t (-8 / +38 lines)
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;
17
my $schema  = Koha::Database->new->schema;
18
19
subtest 'restore_form_values' => sub {
20
14
    plan tests => 1;
21
    plan tests => 1;
15
    my $cgi = CGI->new;
22
16
    my $template_module = Test::MockModule->new( 'Template' );
23
    my $cgi             = CGI->new;
17
    my $vars = {};
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
    C4::Members::Messaging::SetMessagingPreference(
34
        {
35
            borrowernumber          => $patron->id,
36
            message_transport_types => ['email'],
37
            message_attribute_id    => 2,
38
            days_in_advance         => 10,
39
            wants_digest            => 1
40
        }
41
    );
42
43
    C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $patron->id }, $template );
44
    my $set_form_values_vars = $vars;
45
46
    $cgi->param( -name => '2',      -value => 'email' );
47
    $cgi->param( -name => '2-DAYS', -value => '10' );
48
    $cgi->param( -name => 'digest', -value => '1' );
49
21
    C4::Form::MessagingPreferences::restore_form_values( $cgi, $template );
50
    C4::Form::MessagingPreferences::restore_form_values( $cgi, $template );
22
    require Data::Dumper; warn Data::Dumper::Dumper(  $vars ); #FIXME Remove debugging
51
    is_deeply(
23
    # TODO Add some checking on $vars->{messaging_preferences} here
52
        $set_form_values_vars, $vars,
53
        "Messaging preferences don't change when handled with restore_form_values."
54
    );
24
55
25
    ok(1); # FIXME Replace
56
    $schema->storage->txn_rollback;
26
};
57
};
27
- 

Return to bug 34776