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

(-)a/C4/Koha.pm (-23 lines)
Lines 56-62 BEGIN { Link Here
56
		&getitemtypeimagelocation
56
		&getitemtypeimagelocation
57
		&GetAuthorisedValues
57
		&GetAuthorisedValues
58
		&GetAuthorisedValueCategories
58
		&GetAuthorisedValueCategories
59
                &IsAuthorisedValueCategory
60
		&GetKohaAuthorisedValues
59
		&GetKohaAuthorisedValues
61
		&GetKohaAuthorisedValuesFromField
60
		&GetKohaAuthorisedValuesFromField
62
    &GetKohaAuthorisedValuesMapping
61
    &GetKohaAuthorisedValuesMapping
Lines 1118-1145 sub GetAuthorisedValueCategories { Link Here
1118
    return \@results;
1117
    return \@results;
1119
}
1118
}
1120
1119
1121
=head2 IsAuthorisedValueCategory
1122
1123
    $is_auth_val_category = IsAuthorisedValueCategory($category);
1124
1125
Returns whether a given category name is a valid one
1126
1127
=cut
1128
1129
sub IsAuthorisedValueCategory {
1130
    my $category = shift;
1131
    my $query = '
1132
        SELECT category
1133
        FROM authorised_values
1134
        WHERE category=?
1135
        LIMIT 1
1136
    ';
1137
    my $sth = C4::Context->dbh->prepare($query);
1138
    $sth->execute($category);
1139
    $sth->fetchrow ? return 1
1140
                   : return 0;
1141
}
1142
1143
=head2 GetAuthorisedValueByCode
1120
=head2 GetAuthorisedValueByCode
1144
1121
1145
$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
1122
$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 932-938 sub IsAuthorisedValueValid { Link Here
932
    my $reserved_authorised_values = GetReservedAuthorisedValues();
934
    my $reserved_authorised_values = GetReservedAuthorisedValues();
933
935
934
    if ( exists $reserved_authorised_values->{$authorised_value} ||
936
    if ( exists $reserved_authorised_values->{$authorised_value} ||
935
         C4::Koha::IsAuthorisedValueCategory($authorised_value)   ) {
937
         Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
936
        return 1;
938
        return 1;
937
    }
939
    }
938
940
(-)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 (-17 / +5 lines)
Lines 25-31 use Module::Load::Conditional qw/check_install/; Link Here
25
25
26
BEGIN {
26
BEGIN {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
28
        plan tests => 34;
28
        plan tests => 31;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 38-52 use Test::DBIx::Class { Link Here
38
    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
38
    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
39
    connect_opts => { name_sep => '.', quote_char => '`', },
39
    connect_opts => { name_sep => '.', quote_char => '`', },
40
    fixture_class => '::Populate',
40
    fixture_class => '::Populate',
41
}, 'AuthorisedValue', 'Branch' ;
41
}, 'Branch' ;
42
42
43
sub fixtures {
43
sub fixtures {
44
    my ( $av, $libraries ) = @_;
44
    my ( $libraries ) = @_;
45
    fixtures_ok [
45
    fixtures_ok [
46
        AuthorisedValue => [
47
            [ 'category', 'authorised_value' ],
48
            @$av,
49
        ],
50
        Branch => [
46
        Branch => [
51
            ['branchcode', 'branchname'],
47
            ['branchcode', 'branchname'],
52
            @$libraries,
48
            @$libraries,
Lines 57-74 sub fixtures { Link Here
57
my $db = Test::MockModule->new('Koha::Database');
53
my $db = Test::MockModule->new('Koha::Database');
58
$db->mock( _new_schema => sub { return Schema(); } );
54
$db->mock( _new_schema => sub { return Schema(); } );
59
55
60
my $authorised_values = [
61
    ['LOC', 'LOC'],
62
    ['RELTERMS', 'RELTERMS'],
63
];
64
my $libraries = [
56
my $libraries = [
65
    ['XXX_test', 'my branchname XXX'],
57
    ['XXX_test', 'my branchname XXX'],
66
];
58
];
67
fixtures($authorised_values, $libraries);
59
fixtures($libraries);
68
69
is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
70
is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
71
is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
72
60
73
my $isbn13 = "9780330356473";
61
my $isbn13 = "9780330356473";
74
my $isbn13D = "978-0-330-35647-3";
62
my $isbn13D = "978-0-330-35647-3";
Lines 139-145 subtest 'getFacets() tests' => sub { Link Here
139
        ['YYY_test', 'my branchname YYY'],
127
        ['YYY_test', 'my branchname YYY'],
140
        ['ZZZ_test', 'my branchname XXX'],
128
        ['ZZZ_test', 'my branchname XXX'],
141
    ];
129
    ];
142
    fixtures($authorised_values, $libraries);
130
    fixtures($libraries);
143
    is ( Koha::Libraries->search->count, 3, 'There should be only more than 1 library (singleBranchMode off)' );
131
    is ( Koha::Libraries->search->count, 3, 'There should be only more than 1 library (singleBranchMode off)' );
144
132
145
    $facets = C4::Koha::getFacets();
133
    $facets = C4::Koha::getFacets();
(-)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