From 137168c98c8d4faebd3ad11134929f7df291a184 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 19 Sep 2024 12:36:54 +0000 Subject: [PATCH] Bug 37810: Add test Test plan: 1) Apply only tests patch, run: prove t/db_dependent/Koha/ERM/EUsage/UsageDataProvider.t 2) Verify tests fail 3) Apply fix patch 4) Run tests again, verify they pass Signed-off-by: David Nind Signed-off-by: Nick Clemens --- .../Koha/ERM/EUsage/UsageDataProvider.t | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/ERM/EUsage/UsageDataProvider.t b/t/db_dependent/Koha/ERM/EUsage/UsageDataProvider.t index 2513b6f2477..3f64e0e1d3f 100755 --- a/t/db_dependent/Koha/ERM/EUsage/UsageDataProvider.t +++ b/t/db_dependent/Koha/ERM/EUsage/UsageDataProvider.t @@ -17,10 +17,12 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Koha::ERM::EUsage::UsageDataProvider; use Koha::Database; +use Test::MockModule; +use Test::MockObject; use t::lib::TestBuilder; @@ -108,3 +110,37 @@ subtest '_build_url_query' => sub { $schema->storage->txn_rollback; }; + +subtest 'test_connection() tests' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $ua = Test::MockModule->new('LWP::UserAgent'); + $ua->mock('simple_request', sub { + my $response = Test::MockObject->new(); + + $response->mock('code', sub { + return 200; + }); + $response->mock('is_error', sub { + return 0; + }); + $response->mock('is_redirect', sub { + return 0; + }); + $response->mock('decoded_content', sub { + return '{"Description":"COUNTER Usage Reports for Test platform.","ServiceActive":true,"RegistryURL":"https://www.whatever.com"}'; + }); + $response->{_rc} = 200; + return $response; + }); + + my $usage_data_provider = $builder->build_object( + { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); + + is( $usage_data_provider->test_connection, 1); + + $schema->storage->txn_rollback; +}; -- 2.39.5