View | Details | Raw Unified | Return to bug 15783
Collapse All | Expand All

(-)a/C4/Koha.pm (-21 lines)
Lines 67-73 BEGIN { Link Here
67
    &GetAuthorisedValueByCode
67
    &GetAuthorisedValueByCode
68
    &GetKohaImageurlFromAuthorisedValues
68
    &GetKohaImageurlFromAuthorisedValues
69
		&GetAuthValCode
69
		&GetAuthValCode
70
        &AddAuthorisedValue
71
		&GetNormalizedUPC
70
		&GetNormalizedUPC
72
		&GetNormalizedISBN
71
		&GetNormalizedISBN
73
		&GetNormalizedEAN
72
		&GetNormalizedEAN
Lines 1432-1457 sub GetKohaAuthorisedValueLib { Link Here
1432
  return $value;
1431
  return $value;
1433
}
1432
}
1434
1433
1435
=head2 AddAuthorisedValue
1436
1437
    AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl);
1438
1439
Create a new authorised value.
1440
1441
=cut
1442
1443
sub AddAuthorisedValue {
1444
    my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_;
1445
1446
    my $dbh = C4::Context->dbh;
1447
    my $query = qq{
1448
        INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl)
1449
        VALUES (?,?,?,?,?)
1450
    };
1451
    my $sth = $dbh->prepare($query);
1452
    $sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl);
1453
}
1454
1455
=head2 display_marc_indicators
1434
=head2 display_marc_indicators
1456
1435
1457
  my $display_form = C4::Koha::display_marc_indicators($field);
1436
  my $display_form = C4::Koha::display_marc_indicators($field);
(-)a/t/db_dependent/Koha.t (-10 / +49 lines)
Lines 3-12 Link Here
3
# This is to test C4/Koha
3
# This is to test C4/Koha
4
# It requires a working Koha database with the sample data
4
# It requires a working Koha database with the sample data
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
8
use C4::Context;
7
use C4::Context;
9
use Koha::DateUtils qw(dt_from_string);
8
use Koha::DateUtils qw(dt_from_string);
9
use Koha::AuthorisedValue;
10
10
11
use Test::More tests => 10;
11
use Test::More tests => 10;
12
use DateTime::Format::MySQL;
12
use DateTime::Format::MySQL;
Lines 33-40 subtest 'Authorized Values Tests' => sub { Link Here
33
33
34
34
35
# Insert an entry into authorised_value table
35
# Insert an entry into authorised_value table
36
    my $insert_success = AddAuthorisedValue($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
36
    my $insert_success = Koha::AuthorisedValue->new(
37
    ok($insert_success, "Insert data in database");
37
        {   category         => $data->{category},
38
            authorised_value => $data->{authorised_value},
39
            lib              => $data->{lib},
40
            lib_opac         => $data->{lib_opac},
41
            imageurl         => $data->{imageurl}
42
        }
43
    )->store;
44
    ok( $insert_success, "Insert data in database" );
38
45
39
46
40
# Tests
47
# Tests
Lines 64-74 subtest 'Authorized Values Tests' => sub { Link Here
64
    SKIP: {
71
    SKIP: {
65
        eval { require Test::Deep; import Test::Deep; };
72
        eval { require Test::Deep; import Test::Deep; };
66
        skip "Test::Deep required to run the GetAuthorisedValues() tests.", 2 if $@;
73
        skip "Test::Deep required to run the GetAuthorisedValues() tests.", 2 if $@;
67
        AddAuthorisedValue('BUG10656', 'ZZZ', 'Z_STAFF', 'A_PUBLIC', '');
74
        Koha::AuthorisedValue->new(
68
        AddAuthorisedValue('BUG10656', 'AAA', 'A_STAFF', 'Z_PUBLIC', '');
75
            {   category         => 'BUG10656',
76
                authorised_value => 'ZZZ',
77
                lib              => 'Z_STAFF',
78
                lib_opac         => 'A_PUBLIC',
79
                imageurl         => ''
80
            }
81
        )->store;
82
        Koha::AuthorisedValue->new(
83
            {   category         => 'BUG10656',
84
                authorised_value => 'AAA',
85
                lib              => 'A_STAFF',
86
                lib_opac         => 'Z_PUBLIC',
87
                imageurl         => ''
88
            }
89
        )->store;
90
69
        # the next one sets lib_opac to NULL; in that case, the staff
91
        # the next one sets lib_opac to NULL; in that case, the staff
70
        # display value is meant to be used.
92
        # display value is meant to be used.
71
        AddAuthorisedValue('BUG10656', 'DDD', 'D_STAFF', undef, '');
93
        Koha::AuthorisedValue->new(
94
            {   category         => 'BUG10656',
95
                authorised_value => 'DDD',
96
                lib              => 'D_STAFF',
97
                lib_opac         => undef,
98
                imageurl         => ''
99
            }
100
        )->store;
101
72
        my $authvals = GetAuthorisedValues('BUG10656');
102
        my $authvals = GetAuthorisedValues('BUG10656');
73
        cmp_deeply(
103
        cmp_deeply(
74
            $authvals,
104
            $authvals,
Lines 301-307 subtest 'GetFrameworksLoop() tests' => sub { Link Here
301
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
331
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
302
    plan tests => 7;
332
    plan tests => 7;
303
333
304
    my $insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Qwertyware');
334
    my $insertGroup = Koha::AuthorisedValue->new(
335
        {   category         => 'ITEMTYPECAT',
336
            authorised_value => 'Quertyware',
337
        }
338
    )->store;
339
305
    ok($insertGroup, "Create group Qwertyware");
340
    ok($insertGroup, "Create group Qwertyware");
306
341
307
    my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
342
    my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
Lines 319-325 subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ Link Here
319
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
354
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
320
355
321
    # add more data since GetItemTypesCategorized's search is more subtle
356
    # add more data since GetItemTypesCategorized's search is more subtle
322
    $insertGroup = AddAuthorisedValue('ITEMTYPECAT', 'Veryheavybook');
357
    $insertGroup = Koha::AuthorisedValue->new(
358
        {   category         => 'ITEMTYPECAT',
359
            authorised_value => 'Varyheavybook',
360
        }
361
    )->store;
362
323
    $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryheavybook', 1);
363
    $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryheavybook', 1);
324
364
325
    my $hrCat = GetItemTypesCategorized();
365
    my $hrCat = GetItemTypesCategorized();
326
- 

Return to bug 15783