Bug 27683: Unit test for GetAnalyticsCount

Run prove t/db_dependent/Items/GetAnalyticsCount.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Fridolin Somers 2021-02-11 16:28:18 +01:00 committed by Tomas Cohen Arazi
parent b4a9edc83f
commit fd7652255c
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
use Modern::Perl;
use Test::More tests => 1;
use Test::MockModule;
use t::lib::Mocks;
use t::lib::TestBuilder;
use C4::Items;
use Koha::Database;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
subtest 'GetAnalyticsCount' => sub {
plan tests => 2;
my $itemnumber = '123456789';
my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
my $search = Test::MockModule->new("Koha::SearchEngine::${engine}::Search");
$search->mock(
'simple_search_compat',
sub {
my ( $self, $query ) = @_;
if ( $query and $query eq "hi=$itemnumber" ) {
return ( undef, undef, 7 );
}
return ( undef, undef, 0 );
}
);
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
my $c = C4::Items::GetAnalyticsCount($itemnumber);
is( $c, 0, 'GetAnalyticsCount returns 0 when pref is disabled' );
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
$c = C4::Items::GetAnalyticsCount($itemnumber);
is( $c, 7, 'GetAnalyticsCount uses simple_search_compat("hi=<itemnumber>") when pref is enabled' );
};
$schema->storage->txn_rollback;