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

(-)a/t/db_dependent/Template/Plugin/AuthorisedValues.t (-12 / +22 lines)
Lines 73-79 subtest 'GetByCode' => sub { Link Here
73
73
74
subtest 'GetDescriptionByKohaField' => sub {
74
subtest 'GetDescriptionByKohaField' => sub {
75
75
76
    plan tests => 4;
76
    plan tests => 7;
77
77
78
    $schema->storage->txn_begin;
78
    $schema->storage->txn_begin;
79
79
Lines 110-133 subtest 'GetDescriptionByKohaField' => sub { Link Here
110
    );
110
    );
111
    my $av_2 = $builder->build_object(
111
    my $av_2 = $builder->build_object(
112
        {   class => 'Koha::AuthorisedValues',
112
        {   class => 'Koha::AuthorisedValues',
113
            value => { category => $avc->category_name, lib_opac => undef, lib => undef }
113
            value => { category => $avc->category_name, lib_opac => undef, lib => 'lib' }
114
        }
115
    );
116
    my $av_3 = $builder->build_object(
117
        {   class => 'Koha::AuthorisedValues',
118
            value => { category => $avc->category_name, lib_opac =>undef, lib => undef }
114
        }
119
        }
115
    );
120
    );
116
    my $non_existent_av = $av_2->authorised_value;
121
    my $non_existent_av = $av_3->authorised_value;
117
    $av_2->delete;
122
    $av_3->delete;
118
123
119
    my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
124
    my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
120
        { opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
125
        { 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' );
126
    is( $av, 'lib_opac', 'We requested an existing AV description for the OPAC' );
122
123
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
127
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
124
        { kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
128
        { opac => 1, kohafield => 'dummy.field', authorised_value => $av_2->authorised_value } );
125
    is( $av, 'lib', 'We requested an existing AV description, not for the OPAC' );
129
    is( $av, 'lib', 'We requested an OPAC AV description for the OPAC, return a regular description' );
126
130
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
131
        { opac => 1, kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } );
132
    is( $av, $av_3->authorised_value, 'We requested an non-existing OPAC AV description for the OPAC, return the authorised_value.' );
127
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
133
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
128
        { opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } );
134
        { 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' );
135
    is( $av, '', 'We requested a non existing AV description for the OPAC, return empty string' );
130
136
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
137
        { kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
138
    is( $av, 'lib', 'We requested an existing AV regular description.' );
139
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
140
        { kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } );
141
    is( $av, $av_3->authorised_value, 'We requested an non-existing AV regular description, return the authorised_value.' );
131
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
142
    $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
132
        { kohafield => 'dummy.field', authorised_value => $non_existent_av } );
143
        { kohafield => 'dummy.field', authorised_value => $non_existent_av } );
133
    is( $av, '',
144
    is( $av, '',
134
- 

Return to bug 21503