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

(-)a/t/db_dependent/Template/Plugin/AuthorisedValues.t (-3 / +73 lines)
Lines 16-36 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 1;
19
use Test::More tests => 2;
20
20
21
use C4::Context;
21
use C4::Context;
22
use Koha::Caches;
22
use Koha::Database;
23
use Koha::Database;
24
use Koha::MarcSubfieldStructures;
23
use Koha::Template::Plugin::AuthorisedValues;
25
use Koha::Template::Plugin::AuthorisedValues;
24
26
25
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
26
use t::lib::Mocks;
28
use t::lib::Mocks;
27
29
28
my $schema = Koha::Database->schema;
30
my $schema = Koha::Database->schema;
29
$schema->storage->txn_begin;
30
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
31
32
32
subtest 'GetByCode' => sub {
33
subtest 'GetByCode' => sub {
33
    plan tests => 4;
34
    plan tests => 4;
35
36
    $schema->storage->txn_begin;
37
34
    my $avc =
38
    my $avc =
35
      $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } );
39
      $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } );
36
    my $av_1 = $builder->build_object(
40
    my $av_1 = $builder->build_object(
Lines 63-66 subtest 'GetByCode' => sub { Link Here
63
      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
67
      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
64
        'does_not_exist' );
68
        'does_not_exist' );
65
    is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' );
69
    is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' );
70
71
    $schema->storage->txn_rollback;
72
};
73
74
subtest 'GetDescriptionByKohaField' => sub {
75
76
    plan tests => 4;
77
78
    $schema->storage->txn_begin;
79
80
    my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } );
81
82
    # Create a framework mapping
83
    Koha::MarcSubfieldStructure->new(
84
        {   tagfield         => '988',
85
            tagsubfield      => 'a',
86
            liblibrarian     => 'Dummy field',
87
            libopac          => 'Dummy field',
88
            repeatable       => 0,
89
            mandatory        => 0,
90
            kohafield        => 'dummy.field',
91
            tab              => '9',
92
            authorised_value => $avc->category_name,
93
            authtypecode     => q{},
94
            value_builder    => q{},
95
            isurl            => 0,
96
            hidden           => 0,
97
            frameworkcode    => q{},
98
            seealso          => q{},
99
            link             => q{},
100
            defaultvalue     => undef
101
        }
102
    )->store;
103
104
    # Make sure we are not catch by cache
105
    Koha::Caches->get_instance->flush_all;
106
    my $av_1 = $builder->build_object(
107
        {   class => 'Koha::AuthorisedValues',
108
            value => { category => $avc->category_name, lib_opac => 'lib_opac', lib => 'lib' }
109
        }
110
    );
111
    my $av_2 = $builder->build_object(
112
        {   class => 'Koha::AuthorisedValues',
113
            value => { category => $avc->category_name, lib_opac => undef, lib => undef }
114
        }
115
    );
116
    my $non_existent_av = $av_2->authorised_value;
117
    $av_2->delete;
118
119
    my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
120
        { opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
121
    is( $av, 'lib_opac', 'We requested an existing AV description, for the OPAC' );
122
123
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
124
        { kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
125
    is( $av, 'lib', 'We requested an existing AV description, not for the OPAC' );
126
127
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
128
        { opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } );
129
    is( $av, '', 'We requested a non existing AV description, for the OPAC, return empty string' );
130
131
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
132
        { kohafield => 'dummy.field', authorised_value => $non_existent_av } );
133
    is( $av, '',
134
        'We requested a non existing AV description, not for the OPAC, return empty string' );
135
136
    $schema->storage->txn_rollback;
66
};
137
};
67
- 

Return to bug 21503