Bug 19817: Add pref KohaManualLanguage
[koha.git] / t / Koha_ExternalContent_OverDrive.t
blob8afa226679073f79b47e81eb6f2cb152c768a503
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 use Koha::Schema;
13 BEGIN {
14 if ( check_install( module => 'Test::DBIx::Class' ) ) {
15 plan tests => 5;
16 } else {
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(); } );
26 SKIP: {
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()');
46 local $@;
47 eval { $client->auth_by_code("blah", $base_url) };
48 ok($@, "auth_by_code() dies with bogus credentials");
49 SKIP: {
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");