From caef5bf44d572b8106fca565af3a70d641fa04fe Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Sep 2022 11:56:40 +0000 Subject: [PATCH] Bug 31503: Add $av_cat->values Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/AuthorisedValues.t Signed-off-by: Marcel de Rooy --- Koha/AuthorisedValueCategory.pm | 12 ++++++++++++ t/db_dependent/AuthorisedValues.t | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Koha/AuthorisedValueCategory.pm b/Koha/AuthorisedValueCategory.pm index e14129f80d..749c866500 100644 --- a/Koha/AuthorisedValueCategory.pm +++ b/Koha/AuthorisedValueCategory.pm @@ -47,6 +47,18 @@ sub delete { return $self->SUPER::delete; } +=head3 authorized_values + +Returns values within the category at hand. + +=cut + +sub values { + my ( $self ) = @_; + my $rs = $self->_result->authorised_values; + return map { $_->authorised_value } $rs->all; +} + =head3 type =cut diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index e9f64ed5db..a0ec904af6 100755 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use Try::Tiny; use t::lib::TestBuilder; @@ -254,4 +254,12 @@ subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { }; }; +subtest '$category->values' => sub { + plan tests => 1; + Koha::AuthorisedValueCategory->new( { category_name => 'VALUES_TEST' } )->store; + Koha::AuthorisedValue->new({ category => 'VALUES_TEST', authorised_value => 'test1' })->store; + Koha::AuthorisedValue->new({ category => 'VALUES_TEST', authorised_value => 'test2' })->store; + is_deeply( [ sort Koha::AuthorisedValueCategories->find('VALUES_TEST')->values ], [ 'test1', 'test2' ], 'Expecting two values' ); +}; + $schema->storage->txn_rollback; -- 2.20.1