Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use C4::Members qw/AddMember GetMember GetBorrowercategory/; |
6 |
use C4::Branch; |
7 |
use CGI; |
8 |
|
9 |
use Test::More tests => 15; |
10 |
|
11 |
BEGIN { |
12 |
use_ok('C4::ILSDI::Services'); |
13 |
} |
14 |
|
15 |
my $dbh = C4::Context->dbh; |
16 |
|
17 |
# Start transaction |
18 |
$dbh->{AutoCommit} = 0; |
19 |
$dbh->{RaiseError} = 1; |
20 |
|
21 |
# Create patron |
22 |
my %data = ( |
23 |
firstname => 'my firstname', |
24 |
surname => 'my surname', |
25 |
categorycode => 'UT', |
26 |
branchcode => 'UT', |
27 |
cardnumber => 'ilsdi-cardnumber', |
28 |
userid => 'ilsdi-userid', |
29 |
password => 'ilsdi-password', |
30 |
); |
31 |
|
32 |
# Crate patron category |
33 |
unless ( GetBorrowercategory('UT') ) { |
34 |
$dbh->do("INSERT INTO categories |
35 |
(categorycode,description,enrolmentperiod,upperagelimit,enrolmentfee,overduenoticerequired,reservefee,category_type) |
36 |
VALUES |
37 |
('UT','Unit tester',99,99,0.000000,1,0.000000,'C');"); |
38 |
} |
39 |
|
40 |
# Create branch |
41 |
unless ( GetBranchDetail('DEMO') ) { |
42 |
$dbh->do("INSERT INTO branches (branchcode,branchname) VALUES ('UT','Unit test library');"); |
43 |
} |
44 |
|
45 |
|
46 |
my $borrowernumber = AddMember(%data); |
47 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
48 |
|
49 |
{ # AuthenticatePatron test |
50 |
|
51 |
my $query = new CGI; |
52 |
$query->param('username',$borrower->{'userid'}); |
53 |
$query->param('password','ilsdi-password'); |
54 |
|
55 |
my $reply = C4::ILSDI::Services::AuthenticatePatron($query); |
56 |
is($reply->{'id'}, $borrowernumber, "userid and password - Patron authenticated"); |
57 |
is($reply->{'code'}, undef, "Error code undef"); |
58 |
|
59 |
$query->param('password','ilsdi-passworD'); |
60 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
61 |
is($reply->{'code'}, 'PatronNotFound', "userid and wrong password - PatronNotFound"); |
62 |
is($reply->{'id'}, undef, "id undef"); |
63 |
|
64 |
$query->param('password','ilsdi-password'); |
65 |
$query->param('username','wrong-ilsdi-useriD'); |
66 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
67 |
is($reply->{'code'}, 'PatronNotFound', "non-existing userid - PatronNotFound"); |
68 |
is($reply->{'id'}, undef, "id undef"); |
69 |
|
70 |
$query->param('username',uc($borrower->{'userid'})); |
71 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
72 |
is($reply->{'id'}, $borrowernumber, "userid is not case sensitive - Patron authenticated"); |
73 |
is($reply->{'code'}, undef, "Error code undef"); |
74 |
|
75 |
TODO: { local: $TODO = "Can't use cardnumber for authentication with ILS-DI yet."; |
76 |
$query->param('username',$borrower->{'cardnumber'}); |
77 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
78 |
is($reply->{'id'}, $borrowernumber, "cardnumber and password - Patron authenticated"); |
79 |
is($reply->{'code'}, undef, "Error code undef"); |
80 |
|
81 |
$query->param('password','ilsdi-passworD'); |
82 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
83 |
is($reply->{'code'}, 'PatronNotFound', "cardnumber and wrong password - PatronNotFount"); |
84 |
is($reply->{'id'}, undef, "id undef"); |
85 |
|
86 |
$query->param('username','randomcardnumber1234'); |
87 |
$query->param('password','ilsdi-password'); |
88 |
$reply = C4::ILSDI::Services::AuthenticatePatron($query); |
89 |
is($reply->{'code'}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound"); |
90 |
is($reply->{'id'}, undef, "id undef"); |
91 |
} |
92 |
|
93 |
} |