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

(-)a/Koha/Patron/Message/Preferences.pm (+35 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patron::Message::Preference;
23
use Koha::Patron::Message::Preference;
24
use Koha::Patron::Message::Transports;
24
25
25
use base qw(Koha::Objects);
26
use base qw(Koha::Objects);
26
27
Lines 34-39 Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas Link Here
34
35
35
=cut
36
=cut
36
37
38
=head3 get_options
39
40
my $messaging_options = Koha::Patron::Message::Preferences->get_options
41
42
Returns an ARRAYref of HASHrefs on available messaging options.
43
44
=cut
45
46
sub get_options {
47
    my ($self) = @_;
48
49
    my $transports = Koha::Patron::Message::Transports->search(undef,
50
        {
51
            join => ['message_attribute'],
52
            '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'],
53
            '+as' => ['message_name', 'takes_days'],
54
        });
55
56
    my $choices;
57
    while (my $transport = $transports->next) {
58
        my $name = $transport->get_column('message_name');
59
        $choices->{$name}->{'message_attribute_id'} = $transport->message_attribute_id;
60
        $choices->{$name}->{'message_name'}         = $name;
61
        $choices->{$name}->{'takes_days'}           = $transport->get_column('takes_days');
62
        $choices->{$name}->{'has_digest'}           = 1 if $transport->is_digest;
63
        $choices->{$name}->{'transport_'.$transport->get_column('message_transport_type')} = ' ';
64
    }
65
66
    my @return = values %$choices;
67
    @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
68
69
    return \@return;
70
}
71
37
=head3 type
72
=head3 type
38
73
39
=cut
74
=cut
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-2 / +39 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 110-115 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
110
    $schema->storage->txn_rollback;
110
    $schema->storage->txn_rollback;
111
};
111
};
112
112
113
subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub {
114
    plan tests => 2;
115
116
    subtest 'Test method availability and return value' => sub {
117
        plan tests => 3;
118
119
        ok(Koha::Patron::Message::Preferences->can('get_options'),
120
            'Method get_options is available.');
121
        ok(my $options = Koha::Patron::Message::Preferences->get_options,
122
            'Called get_options successfully.');
123
        is(ref($options), 'ARRAY', 'get_options returns a ARRAYref');
124
    };
125
126
    subtest 'Make sure options are correct' => sub {
127
        $schema->storage->txn_begin;
128
        my $options = Koha::Patron::Message::Preferences->get_options;
129
130
        foreach my $option (@$options) {
131
            my $n = $option->{'message_name'};
132
            my $attr = Koha::Patron::Message::Attributes->find($option->{'message_attribute_id'});
133
            is($option->{'message_attribute_id'}, $attr->message_attribute_id,
134
               '$n: message_attribute_id is set');
135
            is($option->{'message_name'}, $attr->message_name, '$n: message_name is set');
136
            is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set');
137
            my $transports = Koha::Patron::Message::Transports->search({
138
                message_attribute_id => $option->{'message_attribute_id'},
139
                is_digest => $option->{'has_digest'} || 0,
140
            });
141
            while (my $trnzport = $transports->next) {
142
                is($option->{'has_digest'} || 0, $trnzport->is_digest, '$n: has_digest is set for '.$trnzport->message_transport_type);
143
                is($option->{'transport_'.$trnzport->message_transport_type}, ' ', '$n: transport_'.$trnzport->message_transport_type.' is set');
144
            }
145
        }
146
147
        $schema->storage->txn_rollback;
148
    };
149
};
150
113
subtest 'Test adding a new preference with invalid parameters' => sub {
151
subtest 'Test adding a new preference with invalid parameters' => sub {
114
    plan tests => 4;
152
    plan tests => 4;
115
153
116
- 

Return to bug 17499