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

(-)a/t/db_dependent/Items/GetAnalyticsCount.t (-1 / +42 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use Test::More tests => 1;
4
use Test::MockModule;
5
use t::lib::Mocks;
6
use t::lib::TestBuilder;
7
8
use C4::Items;
9
use Koha::Database;
10
11
my $schema = Koha::Database->new->schema;
12
$schema->storage->txn_begin;
13
14
subtest 'GetAnalyticsCount' => sub {
15
    plan tests => 2;
16
17
    my $itemnumber = '123456789';
18
19
    my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
20
    my $search = Test::MockModule->new("Koha::SearchEngine::${engine}::Search");
21
    $search->mock(
22
        'simple_search_compat',
23
        sub {
24
            my ( $self, $query ) = @_;
25
            if ( $query and $query eq "hi=$itemnumber" ) {
26
                return ( undef, undef, 7 );
27
            }
28
            return ( undef, undef, 0 );
29
        }
30
    );
31
32
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
33
    my $c = C4::Items::GetAnalyticsCount($itemnumber);
34
    is( $c, 0, 'GetAnalyticsCount returns 0 when pref is disabled' );
35
36
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
37
    $c = C4::Items::GetAnalyticsCount($itemnumber);
38
    is( $c, 7, 'GetAnalyticsCount uses simple_search_compat("hi=<itemnumber>") when pref is enabled' );
39
40
};
41
42
$schema->storage->txn_rollback;

Return to bug 27683