3 use Test::More tests => 1;
6 use t::lib::TestBuilder;
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
14 subtest 'GetAnalyticsCount' => sub {
17 my $itemnumber = '123456789';
19 my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
20 my $search = Test::MockModule->new("Koha::SearchEngine::${engine}::Search");
22 'simple_search_compat',
24 my ( $self, $query ) = @_;
25 if ( $query and $query eq "hi=$itemnumber" ) {
26 return ( undef, undef, 7 );
28 return ( undef, undef, 0 );
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' );
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' );
42 $schema->storage->txn_rollback;