Lines 2-53
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
|
4 |
|
5 |
use t::lib::Mocks; |
|
|
6 |
use Test::More; |
5 |
use Test::More; |
7 |
use Test::MockModule; |
6 |
use Test::MockModule; |
|
|
7 |
use t::lib::Mocks; |
8 |
|
8 |
|
9 |
use Module::Load::Conditional qw( can_load check_install ); |
9 |
use Module::Load::Conditional qw( can_load check_install ); |
10 |
|
10 |
|
11 |
BEGIN { |
11 |
BEGIN { |
12 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
12 |
if ( check_install( module => 'WebService::ILS::OverDrive::Patron' ) ) { |
13 |
plan tests => 5; |
13 |
plan tests => 6; |
14 |
} else { |
14 |
} else { |
15 |
plan skip_all => "Need Test::DBIx::Class" |
15 |
plan skip_all => "Need WebService::ILS::OverDrive::Patron" |
16 |
} |
16 |
} |
17 |
} |
17 |
} |
18 |
|
18 |
|
19 |
use Test::DBIx::Class; |
19 |
use_ok('Koha::ExternalContent::OverDrive'); |
20 |
|
20 |
|
21 |
my $db = Test::MockModule->new('Koha::Database'); |
21 |
t::lib::Mocks::mock_preference('SessionStorage','tmp'); |
22 |
$db->mock( _new_schema => sub { return Schema(); } ); |
|
|
23 |
|
22 |
|
24 |
SKIP: { |
23 |
t::lib::Mocks::mock_preference('OverDriveClientKey', 'DUMMY'); |
25 |
skip "cannot find WebService::ILS::OverDrive::Patron", 5 |
24 |
t::lib::Mocks::mock_preference('OverDriveClientSecret', 'DUMMY'); |
26 |
unless can_load( modules => { 'WebService::ILS::OverDrive::Patron' => undef } ); |
25 |
t::lib::Mocks::mock_preference('OverDriveLibraryID', 'DUMMY'); |
27 |
|
26 |
|
28 |
use_ok('Koha::ExternalContent::OverDrive'); |
27 |
my $client = Koha::ExternalContent::OverDrive->new({koha_session_id => 'DUMMY'}); |
29 |
|
28 |
|
30 |
t::lib::Mocks::mock_preference('SessionStorage','tmp'); |
29 |
my $user_agent_string = $client->user_agent->agent(); |
|
|
30 |
ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set') |
31 |
or diag("User Agent string: $user_agent_string"); |
31 |
|
32 |
|
32 |
t::lib::Mocks::mock_preference('OverDriveClientKey', 'DUMMY'); |
33 |
my $base_url = "http://mykoha.org"; |
33 |
t::lib::Mocks::mock_preference('OverDriveClientSecret', 'DUMMY'); |
34 |
ok ($client->auth_url($base_url), 'auth_url()'); |
34 |
t::lib::Mocks::mock_preference('OverDriveLibraryID', 'DUMMY'); |
35 |
local $@; |
|
|
36 |
eval { $client->auth_by_code("blah", $base_url) }; |
37 |
ok($@, "auth_by_code() dies with bogus credentials"); |
38 |
SKIP: { |
39 |
skip "No exception", 1 unless $@; |
40 |
my $error_message = $client->error_message($@); |
41 |
ok($error_message =~ m/Authorization Failed/i, "error_message()") |
42 |
or diag("Original:\n$@\nTurned into:\n$error_message"); |
43 |
} |
35 |
|
44 |
|
36 |
my $client = Koha::ExternalContent::OverDrive->new({koha_session_id => 'DUMMY'}); |
45 |
subtest 'logger() tests' => sub { |
37 |
|
46 |
|
38 |
my $user_agent_string = $client->user_agent->agent(); |
47 |
plan tests => 2; |
39 |
ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set') |
|
|
40 |
or diag("User Agent string: $user_agent_string"); |
41 |
|
48 |
|
42 |
my $base_url = "http://mykoha.org"; |
49 |
my $external_content = Koha::ExternalContent::OverDrive->new({koha_session_id => 'DUMMY'}); |
43 |
ok ($client->auth_url($base_url), 'auth_url()'); |
50 |
ok( $external_content->can('logger'), 'A Koha::ExternalContent object has a logger accessor' ); |
44 |
local $@; |
51 |
is( ref($external_content->logger), 'Koha::Logger', 'The accessor return the right object type' ); |
45 |
eval { $client->auth_by_code("blah", $base_url) }; |
52 |
}; |
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"); |
52 |
} |
53 |
} |
54 |
- |
|
|