Bugzilla – Attachment 48023 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), 6.94 KB, created by
Kyle M Hall (khall)
on 2016-02-12 19:33:54 UTC
(
hide
)
Description:
Bug 15800: Koha::AuthorisedValues - Remove C4::Koha::IsAuthorisedValueCategory
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-02-12 19:33:54 UTC
Size:
6.94 KB
patch
obsolete
>From cf53ff29f3f4e3456859d8e8171193f749094e12 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 | 42 +----------------------------------------- > t/db_dependent/ReportsGuided.t | 27 +++++---------------------- > 5 files changed, 12 insertions(+), 89 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index e1f8b4f..71685c7 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -58,7 +58,6 @@ BEGIN { > &getitemtypeimagelocation > &GetAuthorisedValues > &GetAuthorisedValueCategories >- &IsAuthorisedValueCategory > &GetKohaAuthorisedValues > &GetKohaAuthorisedValuesFromField > &GetKohaAuthorisedValuesMapping >@@ -1225,28 +1224,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 37eaf98..4eab7ba 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; >@@ -997,7 +999,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 8701085..68448ab 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 366a21b..1f14f75 100755 >--- a/t/Koha.t >+++ b/t/Koha.t >@@ -18,51 +18,11 @@ > use Modern::Perl; > > use C4::Context; >-use Test::More; >+use Test::More tests => 29; > use Test::MockModule; > >-use Module::Load::Conditional qw/check_install/; >- >-BEGIN { >- if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 33; >- } else { >- plan skip_all => "Need Test::DBIx::Class" >- } >-} >- > use_ok('C4::Koha'); > >-use Test::DBIx::Class { >- schema_class => 'Koha::Schema', >- connect_info => ['dbi:SQLite:dbname=:memory:','',''], >- connect_opts => { name_sep => '.', quote_char => '`', }, >- fixture_class => '::Populate', >-}, 'AuthorisedValue' ; >- >-sub fixtures { >- my ( $data ) = @_; >- fixtures_ok [ >- AuthorisedValue => [ >- [ 'category', 'authorised_value' ], >- @$data, >- ], >- ], 'add fixtures'; >-} >- >-my $db = Test::MockModule->new('Koha::Database'); >-$db->mock( _new_schema => sub { return Schema(); } ); >- >-my $authorised_values = [ >- ['LOC', 'LOC'], >- ['RELTERMS', 'RELTERMS'], >-]; >-fixtures($authorised_values); >- >-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'); >- > my $isbn13 = "9780330356473"; > my $isbn13D = "978-0-330-35647-3"; > my $isbn10 = "033035647X"; >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.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 15800
:
47899
|
47926
|
48023
|
48443