Bug 24546: Fix intentions of build_sample_item in Club/Hold.t
[koha.git] / t / db_dependent / Koha_ExternalContent_OverDrive.t
blobc09ea2952dd25e64284d4c8e862ceeb05d2741aa
1 #!/usr/bin/env perl
3 use Modern::Perl;
5 use t::lib::Mocks;
6 use Test::More;
7 use Test::MockModule;
9 use Module::Load::Conditional qw( can_load check_install );
11 BEGIN {
12 if ( check_install( module => 'Test::DBIx::Class' ) ) {
13 plan tests => 5;
14 } else {
15 plan skip_all => "Need Test::DBIx::Class"
19 use Test::DBIx::Class;
21 my $db = Test::MockModule->new('Koha::Database');
22 $db->mock( _new_schema => sub { return Schema(); } );
24 SKIP: {
25 skip "cannot find WebService::ILS::OverDrive::Patron", 5
26 unless can_load( modules => { 'WebService::ILS::OverDrive::Patron' => undef } );
28 use_ok('Koha::ExternalContent::OverDrive');
30 t::lib::Mocks::mock_preference('SessionStorage','tmp');
32 t::lib::Mocks::mock_preference('OverDriveClientKey', 'DUMMY');
33 t::lib::Mocks::mock_preference('OverDriveClientSecret', 'DUMMY');
34 t::lib::Mocks::mock_preference('OverDriveLibraryID', 'DUMMY');
36 my $client = Koha::ExternalContent::OverDrive->new({koha_session_id => 'DUMMY'});
38 my $user_agent_string = $client->user_agent->agent();
39 ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set')
40 or diag("User Agent string: $user_agent_string");
42 my $base_url = "http://mykoha.org";
43 ok ($client->auth_url($base_url), 'auth_url()');
44 local $@;
45 eval { $client->auth_by_code("blah", $base_url) };
46 ok($@, "auth_by_code() dies with bogus credentials");
47 SKIP: {
48 skip "No exception", 1 unless $@;
49 my $error_message = $client->error_message($@);
50 ok($error_message =~ m/Authorization Failed/i, "error_message()")
51 or diag("Original:\n$@\nTurned into:\n$error_message");