Bugzilla – Attachment 124921 Details for
Bug 29033
Add C4::Context->multivalue_preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29033: Add C4::Context->multivalue_preference
Bug-29033-Add-C4Context-multivaluepreference.patch (text/plain), 2.37 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-09-16 12:01:13 UTC
(
hide
)
Description:
Bug 29033: Add C4::Context->multivalue_preference
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-09-16 12:01:13 UTC
Size:
2.37 KB
patch
obsolete
>From 391f31b224a058d5f3395cdaa1fb67b0fe7f447b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 15 Sep 2021 15:56:59 -0300 >Subject: [PATCH] Bug 29033: Add C4::Context->multivalue_preference > >I've seen several places in which a syspref is retrieved and then >splitted using split and the fact they are pipe-separated strings. > >It seems it would be simple (and handy) to add a method to do that. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/Context.t >=> SUCCESS: Tests pass, a pipe-separated syspref is correctly retrieved >as an arrayref. >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Context.pm | 16 ++++++++++++++++ > t/Context.t | 16 +++++++++++++++- > 2 files changed, 31 insertions(+), 1 deletion(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 241589e7b5..74b55114ec 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -350,6 +350,22 @@ sub yaml_preference { > return $yaml; > } > >+=head2 multivalue_preference >+ >+Retrieves the required system preference value, and splits it >+into pieces using the I<pipe> (|) symbol as separator. >+ >+=cut >+ >+sub multivalue_preference { >+ my ( $self, $preference ) = @_; >+ >+ my $syspref = $self->preference($preference) // q{}; >+ my $values = [ split qr{\|}, $syspref ]; >+ >+ return $values; >+} >+ > =head2 enable_syspref_cache > > C4::Context->enable_syspref_cache(); >diff --git a/t/Context.t b/t/Context.t >index 156ae778bb..e2cc96ede7 100755 >--- a/t/Context.t >+++ b/t/Context.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use DBI; >-use Test::More tests => 31; >+use Test::More tests => 32; > use Test::MockModule; > use Test::Warn; > use YAML::XS; >@@ -52,6 +52,20 @@ subtest 'yaml_preference() tests' => sub { > $context->unmock( 'preference' ); > }; > >+subtest 'multivalue_preference() tests' => sub { >+ >+ plan tests => 3; >+ >+ t::lib::Mocks::mock_preference( 'MultiValuedSyspref', '' ); >+ is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [] ); >+ >+ t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some' ); >+ is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), ['some'] ); >+ >+ t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some|more|values' ); >+ is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), ['some','more','values'] ); >+}; >+ > subtest 'needs_install() tests' => sub { > > plan tests => 2; >-- >2.30.2
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 29033
:
124921
|
125031
|
142291