Koha/t/db_dependent/ILSDI_Services.t
Jonathan Druart 4f5217314c Bug 15629: Koha::Libraries - Remove GetBranchDetail
C4::Branch::GetBranchDetail retrieved library infos, it could be easily
replaced with Koha::Libraries->find

When this change needs other big changes, the unblessed method is
called, to manipulate a hashref (as before) instead of a Koha::Library
object (for instance when $library is sent to GetPreparedLetter).

Test plan:
1/ Print a basket group, the library names should be correctly
displayed.
2/ Enable emailLibrarianWhenHoldIsPlaced and place a hold, a HOLDPLACED
notice will be generated (focus on the library name)
3/ Edit a patron and change his/her library
4/ Generate the advanced notices (misc/cronjobs/advance_notices.pl) and
have a look at the generated notices
5/ Same of overdues notices
6/ Set IndependentBranches and use a non superlibrarian user to place a
hold. The "pickup at" should be correctly filled.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
2016-02-24 03:55:06 +00:00

92 lines
3.1 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use C4::Members qw/AddMember GetMember GetBorrowercategory/;
use Koha::Libraries;
use CGI qw ( -utf8 );
use Test::More tests => 15;
BEGIN {
use_ok('C4::ILSDI::Services');
}
my $dbh = C4::Context->dbh;
# Start transaction
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
# Create patron
my %data = (
firstname => 'my firstname',
surname => 'my surname',
categorycode => 'UT',
branchcode => 'UT',
cardnumber => 'ilsdi-cardnumber',
userid => 'ilsdi-userid',
password => 'ilsdi-password',
);
# Crate patron category
unless ( GetBorrowercategory('UT') ) {
$dbh->do("INSERT INTO categories
(categorycode,description,enrolmentperiod,upperagelimit,enrolmentfee,overduenoticerequired,reservefee,category_type,default_privacy)
VALUES
('UT','Unit tester',99,99,0.000000,1,0.000000,'C','default');");
}
# Create library
unless ( Koha::Libraries->find('UT') ) {
$dbh->do("INSERT INTO branches (branchcode,branchname) VALUES ('UT','Unit test library');");
}
my $borrowernumber = AddMember(%data);
my $borrower = GetMember( borrowernumber => $borrowernumber );
{ # AuthenticatePatron test
my $query = new CGI;
$query->param('username',$borrower->{'userid'});
$query->param('password','ilsdi-password');
my $reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'id'}, $borrowernumber, "userid and password - Patron authenticated");
is($reply->{'code'}, undef, "Error code undef");
$query->param('password','ilsdi-passworD');
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'code'}, 'PatronNotFound', "userid and wrong password - PatronNotFound");
is($reply->{'id'}, undef, "id undef");
$query->param('password','ilsdi-password');
$query->param('username','wrong-ilsdi-useriD');
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'code'}, 'PatronNotFound', "non-existing userid - PatronNotFound");
is($reply->{'id'}, undef, "id undef");
$query->param('username',uc($borrower->{'userid'}));
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'id'}, $borrowernumber, "userid is not case sensitive - Patron authenticated");
is($reply->{'code'}, undef, "Error code undef");
$query->param('username',$borrower->{'cardnumber'});
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'id'}, $borrowernumber, "cardnumber and password - Patron authenticated");
is($reply->{'code'}, undef, "Error code undef");
$query->param('password','ilsdi-passworD');
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'code'}, 'PatronNotFound', "cardnumber and wrong password - PatronNotFount");
is($reply->{'id'}, undef, "id undef");
$query->param('username','randomcardnumber1234');
$query->param('password','ilsdi-password');
$reply = C4::ILSDI::Services::AuthenticatePatron($query);
is($reply->{'code'}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound");
is($reply->{'id'}, undef, "id undef");
}