Bugzilla – Attachment 48443 Details for
Bug 15800
Koha::AuthorisedValues - Remove C4::Koha::IsAuthorisedValueCategory
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15800: Koha::AuthorisedValues - Remove C4::Koha::IsAuthorisedValueCategory
Bug-15800-KohaAuthorisedValues---Remove-C4KohaIsAu.patch (text/plain), 7.39 KB, created by
Jonathan Druart
on 2016-02-29 11:19:35 UTC
(
hide
)
Description:
Bug 15800: Koha::AuthorisedValues - Remove C4::Koha::IsAuthorisedValueCategory
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-02-29 11:19:35 UTC
Size:
7.39 KB
patch
obsolete
>From 394e48abbdc867bc742c09cbb6c70e28c0c4d992 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 10 Feb 2016 15:37:30 +0000 >Subject: [PATCH] Bug 15800: Koha::AuthorisedValues - Remove > C4::Koha::IsAuthorisedValueCategory > >C4::Koha::IsAuthorisedValueCategory contains only 2 useful calls, from >C4::Reports::Guided and reports/guided_reports.pl >It can be replaced with > Koha::AuthorisedValues->search({ category => $authorised_value})->count > >Test plan: >1/ Create a sql report using an authorised value category, something >like: > SELECT COUNT(*) FROM items where itemlost=<<lost|LOST>> >2/ Execute the report and confirm that everything works fine. >3/ Create a sql report using a nonexistent authorised value categor, >something like: > SELECT COUNT(*) FROM items where itemlost=<<lost|NONEXIST>> >4/ When saving the report, you should get a warning message > "lost: The authorized value category (NONEXIST) you selected does not exist." >5/ Save anyway and execute the report, you should get the same warning >message. > >QA: > git grep IsAuthorisedValueCategory >should not return any results > prove t/db_dependent/ReportsGuided.t >should return green > >Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com> >Works as described > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/Koha.pm | 23 ----------------------- > C4/Reports/Guided.pm | 4 +++- > reports/guided_reports.pl | 5 +++-- > t/Koha.t | 22 +++++----------------- > t/db_dependent/ReportsGuided.t | 27 +++++---------------------- > 5 files changed, 16 insertions(+), 65 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index b637cd4..f334096 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -56,7 +56,6 @@ BEGIN { > &getitemtypeimagelocation > &GetAuthorisedValues > &GetAuthorisedValueCategories >- &IsAuthorisedValueCategory > &GetKohaAuthorisedValues > &GetKohaAuthorisedValuesFromField > &GetKohaAuthorisedValuesMapping >@@ -1118,28 +1117,6 @@ sub GetAuthorisedValueCategories { > return \@results; > } > >-=head2 IsAuthorisedValueCategory >- >- $is_auth_val_category = IsAuthorisedValueCategory($category); >- >-Returns whether a given category name is a valid one >- >-=cut >- >-sub IsAuthorisedValueCategory { >- my $category = shift; >- my $query = ' >- SELECT category >- FROM authorised_values >- WHERE category=? >- LIMIT 1 >- '; >- my $sth = C4::Context->dbh->prepare($query); >- $sth->execute($category); >- $sth->fetchrow ? return 1 >- : return 0; >-} >- > =head2 GetAuthorisedValueByCode > > $authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac ); >diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm >index daf810d..ffc8afd 100644 >--- a/C4/Reports/Guided.pm >+++ b/C4/Reports/Guided.pm >@@ -34,6 +34,8 @@ use C4::Debug; > # use Data::Dumper; > use C4::Log; > >+use Koha::AuthorisedValues; >+ > BEGIN { > # set the version for version checking > $VERSION = 3.07.00.049; >@@ -932,7 +934,7 @@ sub IsAuthorisedValueValid { > my $reserved_authorised_values = GetReservedAuthorisedValues(); > > if ( exists $reserved_authorised_values->{$authorised_value} || >- C4::Koha::IsAuthorisedValueCategory($authorised_value) ) { >+ Koha::AuthorisedValues->search({ category => $authorised_value })->count ) { > return 1; > } > >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index eed8ab9..200260d 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -29,11 +29,12 @@ use C4::Auth qw/:DEFAULT get_session/; > use C4::Output; > use C4::Debug; > use C4::Branch; # XXX subfield_is_koha_internal_p >-use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/; >+use C4::Koha qw/GetFrameworksLoop/; > use C4::Context; > use C4::Log; > use Koha::DateUtils qw/dt_from_string output_pref/; > use Koha::AuthorisedValue; >+use Koha::AuthorisedValues; > > =head1 NAME > >@@ -706,7 +707,7 @@ elsif ($phase eq 'Run this report'){ > #---- "true" authorised value > } > else { >- if ( IsAuthorisedValueCategory($authorised_value) ) { >+ if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) { > my $query = ' > SELECT authorised_value,lib > FROM authorised_values >diff --git a/t/Koha.t b/t/Koha.t >index e887632..21cbf68 100755 >--- a/t/Koha.t >+++ b/t/Koha.t >@@ -25,7 +25,7 @@ use Module::Load::Conditional qw/check_install/; > > BEGIN { > if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 34; >+ plan tests => 31; > } else { > plan skip_all => "Need Test::DBIx::Class" > } >@@ -38,15 +38,11 @@ use Test::DBIx::Class { > connect_info => ['dbi:SQLite:dbname=:memory:','',''], > connect_opts => { name_sep => '.', quote_char => '`', }, > fixture_class => '::Populate', >-}, 'AuthorisedValue', 'Branch' ; >+}, 'Branch' ; > > sub fixtures { >- my ( $av, $libraries ) = @_; >+ my ( $libraries ) = @_; > fixtures_ok [ >- AuthorisedValue => [ >- [ 'category', 'authorised_value' ], >- @$av, >- ], > Branch => [ > ['branchcode', 'branchname'], > @$libraries, >@@ -57,18 +53,10 @@ sub fixtures { > my $db = Test::MockModule->new('Koha::Database'); > $db->mock( _new_schema => sub { return Schema(); } ); > >-my $authorised_values = [ >- ['LOC', 'LOC'], >- ['RELTERMS', 'RELTERMS'], >-]; > my $libraries = [ > ['XXX_test', 'my branchname XXX'], > ]; >-fixtures($authorised_values, $libraries); >- >-is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category'); >-is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category'); >-is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category'); >+fixtures($libraries); > > my $isbn13 = "9780330356473"; > my $isbn13D = "978-0-330-35647-3"; >@@ -139,7 +127,7 @@ subtest 'getFacets() tests' => sub { > ['YYY_test', 'my branchname YYY'], > ['ZZZ_test', 'my branchname XXX'], > ]; >- fixtures($authorised_values, $libraries); >+ fixtures($libraries); > is ( Koha::Libraries->search->count, 3, 'There should be only more than 1 library (singleBranchMode off)' ); > > $facets = C4::Koha::getFacets(); >diff --git a/t/db_dependent/ReportsGuided.t b/t/db_dependent/ReportsGuided.t >index 097722a..40e49a8 100755 >--- a/t/db_dependent/ReportsGuided.t >+++ b/t/db_dependent/ReportsGuided.t >@@ -3,33 +3,16 @@ > use Modern::Perl; > > use Test::More tests => 13; >-use Test::MockModule; > >-use t::lib::Mocks; >+use Koha::Database; > > use_ok('C4::Reports::Guided'); > >-my $context = new Test::MockModule('C4::Context'); >-my $koha = new Test::MockModule('C4::Koha'); >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; > >-BEGIN { >- t::lib::Mocks::mock_dbh; >-} >- >-sub MockedIsAuthorisedValueCategory { >- my $authorised_value = shift; >- >- if ( $authorised_value eq 'LOC' ) { >- return 1; >- } else { >- return 0; >- } >-} >- >-$koha->mock( >- 'IsAuthorisedValueCategory', >- \&MockedIsAuthorisedValueCategory >-); >+$_->delete for Koha::AuthorisedValues->search({ category => 'XXX' }); >+Koha::AuthorisedValue->new({category => 'LOC'})->store; > > { # GetReservedAuthorisedValues tests > # This one will catch new reserved words not added >-- >2.7.0
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 15800
:
47899
|
47926
|
48023
| 48443