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> (cherry picked from commitfd7652255c) Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> (cherry picked from commit555efbd447) Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
This commit is contained in:
parent
79719d61f5
commit
a989b49ec9
|
|
@ -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;
|
||||
Loading…
Reference in New Issue