View | Details | Raw Unified | Return to bug 25527
Collapse All | Expand All

(-)a/Koha/ExternalContent.pm (-1 / +5 lines)
Lines 22-31 use Carp; Link Here
22
use base qw(Class::Accessor);
22
use base qw(Class::Accessor);
23
23
24
use Koha;
24
use Koha;
25
use Koha::Logger;
25
use Koha::Patrons;
26
use Koha::Patrons;
26
use C4::Auth;
27
use C4::Auth;
27
28
28
__PACKAGE__->mk_accessors(qw(client koha_session_id koha_patron));
29
__PACKAGE__->mk_accessors(qw(client koha_session_id koha_patron logger));
29
30
30
=head1 NAME
31
=head1 NAME
31
32
Lines 54-59 sub agent_string { Link Here
54
sub new {
55
sub new {
55
    my $class     = shift;
56
    my $class     = shift;
56
    my $params    = shift || {};
57
    my $params    = shift || {};
58
59
    $params->{logger} = Koha::Logger->get();
60
57
    return bless $params, $class;
61
    return bless $params, $class;
58
}
62
}
59
63
(-)a/Koha/ExternalContent/OverDrive.pm (-3 / +1 lines)
Lines 23-31 use Carp; Link Here
23
use base qw(Koha::ExternalContent);
23
use base qw(Koha::ExternalContent);
24
use WebService::ILS::OverDrive::Patron;
24
use WebService::ILS::OverDrive::Patron;
25
use C4::Context;
25
use C4::Context;
26
use Koha::Logger;
27
28
use constant logger => Koha::Logger->get();
29
26
30
=head1 NAME
27
=head1 NAME
31
28
Lines 71-76 sub new { Link Here
71
            user_agent_params => { agent => $class->agent_string }
68
            user_agent_params => { agent => $class->agent_string }
72
        ) );
69
        ) );
73
    }
70
    }
71
74
    return $self;
72
    return $self;
75
}
73
}
76
74
(-)a/Koha/ExternalContent/RecordedBooks.pm (-3 lines)
Lines 24-32 use base qw(Koha::ExternalContent); Link Here
24
use WebService::ILS::RecordedBooks::PartnerPatron;
24
use WebService::ILS::RecordedBooks::PartnerPatron;
25
use WebService::ILS::RecordedBooks::Partner;
25
use WebService::ILS::RecordedBooks::Partner;
26
use C4::Context;
26
use C4::Context;
27
use Koha::Logger;
28
29
use constant logger => Koha::Logger->get();
30
27
31
__PACKAGE__->mk_accessors(qw(domain is_identified));
28
__PACKAGE__->mk_accessors(qw(domain is_identified));
32
29
(-)a/t/db_dependent/Koha_ExternalContent_OverDrive.t (-32 / +30 lines)
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
- 

Return to bug 25527