Bugzilla – Attachment 63805 Details for
Bug 17499
Koha objects for messaging preferences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17499: Add a method for getting messaging options
Bug-17499-Add-a-method-for-getting-messaging-optio.patch (text/plain), 4.77 KB, created by
Marc Véron
on 2017-05-29 12:30:49 UTC
(
hide
)
Description:
Bug 17499: Add a method for getting messaging options
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2017-05-29 12:30:49 UTC
Size:
4.77 KB
patch
obsolete
>From 2a1f7f0dd08386d8425a4f9fa403ead5a2047f2a Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Thu, 27 Oct 2016 14:24:34 +0300 >Subject: [PATCH] Bug 17499: Add a method for getting messaging options >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds a method for getting available messaging options. > >To test: >1. Run t/db_dependent/Koha/Patron/Message/Preferences.t > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > Koha/Patron/Message/Preferences.pm | 35 +++++++++++++++++++++ > t/db_dependent/Koha/Patron/Message/Preferences.t | 40 +++++++++++++++++++++++- > 2 files changed, 74 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron/Message/Preferences.pm b/Koha/Patron/Message/Preferences.pm >index 4639a6b..bf3d14c 100644 >--- a/Koha/Patron/Message/Preferences.pm >+++ b/Koha/Patron/Message/Preferences.pm >@@ -21,6 +21,7 @@ use Modern::Perl; > > use Koha::Database; > use Koha::Patron::Message::Preference; >+use Koha::Patron::Message::Transports; > > use base qw(Koha::Objects); > >@@ -34,6 +35,40 @@ Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas > > =cut > >+=head3 get_options >+ >+my $messaging_options = Koha::Patron::Message::Preferences->get_options >+ >+Returns an ARRAYref of HASHrefs on available messaging options. >+ >+=cut >+ >+sub get_options { >+ my ($self) = @_; >+ >+ my $transports = Koha::Patron::Message::Transports->search(undef, >+ { >+ join => ['message_attribute'], >+ '+select' => ['message_attribute.message_name', 'message_attribute.takes_days'], >+ '+as' => ['message_name', 'takes_days'], >+ }); >+ >+ my $choices; >+ while (my $transport = $transports->next) { >+ my $name = $transport->get_column('message_name'); >+ $choices->{$name}->{'message_attribute_id'} = $transport->message_attribute_id; >+ $choices->{$name}->{'message_name'} = $name; >+ $choices->{$name}->{'takes_days'} = $transport->get_column('takes_days'); >+ $choices->{$name}->{'has_digest'} = 1 if $transport->is_digest; >+ $choices->{$name}->{'transport_'.$transport->get_column('message_transport_type')} = ' '; >+ } >+ >+ my @return = values %$choices; >+ @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return; >+ >+ return \@return; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Patron/Message/Preferences.t b/t/db_dependent/Koha/Patron/Message/Preferences.t >index 7fa3688..2f20039 100644 >--- a/t/db_dependent/Koha/Patron/Message/Preferences.t >+++ b/t/db_dependent/Koha/Patron/Message/Preferences.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 3; >+use Test::More tests => 4; > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -110,6 +110,44 @@ subtest 'Test Koha::Patron::Message::Preferences' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub { >+ plan tests => 2; >+ >+ subtest 'Test method availability and return value' => sub { >+ plan tests => 3; >+ >+ ok(Koha::Patron::Message::Preferences->can('get_options'), >+ 'Method get_options is available.'); >+ ok(my $options = Koha::Patron::Message::Preferences->get_options, >+ 'Called get_options successfully.'); >+ is(ref($options), 'ARRAY', 'get_options returns a ARRAYref'); >+ }; >+ >+ subtest 'Make sure options are correct' => sub { >+ $schema->storage->txn_begin; >+ my $options = Koha::Patron::Message::Preferences->get_options; >+ >+ foreach my $option (@$options) { >+ my $n = $option->{'message_name'}; >+ my $attr = Koha::Patron::Message::Attributes->find($option->{'message_attribute_id'}); >+ is($option->{'message_attribute_id'}, $attr->message_attribute_id, >+ '$n: message_attribute_id is set'); >+ is($option->{'message_name'}, $attr->message_name, '$n: message_name is set'); >+ is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set'); >+ my $transports = Koha::Patron::Message::Transports->search({ >+ message_attribute_id => $option->{'message_attribute_id'}, >+ is_digest => $option->{'has_digest'} || 0, >+ }); >+ while (my $trnzport = $transports->next) { >+ is($option->{'has_digest'} || 0, $trnzport->is_digest, '$n: has_digest is set for '.$trnzport->message_transport_type); >+ is($option->{'transport_'.$trnzport->message_transport_type}, ' ', '$n: transport_'.$trnzport->message_transport_type.' is set'); >+ } >+ } >+ >+ $schema->storage->txn_rollback; >+ }; >+}; >+ > subtest 'Test adding a new preference with invalid parameters' => sub { > plan tests => 4; > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17499
:
63427
|
63428
|
63429
|
63430
|
63431
|
63432
|
63433
|
63434
|
63786
|
63787
|
63788
|
63789
|
63790
|
63791
|
63792
|
63793
|
63801
|
63802
|
63803
|
63804
|
63805
|
63806
|
63807
|
63808
|
63809
|
63810
|
63811
|
63812
|
63878
|
63895
|
64035
|
64036
|
64037
|
64038
|
64039
|
64040
|
64041
|
64042
|
64043
|
64044
|
64795
|
66686
|
69434
|
69435
|
69458
|
91864
|
93863
|
93865
|
93872
|
94748
|
99479
|
99634
|
99668
|
99669
|
99670
|
103441
|
103442
|
103443
|
106653
|
106654
|
106655
|
106656
|
106657
|
107612
|
107613
|
107614
|
107615
|
107616
|
113010
|
113011
|
113127
|
113129
|
113686
|
113687
|
113765
|
113766
|
113767
|
113768
|
118452
|
118453
|
119470
|
119471
|
119472
|
119473
|
119474
|
119475
|
119476
|
119477
|
119478
|
119479
|
119480
|
119481
|
119482
|
119483
|
119484
|
119485
|
119486
|
119487
|
119488
|
119489
|
119490
|
119491
|
141408
|
141409
|
141410
|
141411
|
141412
|
141413
|
141414
|
141415
|
141416
|
141417
|
141418
|
146529
|
146530
|
146531
|
146532
|
146533
|
146534
|
146535
|
146536
|
146537
|
146538
|
146539
|
146540
|
151900
|
151901
|
151902
|
151903
|
151904
|
151905
|
151906
|
151907
|
151908
|
151909
|
151910
|
151911
|
151937
|
151938
|
151939
|
151940
|
151941
|
151942
|
151943
|
151944
|
151945
|
151946
|
151947
|
151948
|
155365
|
155366
|
155367
|
155368
|
155369
|
155370
|
155371
|
155372
|
155373
|
155374
|
155375
|
155376