9 use Module
::Load
::Conditional
qw( can_load check_install );
14 if ( check_install
( module
=> 'Test::DBIx::Class' ) ) {
17 plan skip_all
=> "Need Test::DBIx::Class"
21 use Test
::DBIx
::Class
;
23 my $db = Test
::MockModule
->new('Koha::Database');
24 $db->mock( _new_schema
=> sub { return Schema
(); } );
27 skip
"cannot find WebService::ILS::OverDrive::Patron", 5
28 unless can_load
( modules
=> { 'WebService::ILS::OverDrive::Patron' => undef } );
30 use_ok
('Koha::ExternalContent::OverDrive');
32 t
::lib
::Mocks
::mock_preference
('SessionStorage','tmp');
34 t
::lib
::Mocks
::mock_preference
('OverDriveClientKey', 'DUMMY');
35 t
::lib
::Mocks
::mock_preference
('OverDriveClientSecret', 'DUMMY');
36 t
::lib
::Mocks
::mock_preference
('OverDriveLibraryID', 'DUMMY');
38 my $client = Koha
::ExternalContent
::OverDrive
->new({koha_session_id
=> 'DUMMY'});
40 my $user_agent_string = $client->user_agent->agent();
41 ok
($user_agent_string =~ m/^Koha/, 'User Agent string is set')
42 or diag
("User Agent string: $user_agent_string");
44 my $base_url = "http://mykoha.org";
45 ok
($client->auth_url($base_url), 'auth_url()');
47 eval { $client->auth_by_code("blah", $base_url) };
48 ok
($@
, "auth_by_code() dies with bogus credentials");
50 skip
"No exception", 1 unless $@
;
51 my $error_message = $client->error_message($@
);
52 ok
($error_message =~ m/Authorization Failed/i, "error_message()")
53 or diag
("Original:\n$@\nTurned into:\n$error_message");