5 use C4
::Members qw
/AddMember GetMember GetBorrowercategory/;
9 use Test
::More tests
=> 16;
11 use t
::lib
::TestBuilder
;
14 use_ok
('C4::ILSDI::Services');
17 my $dbh = C4
::Context
->dbh;
20 $dbh->{AutoCommit
} = 0;
21 $dbh->{RaiseError
} = 1;
25 firstname
=> 'my firstname',
26 surname
=> 'my surname',
29 cardnumber
=> 'ilsdi-cardnumber',
30 userid
=> 'ilsdi-userid',
31 password
=> 'ilsdi-password',
34 # Crate patron category
35 unless ( GetBorrowercategory
('UT') ) {
36 $dbh->do("INSERT INTO categories
37 (categorycode,description,enrolmentperiod,upperagelimit,enrolmentfee,overduenoticerequired,reservefee,category_type,default_privacy)
39 ('UT','Unit tester',99,99,0.000000,1,0.000000,'C','default');");
43 unless ( Koha
::Libraries
->find('UT') ) {
44 $dbh->do("INSERT INTO branches (branchcode,branchname) VALUES ('UT','Unit test library');");
48 my $borrowernumber = AddMember
(%data);
49 my $borrower = GetMember
( borrowernumber
=> $borrowernumber );
51 { # AuthenticatePatron test
54 $query->param('username',$borrower->{'userid'});
55 $query->param('password','ilsdi-password');
57 my $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
58 is
($reply->{'id'}, $borrowernumber, "userid and password - Patron authenticated");
59 is
($reply->{'code'}, undef, "Error code undef");
61 $query->param('password','ilsdi-passworD');
62 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
63 is
($reply->{'code'}, 'PatronNotFound', "userid and wrong password - PatronNotFound");
64 is
($reply->{'id'}, undef, "id undef");
66 $query->param('password','ilsdi-password');
67 $query->param('username','wrong-ilsdi-useriD');
68 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
69 is
($reply->{'code'}, 'PatronNotFound', "non-existing userid - PatronNotFound");
70 is
($reply->{'id'}, undef, "id undef");
72 $query->param('username',uc($borrower->{'userid'}));
73 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
74 is
($reply->{'id'}, $borrowernumber, "userid is not case sensitive - Patron authenticated");
75 is
($reply->{'code'}, undef, "Error code undef");
77 $query->param('username',$borrower->{'cardnumber'});
78 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
79 is
($reply->{'id'}, $borrowernumber, "cardnumber and password - Patron authenticated");
80 is
($reply->{'code'}, undef, "Error code undef");
82 $query->param('password','ilsdi-passworD');
83 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
84 is
($reply->{'code'}, 'PatronNotFound', "cardnumber and wrong password - PatronNotFount");
85 is
($reply->{'id'}, undef, "id undef");
87 $query->param('username','randomcardnumber1234');
88 $query->param('password','ilsdi-password');
89 $reply = C4
::ILSDI
::Services
::AuthenticatePatron
($query);
90 is
($reply->{'code'}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound");
91 is
($reply->{'id'}, undef, "id undef");
97 $dbh->{AutoCommit
} = 1;
98 $dbh->{RaiseError
} = 0;
100 my $schema = Koha
::Database
->schema;
101 $schema->storage->txn_begin;
103 $schema->resultset( 'Issue' )->delete_all;
104 $schema->resultset( 'Borrower' )->delete_all;
105 $schema->resultset( 'BorrowerAttribute' )->delete_all;
106 $schema->resultset( 'BorrowerAttributeType' )->delete_all;
107 $schema->resultset( 'Category' )->delete_all;
108 $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
109 $schema->resultset( 'Branch' )->delete_all;
112 { # GetPatronInfo/GetBorrowerAttributes test for extended patron attributes:
114 # Configure Koha to enable ILS-DI server and extended attributes:
115 t
::lib
::Mocks
::mock_preference
( 'ILS-DI', 1 );
116 t
::lib
::Mocks
::mock_preference
( 'ExtendedPatronAttributes', 1 );
118 my $builder = t
::lib
::TestBuilder
->new;
120 # Set up a library/branch for our user to belong to:
121 my $lib = $builder->build( {
124 branchcode
=> 'T_ILSDI',
128 # Create a new category for user to belong to:
129 my $cat = $builder->build( {
130 source
=> 'Category',
132 category_type
=> 'A',
133 BlockExpiredPatronOpacActions
=> -1,
137 # Create a new attribute type:
138 my $attr_type = $builder->build( {
139 source
=> 'BorrowerAttributeType',
143 authorised_value_category
=> '',
149 my $brwr = $builder->build( {
150 source
=> 'Borrower',
152 categorycode
=> $cat->{'categorycode'},
158 my $auth = $builder->build( {
159 source
=> 'AuthorisedValue',
161 category
=> $cat->{'categorycode'}
165 # Set the new attribute for our user:
166 my $attr = $builder->build( {
167 source
=> 'BorrowerAttribute',
169 borrowernumber
=> $brwr->{'borrowernumber'},
170 code
=> $attr_type->{'code'},
176 # Prepare and send web request for IL-SDI server:
178 $query->param( 'service', 'GetPatronInfo' );
179 $query->param( 'patron_id', $brwr->{'borrowernumber'} );
180 $query->param( 'show_attributes', '1' );
182 my $reply = C4
::ILSDI
::Services
::GetPatronInfo
( $query );
184 # Build a structure for comparison:
186 category_code
=> $attr_type->{'category_code'},
187 class => $attr_type->{'class'},
188 code
=> $attr->{'code'},
189 description
=> $attr_type->{'description'},
190 display_checkout
=> $attr_type->{'display_checkout'},
192 value
=> $attr->{'attribute'},
193 value_description
=> undef,
197 is_deeply
( $reply->{'attributes'}, [ $cmp ], 'Test GetPatronInfo - show_attributes parameter' );
201 $schema->storage->txn_rollback;