Browse Source

Bug 15783: AddAuthorisedValue - Remove the subroutine

Test plan:
  prove t/db_dependent/Koha.t
should return green

  git grep AddAuthorisedValue
should not return any results

Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
new_12478_elasticsearch
Jonathan Druart 8 years ago
committed by Brendan Gallagher
parent
commit
2ea901c641
  1. 21
      C4/Koha.pm
  2. 58
      t/db_dependent/Koha.t

21
C4/Koha.pm

@ -65,7 +65,6 @@ BEGIN {
&GetKohaAuthorisedValueLib
&GetAuthorisedValueByCode
&GetAuthValCode
&AddAuthorisedValue
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
@ -1395,26 +1394,6 @@ sub GetKohaAuthorisedValueLib {
return $value;
}
=head2 AddAuthorisedValue
AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl);
Create a new authorised value.
=cut
sub AddAuthorisedValue {
my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_;
my $dbh = C4::Context->dbh;
my $query = qq{
INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl)
VALUES (?,?,?,?,?)
};
my $sth = $dbh->prepare($query);
$sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl);
}
=head2 display_marc_indicators
my $display_form = C4::Koha::display_marc_indicators($field);

58
t/db_dependent/Koha.t

@ -3,10 +3,10 @@
# This is to test C4/Koha
# It requires a working Koha database with the sample data
use strict;
use warnings;
use Modern::Perl;
use C4::Context;
use Koha::DateUtils qw(dt_from_string);
use Koha::AuthorisedValue;
use Test::More tests => 10;
use DateTime::Format::MySQL;
@ -33,8 +33,15 @@ subtest 'Authorized Values Tests' => sub {
# Insert an entry into authorised_value table
my $insert_success = AddAuthorisedValue($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
ok($insert_success, "Insert data in database");
my $insert_success = Koha::AuthorisedValue->new(
{ category => $data->{category},
authorised_value => $data->{authorised_value},
lib => $data->{lib},
lib_opac => $data->{lib_opac},
imageurl => $data->{imageurl}
}
)->store;
ok( $insert_success, "Insert data in database" );
# Tests
@ -63,11 +70,34 @@ subtest 'Authorized Values Tests' => sub {
SKIP: {
eval { require Test::Deep; import Test::Deep; };
skip "Test::Deep required to run the GetAuthorisedValues() tests.", 2 if $@;
AddAuthorisedValue('BUG10656', 'ZZZ', 'Z_STAFF', 'A_PUBLIC', '');
AddAuthorisedValue('BUG10656', 'AAA', 'A_STAFF', 'Z_PUBLIC', '');
Koha::AuthorisedValue->new(
{ category => 'BUG10656',
authorised_value => 'ZZZ',
lib => 'Z_STAFF',
lib_opac => 'A_PUBLIC',
imageurl => ''
}
)->store;
Koha::AuthorisedValue->new(
{ category => 'BUG10656',
authorised_value => 'AAA',
lib => 'A_STAFF',
lib_opac => 'Z_PUBLIC',
imageurl => ''
}
)->store;
# the next one sets lib_opac to NULL; in that case, the staff
# display value is meant to be used.
AddAuthorisedValue('BUG10656', 'DDD', 'D_STAFF', undef, '');
Koha::AuthorisedValue->new(
{ category => 'BUG10656',
authorised_value => 'DDD',
lib => 'D_STAFF',
lib_opac => undef,
imageurl => ''
}
)->store;
my $authvals = GetAuthorisedValues('BUG10656');
cmp_deeply(
$authvals,
@ -300,7 +330,12 @@ subtest 'GetFrameworksLoop() tests' => sub {
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
plan tests => 7;
my $insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Qwertyware');
my $insertGroup = Koha::AuthorisedValue->new(
{ category => 'ITEMTYPECAT',
authorised_value => 'Quertyware',
}
)->store;
ok($insertGroup, "Create group Qwertyware");
my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
@ -318,7 +353,12 @@ subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
# add more data since GetItemTypesCategorized's search is more subtle
$insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Veryheavybook');
$insertGroup = Koha::AuthorisedValue->new(
{ category => 'ITEMTYPECAT',
authorised_value => 'Varyheavybook',
}
)->store;
$insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryheavybook', 1);
my $hrCat = GetItemTypesCategorized();

Loading…
Cancel
Save