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

(-)a/C4/XSLT.pm (-14 / +15 lines)
Lines 282-302 sub XSLTParse4Display { Link Here
282
    }
282
    }
283
283
284
    # possibly show analytics link in Detail views
284
    # possibly show analytics link in Detail views
285
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" ) {
285
    my $ShowComponentRecords = C4::Context->preference('ShowComponentRecords');
286
        $biblio //= Koha::Biblios->find( $biblionumber );
286
    if (
287
        (
288
               $xslsyspref eq "OPACXSLTDetailsDisplay"
289
            || $xslsyspref eq "XSLTDetailsDisplay"
290
        )
291
        && (   $ShowComponentRecords ne 'both'
292
            || ( $ShowComponentRecords eq 'staff' && $xslsyspref =~ m/OPAC/ )
293
            || ( $ShowComponentRecords eq 'opac'  && $xslsyspref !~ m/OPAC/ ) )
294
      )
295
    {
296
297
        $biblio //= Koha::Biblios->find($biblionumber);
287
        my $components = $biblio->get_marc_components();
298
        my $components = $biblio->get_marc_components();
288
        $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
299
        $variables->{show_analytics_link} = ( scalar @$components ) ? 0 : 1;
289
300
290
        my $showcomp = C4::Context->preference('ShowComponentRecords');
291
        if (
292
            $variables->{show_analytics_link}
293
            && (   $showcomp eq 'both'
294
                || ( $showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ )
295
                || ( $showcomp eq 'opac'  && $xslsyspref =~ m/OPAC/ ) )
296
          )
297
        {
298
             $variables->{show_analytics_link} = 0;
299
        }
300
    }
301
    }
301
302
302
    my $varxml = "<variables>\n";
303
    my $varxml = "<variables>\n";
(-)a/t/db_dependent/XSLT.t (-2 / +81 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use MARC::Record;
20
use MARC::Record;
21
use Test::More tests => 4;
21
use Test::More tests => 5;
22
use Test::Warn;
22
use Test::Warn;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 213-215 subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { Link Here
213
213
214
    $schema->storage->txn_rollback;
214
    $schema->storage->txn_rollback;
215
};
215
};
216
- 
216
217
subtest 'XSLTParse4Display and show_analytics_link' => sub {
218
    plan tests => 4;
219
220
    $schema->storage->txn_begin;
221
222
    my ($host_bibnum) = C4::Biblio::AddBiblio( host_record(), '' );
223
    t::lib::Mocks::mock_preference( 'SearchEngine',         'Zebra' );
224
225
    my $biblio      = Koha::Biblios->find($host_bibnum);
226
    my $marc_record = $biblio->metadata->record;
227
228
    t::lib::Mocks::mock_preference( 'ShowComponentRecords', 'both' );
229
    my $xml = C4::XSLT::XSLTParse4Display(
230
        {
231
            biblionumber => $host_bibnum,
232
            record       => $marc_record,
233
            xsl_syspref  => 'OPACXSLTDetailsDisplay'
234
        }
235
    );
236
    unlike( $xml, qr{Show analytics}, 'If pref is on and record do not have component, show analytics link is not displayed' );
237
238
    t::lib::Mocks::mock_preference( 'ShowComponentRecords', 'nowhere' );
239
    $xml = C4::XSLT::XSLTParse4Display(
240
        {
241
            biblionumber => $host_bibnum,
242
            record       => $marc_record,
243
            xsl_syspref  => 'OPACXSLTDetailsDisplay'
244
        }
245
    );
246
    like( $xml, qr{Show analytics}, 'If pref is off and record do not have component, show analytics link is displayed' );
247
248
249
    my $search_mod = Test::MockModule->new('Koha::SearchEngine::Zebra::Search');
250
    $search_mod->mock( 'simple_search_compat', \&search_component_record );
251
252
    t::lib::Mocks::mock_preference( 'ShowComponentRecords', 'both' );
253
    $xml = C4::XSLT::XSLTParse4Display(
254
        {
255
            biblionumber => $host_bibnum,
256
            record       => $marc_record,
257
            xsl_syspref  => 'OPACXSLTDetailsDisplay'
258
        }
259
    );
260
    unlike( $xml, qr{Show analytics}, 'If pref is on and record has component, show analytics link is not displayed' );
261
262
    t::lib::Mocks::mock_preference( 'ShowComponentRecords', 'nowhere' );
263
    $xml = C4::XSLT::XSLTParse4Display(
264
        {
265
            biblionumber => $host_bibnum,
266
            record       => $marc_record,
267
            xsl_syspref  => 'OPACXSLTDetailsDisplay'
268
        }
269
    );
270
    unlike( $xml, qr{Show analytics}, 'If pref is off and record has component, show analytics link is displayed' );
271
272
    $search_mod->unmock('simple_search_compat');
273
274
    $schema->storage->txn_rollback;
275
};
276
277
sub host_record {
278
    my $marc = MARC::Record->new;
279
    $marc->append_fields(
280
        MARC::Field->new( '001', '1234' ),
281
        MARC::Field->new( '003', 'FIRST' ),
282
        MARC::Field->new( '245', '', '', a => 'Some title 1' ),
283
    );
284
    return $marc;
285
}
286
287
sub search_component_record {
288
    my $record = MARC::Record->new;
289
    $record->append_fields(
290
        MARC::Field->new( '001', '3456' ),
291
        MARC::Field->new( '245', '', '', a => 'Some title' ),
292
        MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
293
    );
294
    return ( undef, [$record], 1 );
295
}

Return to bug 11175