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

(-)a/C4/External/BakerTaylor.pm (-6 / +15 lines)
Lines 1-4 Link Here
1
package C4::External::BakerTaylor;
1
package C4::External::BakerTaylor;
2
2
# Copyright (C) 2008 LibLime
3
# Copyright (C) 2008 LibLime
3
# <jmf at liblime dot com>
4
# <jmf at liblime dot com>
4
#
5
#
Lines 19-35 package C4::External::BakerTaylor; Link Here
19
20
20
use XML::Simple;
21
use XML::Simple;
21
use LWP::Simple;
22
use LWP::Simple;
22
# use LWP::UserAgent;
23
use HTTP::Request::Common;
23
use HTTP::Request::Common;
24
24
use C4::Context;
25
use C4::Context;
25
use C4::Debug;
26
use C4::Debug;
26
27
27
use strict;
28
use Modern::Perl;
28
use warnings;
29
29
30
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
30
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
31
use vars qw($user $pass $agent $image_url $link_url);
32
&initialize;
33
31
34
BEGIN {
32
BEGIN {
35
	require Exporter;
33
	require Exporter;
Lines 39-45 BEGIN { Link Here
39
	%EXPORT_TAGS = (all=>\@EXPORT_OK);
37
	%EXPORT_TAGS = (all=>\@EXPORT_OK);
40
}
38
}
41
39
42
sub initialize {
40
# These variables are plack safe: they are initialized each time
41
my ( $user, $pass, $agent, $image_url, $link_url );
42
43
sub _initialize {
43
	$user     = (@_ ? shift : C4::Context->preference('BakerTaylorUsername')    ) || ''; # LL17984
44
	$user     = (@_ ? shift : C4::Context->preference('BakerTaylorUsername')    ) || ''; # LL17984
44
	$pass     = (@_ ? shift : C4::Context->preference('BakerTaylorPassword')    ) || ''; # CC82349
45
	$pass     = (@_ ? shift : C4::Context->preference('BakerTaylorPassword')    ) || ''; # CC82349
45
	$link_url = (@_ ? shift : C4::Context->preference('BakerTaylorBookstoreURL'));
46
	$link_url = (@_ ? shift : C4::Context->preference('BakerTaylorBookstoreURL'));
Lines 49-72 sub initialize { Link Here
49
}
50
}
50
51
51
sub image_url {
52
sub image_url {
53
    _initialize();
52
	($user and $pass) or return;
54
	($user and $pass) or return;
53
	my $isbn = (@_ ? shift : '');
55
	my $isbn = (@_ ? shift : '');
54
	$isbn =~ s/(p|-)//g;	# sanitize
56
	$isbn =~ s/(p|-)//g;	# sanitize
55
	return $image_url . $isbn;
57
	return $image_url . $isbn;
56
}
58
}
59
57
sub link_url {
60
sub link_url {
61
    _initialize();
58
	my $isbn = (@_ ? shift : '');
62
	my $isbn = (@_ ? shift : '');
59
	$isbn =~ s/(p|-)//g;	# sanitize
63
	$isbn =~ s/(p|-)//g;	# sanitize
60
	$link_url or return;
64
	$link_url or return;
61
	return $link_url . $isbn;
65
	return $link_url . $isbn;
62
}
66
}
67
63
sub content_cafe_url {
68
sub content_cafe_url {
69
    _initialize();
64
	($user and $pass) or return;
70
	($user and $pass) or return;
65
	my $isbn = (@_ ? shift : '');
71
	my $isbn = (@_ ? shift : '');
66
	$isbn =~ s/(p|-)//g;	# sanitize
72
	$isbn =~ s/(p|-)//g;	# sanitize
67
	return "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$user&Password=$pass&Options=Y&ItemKey=$isbn";
73
	return "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$user&Password=$pass&Options=Y&ItemKey=$isbn";
68
}
74
}
75
69
sub http_jacket_link {
76
sub http_jacket_link {
77
    _initialize();
70
	my $isbn = shift or return;
78
	my $isbn = shift or return;
71
	$isbn =~ s/(p|-)//g;	# sanitize
79
	$isbn =~ s/(p|-)//g;	# sanitize
72
	my $image = availability($isbn);
80
	my $image = availability($isbn);
Lines 78-83 sub http_jacket_link { Link Here
78
}
86
}
79
87
80
sub availability {
88
sub availability {
89
    _initialize();
81
	my $isbn = shift or return;
90
	my $isbn = shift or return;
82
	($user and $pass) or return;
91
	($user and $pass) or return;
83
	$isbn =~ s/(p|-)//g;	# sanitize
92
	$isbn =~ s/(p|-)//g;	# sanitize
(-)a/t/db_dependent/External_BakerTaylor.t (-20 / +18 lines)
Lines 2-34 Link Here
2
2
3
# some simple tests of the elements of C4::External::BakerTaylor that do not require a valid username and password
3
# some simple tests of the elements of C4::External::BakerTaylor that do not require a valid username and password
4
4
5
use strict;
5
use Modern::Perl;
6
use warnings;
7
6
8
use Test::More tests => 9;
7
use Test::More tests => 9;
8
use t::lib::Mocks;
9
9
10
BEGIN {
10
BEGIN {
11
        use_ok('C4::External::BakerTaylor');
11
        use_ok('C4::External::BakerTaylor');
12
}
12
}
13
13
14
# for testing, to avoid using C4::Context
14
# test with mocked prefs
15
my $username="testing_username";
15
my $username= "testing_username";
16
my $password="testing_password";
16
my $password= "testing_password";
17
my $link_url = "http://wrongexample.com?ContentCafe.aspx?UserID=$username";
17
18
18
# taken from C4::External::BakerTaylor::initialize
19
t::lib::Mocks::mock_preference( 'BakerTaylorUsername', $username );
19
my $image_url = "http://contentcafe2.btol.com/ContentCafe/Jacket.aspx?UserID=$username&Password=$password&Options=Y&Return=T&Type=S&Value=";
20
t::lib::Mocks::mock_preference( 'BakerTaylorPassword', $password );
20
21
t::lib::Mocks::mock_preference( 'BakerTaylorBookstoreURL', $link_url );
21
# test without initializing
22
is( C4::External::BakerTaylor::image_url(), undef, "testing image url pre initilization");
23
is( C4::External::BakerTaylor::link_url(), undef, "testing link url pre initilization");
24
is( C4::External::BakerTaylor::content_cafe_url(""), undef, "testing content cafe url pre initilization");
25
is( C4::External::BakerTaylor::http_jacket_link(""), undef, "testing http jacket link pre initilization");
26
is( C4::External::BakerTaylor::availability(""), undef, "testing availability pre initilization");
27
22
28
# intitialize
23
my $image_url = "http://contentcafe2.btol.com/ContentCafe/Jacket.aspx?UserID=$username&Password=$password&Options=Y&Return=T&Type=S&Value=";
29
C4::External::BakerTaylor::initialize($username, $password, "link_url");
24
my $content_cafe = "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$username&Password=$password&Options=Y&ItemKey=";
30
25
31
# testing basic results
26
is( C4::External::BakerTaylor::image_url(), $image_url, "testing default image url");
32
is( C4::External::BakerTaylor::image_url("aa"), $image_url."aa", "testing image url construction");
27
is( C4::External::BakerTaylor::image_url("aa"), $image_url."aa", "testing image url construction");
33
is( C4::External::BakerTaylor::link_url("bb"), "link_urlbb", "testing link url construction");
28
is( C4::External::BakerTaylor::link_url(), $link_url, "testing default link url");
34
is( C4::External::BakerTaylor::content_cafe_url("cc"), "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$username&Password=$password&Options=Y&ItemKey=cc", "testing content cafe url  construction");
29
is( C4::External::BakerTaylor::link_url("bb"), "${link_url}bb", "testing link url construction");
30
is( C4::External::BakerTaylor::content_cafe_url(""), $content_cafe, "testing default content cafe url");
31
is( C4::External::BakerTaylor::content_cafe_url("cc"), "${content_cafe}cc", "testing content cafe url construction");
32
is( C4::External::BakerTaylor::http_jacket_link(""), undef, "testing empty http jacket link");
33
is( C4::External::BakerTaylor::availability(""), undef, "testing empty availability");
35
- 

Return to bug 16636