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

(-)a/C4/Koha.pm (-23 lines)
Lines 58-64 BEGIN { Link Here
58
		&getitemtypeimagelocation
58
		&getitemtypeimagelocation
59
		&GetAuthorisedValues
59
		&GetAuthorisedValues
60
		&GetAuthorisedValueCategories
60
		&GetAuthorisedValueCategories
61
                &IsAuthorisedValueCategory
62
		&GetKohaAuthorisedValues
61
		&GetKohaAuthorisedValues
63
		&GetKohaAuthorisedValuesFromField
62
		&GetKohaAuthorisedValuesFromField
64
    &GetKohaAuthorisedValuesMapping
63
    &GetKohaAuthorisedValuesMapping
Lines 1225-1252 sub GetAuthorisedValueCategories { Link Here
1225
    return \@results;
1224
    return \@results;
1226
}
1225
}
1227
1226
1228
=head2 IsAuthorisedValueCategory
1229
1230
    $is_auth_val_category = IsAuthorisedValueCategory($category);
1231
1232
Returns whether a given category name is a valid one
1233
1234
=cut
1235
1236
sub IsAuthorisedValueCategory {
1237
    my $category = shift;
1238
    my $query = '
1239
        SELECT category
1240
        FROM authorised_values
1241
        WHERE category=?
1242
        LIMIT 1
1243
    ';
1244
    my $sth = C4::Context->dbh->prepare($query);
1245
    $sth->execute($category);
1246
    $sth->fetchrow ? return 1
1247
                   : return 0;
1248
}
1249
1250
=head2 GetAuthorisedValueByCode
1227
=head2 GetAuthorisedValueByCode
1251
1228
1252
$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
1229
$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
(-)a/C4/Reports/Guided.pm (-1 / +3 lines)
Lines 34-39 use C4::Debug; Link Here
34
# use Data::Dumper;
34
# use Data::Dumper;
35
use C4::Log;
35
use C4::Log;
36
36
37
use Koha::AuthorisedValues;
38
37
BEGIN {
39
BEGIN {
38
    # set the version for version checking
40
    # set the version for version checking
39
    $VERSION = 3.07.00.049;
41
    $VERSION = 3.07.00.049;
Lines 997-1003 sub IsAuthorisedValueValid { Link Here
997
    my $reserved_authorised_values = GetReservedAuthorisedValues();
999
    my $reserved_authorised_values = GetReservedAuthorisedValues();
998
1000
999
    if ( exists $reserved_authorised_values->{$authorised_value} ||
1001
    if ( exists $reserved_authorised_values->{$authorised_value} ||
1000
         C4::Koha::IsAuthorisedValueCategory($authorised_value)   ) {
1002
         Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
1001
        return 1;
1003
        return 1;
1002
    }
1004
    }
1003
1005
(-)a/reports/guided_reports.pl (-2 / +3 lines)
Lines 29-39 use C4::Auth qw/:DEFAULT get_session/; Link Here
29
use C4::Output;
29
use C4::Output;
30
use C4::Debug;
30
use C4::Debug;
31
use C4::Branch; # XXX subfield_is_koha_internal_p
31
use C4::Branch; # XXX subfield_is_koha_internal_p
32
use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/;
32
use C4::Koha qw/GetFrameworksLoop/;
33
use C4::Context;
33
use C4::Context;
34
use C4::Log;
34
use C4::Log;
35
use Koha::DateUtils qw/dt_from_string output_pref/;
35
use Koha::DateUtils qw/dt_from_string output_pref/;
36
use Koha::AuthorisedValue;
36
use Koha::AuthorisedValue;
37
use Koha::AuthorisedValues;
37
38
38
=head1 NAME
39
=head1 NAME
39
40
Lines 706-712 elsif ($phase eq 'Run this report'){ Link Here
706
                        #---- "true" authorised value
707
                        #---- "true" authorised value
707
                    }
708
                    }
708
                    else {
709
                    else {
709
                        if ( IsAuthorisedValueCategory($authorised_value) ) {
710
                        if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
710
                            my $query = '
711
                            my $query = '
711
                            SELECT authorised_value,lib
712
                            SELECT authorised_value,lib
712
                            FROM authorised_values
713
                            FROM authorised_values
(-)a/t/Koha.t (-41 / +1 lines)
Lines 18-68 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Context;
20
use C4::Context;
21
use Test::More;
21
use Test::More tests => 29;
22
use Test::MockModule;
22
use Test::MockModule;
23
23
24
use Module::Load::Conditional qw/check_install/;
25
26
BEGIN {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
28
        plan tests => 33;
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
32
}
33
34
use_ok('C4::Koha');
24
use_ok('C4::Koha');
35
25
36
use Test::DBIx::Class {
37
    schema_class => 'Koha::Schema',
38
    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
39
    connect_opts => { name_sep => '.', quote_char => '`', },
40
    fixture_class => '::Populate',
41
}, 'AuthorisedValue' ;
42
43
sub fixtures {
44
    my ( $data ) = @_;
45
    fixtures_ok [
46
        AuthorisedValue => [
47
            [ 'category', 'authorised_value' ],
48
            @$data,
49
        ],
50
    ], 'add fixtures';
51
}
52
53
my $db = Test::MockModule->new('Koha::Database');
54
$db->mock( _new_schema => sub { return Schema(); } );
55
56
my $authorised_values = [
57
    ['LOC', 'LOC'],
58
    ['RELTERMS', 'RELTERMS'],
59
];
60
fixtures($authorised_values);
61
62
is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
63
is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
64
is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
65
66
my $isbn13 = "9780330356473";
26
my $isbn13 = "9780330356473";
67
my $isbn13D = "978-0-330-35647-3";
27
my $isbn13D = "978-0-330-35647-3";
68
my $isbn10 = "033035647X";
28
my $isbn10 = "033035647X";
(-)a/t/db_dependent/ReportsGuided.t (-23 / +5 lines)
Lines 3-35 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 13;
5
use Test::More tests => 13;
6
use Test::MockModule;
7
6
8
use t::lib::Mocks;
7
use Koha::Database;
9
8
10
use_ok('C4::Reports::Guided');
9
use_ok('C4::Reports::Guided');
11
10
12
my $context = new Test::MockModule('C4::Context');
11
my $schema = Koha::Database->new->schema;
13
my $koha = new Test::MockModule('C4::Koha');
12
$schema->storage->txn_begin;
14
13
15
BEGIN {
14
$_->delete for Koha::AuthorisedValues->search({ category => 'XXX' });
16
    t::lib::Mocks::mock_dbh;
15
Koha::AuthorisedValue->new({category => 'LOC'})->store;
17
}
18
19
sub MockedIsAuthorisedValueCategory {
20
    my $authorised_value = shift;
21
22
    if ( $authorised_value eq 'LOC' ) {
23
        return 1;
24
    } else {
25
        return 0;
26
    }
27
}
28
29
$koha->mock(
30
    'IsAuthorisedValueCategory',
31
    \&MockedIsAuthorisedValueCategory
32
);
33
16
34
{   # GetReservedAuthorisedValues tests
17
{   # GetReservedAuthorisedValues tests
35
    # This one will catch new reserved words not added
18
    # This one will catch new reserved words not added
36
- 

Return to bug 15800