Bug 15548: Move new patron related code to Patron*
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Jan 2016 15:57:59 +0000 (15:57 +0000)
committerJesse Weaver <jweaver@bywatersolutions.com>
Thu, 3 Mar 2016 21:38:26 +0000 (14:38 -0700)
The 'borrower' should not be used anymore, especially for new code.
This patch move files and rename variables newly pushed (i.e. in the Koha
namespace).

Test plan:
1/
  git grep Koha::Borrower
should not return code in use.

2/
Prove the different modified test files

3/ Do some clicks in the member^Wpatron module to be sure there is not
an obvious error.

Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com>
Works as described. Tested with Circulation, Members/Patrons, Discharge,
Restrictions modules and the must common functionalities

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
67 files changed:
C4/Circulation.pm
C4/Members.pm
Koha/Borrower.pm [deleted file]
Koha/Borrower/Debarments.pm [deleted file]
Koha/Borrower/Discharge.pm [deleted file]
Koha/Borrower/Files.pm [deleted file]
Koha/Borrower/Modifications.pm [deleted file]
Koha/Borrowers.pm [deleted file]
Koha/Hold.pm
Koha/Item.pm
Koha/Misc/Files.pm
Koha/Patron.pm [new file with mode: 0644]
Koha/Patron/Debarments.pm [new file with mode: 0644]
Koha/Patron/Discharge.pm [new file with mode: 0644]
Koha/Patron/Files.pm [new file with mode: 0644]
Koha/Patron/Modifications.pm [new file with mode: 0644]
Koha/Patrons.pm [new file with mode: 0644]
Koha/REST/V1.pm
Koha/REST/V1/Patrons.pm
Koha/Template/Plugin/Borrowers.pm
Koha/Virtualshelf.pm
about.pl
admin/categories.pl
circ/circulation.pl
circ/ysearch.pl
mainpage.pl
members/discharge.pl
members/discharges.pl
members/files.pl
members/memberentry.pl
members/members-home.pl
members/members-update-do.pl
members/members-update.pl
members/mod_debarment.pl
members/moremember.pl
misc/cronjobs/cleanup_database.pl
misc/cronjobs/longoverdue.pl
misc/cronjobs/overdue_notices.pl
opac/opac-discharge.pl
opac/opac-memberentry.pl
opac/opac-privacy.pl
opac/opac-registration-verify.pl
opac/opac-reserve.pl
opac/opac-user.pl
reserve/request.pl
t/Borrower.t [deleted file]
t/Patron.t [new file with mode: 0755]
t/db_dependent/Accounts.t
t/db_dependent/BiblioObject.t
t/db_dependent/Borrower.t [deleted file]
t/db_dependent/Borrower_Debarments.t [deleted file]
t/db_dependent/Borrower_Discharge.t [deleted file]
t/db_dependent/Borrower_Files.t [deleted file]
t/db_dependent/Borrowers.t [deleted file]
t/db_dependent/Circulation/AnonymiseIssueHistory.t
t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t
t/db_dependent/Creators/Lib.t
t/db_dependent/Hold.t
t/db_dependent/Koha_borrower_modifications.t
t/db_dependent/Patron.t [new file with mode: 0755]
t/db_dependent/Patron/Borrower_Debarments.t [new file with mode: 0755]
t/db_dependent/Patron/Borrower_Discharge.t [new file with mode: 0644]
t/db_dependent/Patron/Borrower_Files.t [new file with mode: 0644]
t/db_dependent/Patrons.t [new file with mode: 0755]
t/db_dependent/Review.t
t/db_dependent/api/v1/patrons.t
tools/import_borrowers.pl

index 2d2720a..9b4edf8 100644 (file)
@@ -48,8 +48,8 @@ use Data::Dumper;
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::Items;
-use Koha::Borrowers;
-use Koha::Borrower::Debarments;
+use Koha::Patrons;
+use Koha::Patron::Debarments;
 use Koha::Database;
 use Koha::Libraries;
 use Carp;
@@ -2201,7 +2201,7 @@ sub MarkIssueReturned {
 
     if ( C4::Context->preference('StoreLastBorrower') ) {
         my $item = Koha::Items->find( $itemnumber );
-        my $patron = Koha::Borrowers->find( $borrowernumber );
+        my $patron = Koha::Patrons->find( $borrowernumber );
         $item->last_returned_by( $patron );
     }
 }
@@ -2265,13 +2265,13 @@ sub _debar_user_on_return {
             my $new_debar_dt =
               $dt_today->clone()->add_duration( $suspension_days );
 
-            Koha::Borrower::Debarments::AddUniqueDebarment({
+            Koha::Patron::Debarments::AddUniqueDebarment({
                 borrowernumber => $borrower->{borrowernumber},
                 expiration     => $new_debar_dt->ymd(),
                 type           => 'SUSPENSION',
             });
             # if borrower was already debarred but does not get an extra debarment
-            if ( $borrower->{debarred} eq Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber}) ) {
+            if ( $borrower->{debarred} eq Koha::Patron::Debarments::IsDebarred($borrower->{borrowernumber}) ) {
                     return ($borrower->{debarred},1);
             }
             return $new_debar_dt->ymd();
@@ -2834,7 +2834,7 @@ sub CanBookBeRenewed {
 
     my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
     my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
-    my $restricted = Koha::Borrower::Debarments::IsDebarred($borrowernumber);
+    my $restricted = Koha::Patron::Debarments::IsDebarred($borrowernumber);
     my $hasoverdues = C4::Members::HasOverdues($borrowernumber);
 
     if ( $restricted and $restrictionblockrenewing ) {
index a003809..a7f686c 100644 (file)
@@ -36,7 +36,7 @@ use C4::NewsChannels; #get slip news
 use DateTime;
 use Koha::Database;
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Patron::Debarments qw(IsDebarred);
 use Text::Unaccent qw( unac_string );
 use Koha::AuthUtils qw(hash_password);
 use Koha::Database;
@@ -516,7 +516,7 @@ sub IsMemberBlocked {
     my $borrowernumber = shift;
     my $dbh            = C4::Context->dbh;
 
-    my $blockeddate = Koha::Borrower::Debarments::IsDebarred($borrowernumber);
+    my $blockeddate = Koha::Patron::Debarments::IsDebarred($borrowernumber);
 
     return ( 1, $blockeddate ) if $blockeddate;
 
diff --git a/Koha/Borrower.pm b/Koha/Borrower.pm
deleted file mode 100644 (file)
index d058301..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-package Koha::Borrower;
-
-# Copyright ByWater Solutions 2014
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Carp;
-
-use Koha::Database;
-
-use base qw(Koha::Object);
-
-=head1 NAME
-
-Koha::Borrower - Koha Borrower Object class
-
-=head1 API
-
-=head2 Class Methods
-
-=cut
-
-=head3 guarantor
-
-Returns a Koha::Borrower object for this borrower's guarantor
-
-=cut
-
-sub guarantor {
-    my ( $self ) = @_;
-
-    return Koha::Borrowers->find( $self->guarantorid() );
-}
-
-=head3 type
-
-=cut
-
-sub _type {
-    return 'Borrower';
-}
-
-=head1 AUTHOR
-
-Kyle M Hall <kyle@bywatersolutions.com>
-
-=cut
-
-1;
diff --git a/Koha/Borrower/Debarments.pm b/Koha/Borrower/Debarments.pm
deleted file mode 100644 (file)
index 9efdc42..0000000
+++ /dev/null
@@ -1,333 +0,0 @@
-package Koha::Borrower::Debarments;
-
-# This file is part of Koha.
-#
-# Copyright 2013 ByWater Solutions
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use C4::Context;
-
-use parent qw( Exporter );
-
-our @EXPORT = qw(
-  GetDebarments
-
-  AddDebarment
-  DelDebarment
-  ModDebarment
-
-  AddUniqueDebarment
-  DelUniqueDebarment
-
-  IsDebarred
-);
-
-=head1 Koha::Borrower::Debarments
-
-Koha::Borrower::Debarments - Module for managing borrower debarments
-
-=cut
-
-=head2 GetDebarments
-
-my $arrayref = GetDebarments({ borrowernumber => $borrowernumber [, key => $value ] );
-
-=cut
-
-sub GetDebarments {
-    my ($params) = @_;
-
-    return unless ( $params->{'borrowernumber'} );
-
-    my @keys   = keys %$params;
-    my @values = values %$params;
-
-    my $where = join( ' AND ', map { "$_ = ?" } @keys );
-    my $sql   = "SELECT * FROM borrower_debarments WHERE $where";
-    my $sth   = C4::Context->dbh->prepare($sql);
-    $sth->execute(@values);
-
-    return $sth->fetchall_arrayref( {} );
-}
-
-=head2 AddDebarment
-
-my $success = AddDebarment({
-    borrowernumber => $borrowernumber,
-    expiration     => $expiration,
-    type           => $type, ## enum('FINES','OVERDUES','MANUAL')
-    comment        => $comment,
-});
-
-Creates a new debarment.
-
-Required keys: borrowernumber, type
-
-=cut
-
-sub AddDebarment {
-    my ($params) = @_;
-
-    my $borrowernumber = $params->{'borrowernumber'};
-    my $expiration     = $params->{'expiration'} || undef;
-    my $type           = $params->{'type'} || 'MANUAL';
-    my $comment        = $params->{'comment'} || undef;
-
-    return unless ( $borrowernumber && $type );
-
-    my $manager_id;
-    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
-
-    my $sql = "
-        INSERT INTO borrower_debarments ( borrowernumber, expiration, type, comment, manager_id, created )
-        VALUES ( ?, ?, ?, ?, ?, NOW() )
-    ";
-
-    my $r = C4::Context->dbh->do( $sql, {}, ( $borrowernumber, $expiration, $type, $comment, $manager_id ) );
-
-    _UpdateBorrowerDebarmentFlags($borrowernumber);
-
-    return $r;
-}
-
-=head2 DelDebarment
-
-my $success = DelDebarment( $borrower_debarment_id );
-
-Deletes a debarment.
-
-=cut
-
-sub DelDebarment {
-    my ($id) = @_;
-
-    my $borrowernumber = _GetBorrowernumberByDebarmentId($id);
-
-    my $sql = "DELETE FROM borrower_debarments WHERE borrower_debarment_id = ?";
-
-    my $r = C4::Context->dbh->do( $sql, {}, ($id) );
-
-    _UpdateBorrowerDebarmentFlags($borrowernumber);
-
-    return $r;
-}
-
-=head2 ModDebarment
-
-my $success = ModDebarment({
-    borrower_debarment_id => $borrower_debarment_id,
-    expiration            => $expiration,
-    type                  => $type, ## enum('FINES','OVERDUES','MANUAL','DISCHARGE')
-    comment               => $comment,
-});
-
-Updates an existing debarment.
-
-Required keys: borrower_debarment_id
-
-=cut
-
-sub ModDebarment {
-    my ($params) = @_;
-
-    my $borrower_debarment_id = $params->{'borrower_debarment_id'};
-
-    return unless ($borrower_debarment_id);
-
-    delete( $params->{'borrower_debarment_id'} );
-
-    delete( $params->{'created'} );
-    delete( $params->{'updated'} );
-
-    $params->{'manager_id'} = C4::Context->userenv->{'number'} if C4::Context->userenv;
-
-    my @keys   = keys %$params;
-    my @values = values %$params;
-
-    my $sql = join( ',', map { "$_ = ?" } @keys );
-
-    $sql = "UPDATE borrower_debarments SET $sql, updated = NOW() WHERE borrower_debarment_id = ?";
-
-    my $r = C4::Context->dbh->do( $sql, {}, ( @values, $borrower_debarment_id ) );
-
-    _UpdateBorrowerDebarmentFlags( _GetBorrowernumberByDebarmentId($borrower_debarment_id) );
-
-    return $r;
-}
-
-=head2 IsDebarred
-
-my $debarment_expiration = IsDebarred( $borrowernumber );
-
-Returns the date a borrowers debarment will expire, or
-undef if the borrower is not debarred
-
-=cut
-
-sub IsDebarred {
-    my ($borrowernumber) = @_;
-
-    return unless ($borrowernumber);
-
-    my $sql = "SELECT debarred FROM borrowers WHERE borrowernumber = ? AND debarred > CURRENT_DATE()";
-    my $sth = C4::Context->dbh->prepare($sql);
-    $sth->execute($borrowernumber);
-    my ($debarred) = $sth->fetchrow_array();
-
-    return $debarred;
-}
-
-=head2 AddUniqueDebarment
-
-my $success = AddUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    type           => $type,
-    expiration     => $expiration,
-    comment        => $comment,
-});
-
-Creates a new debarment of the type defined by the key type.
-If a unique debarment already exists of the given type, it is updated instead.
-The current unique debarment types are OVERDUES, and SUSPENSION
-
-Required keys: borrowernumber, type
-
-=cut
-
-sub AddUniqueDebarment {
-    my ($params) = @_;
-
-    my $borrowernumber = $params->{'borrowernumber'};
-    my $type           = $params->{'type'};
-
-    return unless ( $borrowernumber && $type );
-
-    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
-
-    my $r;
-    if ($debarment) {
-
-        # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead
-        $params->{'expiration'} = $debarment->{'expiration'}
-          if ( $debarment->{'expiration'}
-            && $debarment->{'expiration'} gt $params->{'expiration'} );
-
-        $params->{'borrower_debarment_id'} =
-          $debarment->{'borrower_debarment_id'};
-        $r = ModDebarment($params);
-    } else {
-
-        $r = AddDebarment($params);
-    }
-
-    _UpdateBorrowerDebarmentFlags($borrowernumber);
-
-    return $r;
-}
-
-=head2 DelUniqueDebarment
-
-my $success = _DelUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    type           => $type,
-});
-
-Deletes a unique debarment of the type defined by the key type.
-The current unique debarment types are OVERDUES, and SUSPENSION
-
-Required keys: borrowernumber, type
-
-=cut
-
-sub DelUniqueDebarment {
-    my ($params) = @_;
-
-    my $borrowernumber = $params->{'borrowernumber'};
-    my $type           = $params->{'type'};
-
-    return unless ( $borrowernumber && $type );
-
-    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
-
-    return unless ( $debarment );
-
-    return DelDebarment( $debarment->{'borrower_debarment_id'} );
-}
-
-=head2 _UpdateBorrowerDebarmentFlags
-
-my $success = _UpdateBorrowerDebarmentFlags( $borrowernumber );
-
-So as not to create additional latency, the fields borrowers.debarred
-and borrowers.debarredcomment remain in the borrowers table. Whenever
-the a borrowers debarrments are modified, this subroutine is run to
-decide if the borrower is currently debarred and update the 'quick flags'
-in the borrowers table accordingly.
-
-=cut
-
-sub _UpdateBorrowerDebarmentFlags {
-    my ($borrowernumber) = @_;
-
-    return unless ($borrowernumber);
-
-    my $dbh = C4::Context->dbh;
-
-    my $sql = q{
-        SELECT COUNT(*), COUNT(*) - COUNT(expiration), MAX(expiration), GROUP_CONCAT(comment SEPARATOR '\n') FROM borrower_debarments
-        WHERE ( expiration > CURRENT_DATE() OR expiration IS NULL ) AND borrowernumber = ?
-    };
-    my $sth = $dbh->prepare($sql);
-    $sth->execute($borrowernumber);
-    my ( $count, $indefinite_expiration, $expiration, $comment ) = $sth->fetchrow_array();
-
-    if ($count) {
-        $expiration = "9999-12-31" if ($indefinite_expiration);
-    } else {
-        $expiration = undef;
-        $comment    = undef;
-    }
-
-    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
-}
-
-=head2 _GetBorrowernumberByDebarmentId
-
-my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
-
-=cut
-
-sub _GetBorrowernumberByDebarmentId {
-    my ($borrower_debarment_id) = @_;
-
-    return unless ($borrower_debarment_id);
-
-    my $sql = "SELECT borrowernumber FROM borrower_debarments WHERE borrower_debarment_id = ?";
-    my $sth = C4::Context->dbh->prepare($sql);
-    $sth->execute($borrower_debarment_id);
-    my ($borrowernumber) = $sth->fetchrow_array();
-
-    return $borrowernumber;
-}
-
-1;
-
-=head2 AUTHOR
-
-Kyle M Hall <kyle@bywatersoltuions.com>
-
-=cut
diff --git a/Koha/Borrower/Discharge.pm b/Koha/Borrower/Discharge.pm
deleted file mode 100644 (file)
index bbfab56..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-package Koha::Borrower::Discharge;
-
-use Modern::Perl;
-use CGI;
-use File::Temp qw( :POSIX );
-use Carp;
-
-use C4::Templates qw ( gettemplate );
-use C4::Members qw( GetPendingIssues );
-use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
-
-use Koha::Database;
-use Koha::DateUtils qw( dt_from_string output_pref );
-
-my $rs = Koha::Database->new->schema->resultset('Discharge');
-
-sub count {
-    my ($params) = @_;
-    my $values = {};
-
-    if( $params->{borrowernumber} ) {
-        $values->{borrower} = $params->{borrowernumber};
-    }
-    if( $params->{pending} ) {
-        $values->{needed} = { '!=', undef };
-        $values->{validated} = undef;
-    }
-    elsif( $params->{validated} ) {
-        $values->{validated} = { '!=', undef };
-    }
-
-    return $rs->search( $values )->count;
-}
-
-sub can_be_discharged {
-    my ($params) = @_;
-    return unless $params->{borrowernumber};
-
-    my $issues = GetPendingIssues( $params->{borrowernumber} );
-    if( @$issues ) {
-        return 0;
-    }
-    else {
-        return 1;
-    }
-}
-
-sub is_discharged {
-    my ($params) = @_;
-    return unless $params->{borrowernumber};
-    my $borrowernumber = $params->{borrowernumber};
-
-
-    my $restricted = Koha::Borrower::Debarments::IsDebarred($borrowernumber);
-    my $validated = get_validated({borrowernumber => $borrowernumber});
-
-    if ($restricted && $validated) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
-sub request {
-    my ($params) = @_;
-    my $borrowernumber = $params->{borrowernumber};
-    return unless $borrowernumber;
-    return unless can_be_discharged({ borrowernumber => $borrowernumber });
-
-    return $rs->create({
-        borrower => $borrowernumber,
-        needed   => dt_from_string,
-    });
-}
-
-sub discharge {
-    my ($params) = @_;
-    my $borrowernumber = $params->{borrowernumber};
-    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
-
-    # Cancel reserves
-    my @reserves = GetReservesFromBorrowernumber($borrowernumber);
-    for my $reserve (@reserves) {
-        CancelReserve( { reserve_id => $reserve->{reserve_id} } );
-    }
-
-    # Debar the member
-    Koha::Borrower::Debarments::AddDebarment({
-        borrowernumber => $borrowernumber,
-        type           => 'DISCHARGE',
-    });
-
-    # Generate the discharge
-    my $discharge = $rs->search({ borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 });
-    if( $discharge->count > 0 ) {
-        $discharge->update({ validated => dt_from_string });
-    }
-    else {
-        $rs->create({
-            borrower  => $borrowernumber,
-            validated => dt_from_string,
-        });
-    }
-}
-
-sub generate_as_pdf {
-    my ($params) = @_;
-    return unless $params->{borrowernumber};
-
-    my $letter = C4::Letters::GetPreparedLetter(
-        module      => 'members',
-        letter_code => 'DISCHARGE',
-        tables      => { borrowers => $params->{borrowernumber}, branches => $params->{'branchcode'}, },
-    );
-
-    my $today = output_pref( dt_from_string() );
-    $letter->{'title'}   =~ s/<<today>>/$today/g;
-    $letter->{'content'} =~ s/<<today>>/$today/g;
-
-    my $tmpl = C4::Templates::gettemplate('batch/print-notices.tt', 'intranet', new CGI);
-    $tmpl->param(
-        stylesheet => C4::Context->preference("NoticeCSS"),
-        today      => $today,
-        messages   => [$letter],
-    );
-
-    my $html_path = tmpnam() . '.html';
-    my $pdf_path = tmpnam() . '.pdf';
-    my $html_content = $tmpl->output;
-    open my $html_fh, '>:encoding(utf8)', $html_path;
-    say $html_fh $html_content;
-    close $html_fh;
-    my $output = eval { require PDF::FromHTML; return; } || $@;
-    if ($output && $params->{testing}) {
-        carp $output;
-        $pdf_path = undef;
-    }
-    elsif ($output) {
-        die $output;
-    }
-    else {
-        my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
-        $pdf->load_file( $html_path );
-        $pdf->convert;
-        $pdf->write_file( $pdf_path );
-    }
-
-    return $pdf_path;
-}
-
-sub get_pendings {
-    my ($params)       = @_;
-    my $branchcode     = $params->{branchcode};
-    my $borrowernumber = $params->{borrowernumber};
-
-    my $cond = {
-        'me.needed'    => { '!=', undef },
-        'me.validated' => undef,
-        ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
-        ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
-    };
-
-    my @rs = $rs->search( $cond, { join => 'borrower' } );
-    return \@rs;
-}
-
-sub get_validated {
-    my ($params)       = @_;
-    my $branchcode     = $params->{branchcode};
-    my $borrowernumber = $params->{borrowernumber};
-
-    my $cond = {
-        'me.validated' => { '!=', undef },
-        ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
-        ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
-    };
-
-    my @rs = $rs->search( $cond, { join => 'borrower' } );
-    return \@rs;
-}
-
-
-1;
diff --git a/Koha/Borrower/Files.pm b/Koha/Borrower/Files.pm
deleted file mode 100644 (file)
index 028757d..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-package Koha::Borrower::Files;
-
-# Copyright 2012 Kyle M Hall
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use vars qw($VERSION);
-
-use C4::Context;
-use C4::Output;
-use C4::Debug;
-
-BEGIN {
-
-    # set the version for version checking
-    $VERSION = 0.01;
-}
-
-=head1 NAME
-
-Koha::Borrower::Files - Module for managing borrower files
-
-=head1 METHODS
-
-=over
-
-=cut
-
-sub new {
-    my ( $class, %args ) = @_;
-    my $self = bless( {}, $class );
-
-    $self->{'borrowernumber'} = $args{'borrowernumber'};
-
-    return $self;
-}
-
-=item GetFilesInfo()
-
-    my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
-    my $files_hashref = $bf->GetFilesInfo
-
-=cut
-
-sub GetFilesInfo {
-    my $self = shift;
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT
-            file_id,
-            file_name,
-            file_type,
-            file_description,
-            date_uploaded
-        FROM borrower_files
-        WHERE borrowernumber = ?
-        ORDER BY file_name, date_uploaded
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $self->{'borrowernumber'} );
-    return $sth->fetchall_arrayref( {} );
-}
-
-=item AddFile()
-
-    my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
-    $bh->AddFile( name => $filename, type => $mimetype,
-                  description => $description, content => $content );
-
-=cut
-
-sub AddFile {
-    my ( $self, %args ) = @_;
-
-    my $name        = $args{'name'};
-    my $type        = $args{'type'};
-    my $description = $args{'description'};
-    my $content     = $args{'content'};
-
-    return unless ( $name && $content );
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
-        VALUES ( ?,?,?,?,? )
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $self->{'borrowernumber'},
-        $name, $type, $description, $content );
-}
-
-=item GetFile()
-
-    my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
-    my $file = $bh->GetFile( file_id => $file_id );
-
-=cut
-
-sub GetFile {
-    my ( $self, %args ) = @_;
-
-    my $file_id = $args{'id'};
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $file_id, $self->{'borrowernumber'} );
-    return $sth->fetchrow_hashref();
-}
-
-=item DelFile()
-
-    my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
-    $bh->DelFile( file_id => $file_id );
-
-=cut
-
-sub DelFile {
-    my ( $self, %args ) = @_;
-
-    my $file_id = $args{'id'};
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $file_id, $self->{'borrowernumber'} );
-}
-
-1;
-__END__
-
-=back
-
-=head1 AUTHOR
-
-Kyle M Hall <kyle.m.hall@gmail.com>
-
-=cut
diff --git a/Koha/Borrower/Modifications.pm b/Koha/Borrower/Modifications.pm
deleted file mode 100644 (file)
index 12cee66..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-package Koha::Borrower::Modifications;
-
-# Copyright 2012 ByWater Solutions
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-=head1 NAME
-
-C4::Borrowers::Modifications
-
-=cut
-
-use Modern::Perl;
-
-use C4::Context;
-use C4::Debug;
-
-sub new {
-    my ( $class, %args ) = @_;
-
-    return bless( \%args, $class );
-}
-
-=head2 AddModifications
-
-Koha::Borrower::Modifications->AddModifications( $data );
-
-Adds or updates modifications for a borrower.
-
-Requires either the key borrowernumber, or verification_token
-to be part of the passed in hash.
-
-=cut
-
-sub AddModifications {
-    my ( $self, $data ) = @_;
-
-    delete $data->{borrowernumber};
-    if( $self->{borrowernumber} ) {
-        return if( not keys %$data );
-        $data->{borrowernumber} = $self->{borrowernumber};
-        $data->{verification_token} = '';
-    }
-    elsif( $self->{verification_token} ) {
-        $data->{verification_token} = $self->{verification_token};
-        $data->{borrowernumber} = 0;
-    }
-    else {
-        return;
-    }
-
-    my $rs = Koha::Database->new()->schema->resultset('BorrowerModification');
-    return $rs->update_or_create($data, { key => 'primary' } );
-}
-
-=head2 Verify
-
-$verified = Koha::Borrower::Modifications->Verify( $verification_token );
-
-Returns true if the passed in token is valid.
-
-=cut
-
-sub Verify {
-    my ( $self, $verification_token ) = @_;
-
-    $verification_token =
-      ($verification_token)
-      ? $verification_token
-      : $self->{'verification_token'};
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT COUNT(*) AS count
-        FROM borrower_modifications
-        WHERE verification_token = ?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($verification_token);
-    my $result = $sth->fetchrow_hashref();
-
-    return $result->{'count'};
-}
-
-=head2 GetPendingModificationsCount
-
-$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
-
-Returns the number of pending modifications for existing borrowers.
-
-=cut
-
-sub GetPendingModificationsCount {
-    my ( $self, $branchcode ) = @_;
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT COUNT(*) AS count
-        FROM borrower_modifications, borrowers
-        WHERE borrower_modifications.borrowernumber > 0
-        AND borrower_modifications.borrowernumber = borrowers.borrowernumber
-    ";
-
-    my @params;
-    if ($branchcode) {
-        $query .= " AND borrowers.branchcode = ? ";
-        push( @params, $branchcode );
-    }
-
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@params);
-    my $result = $sth->fetchrow_hashref();
-
-    return $result->{'count'};
-}
-
-=head2 GetPendingModifications
-
-$arrayref = Koha::Borrower::Modifications->GetPendingModifications();
-
-Returns an arrayref of hashrefs for all pending modifications for existing borrowers.
-
-=cut
-
-sub GetPendingModifications {
-    my ( $self, $branchcode ) = @_;
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT borrower_modifications.*
-        FROM borrower_modifications, borrowers
-        WHERE borrower_modifications.borrowernumber > 0
-        AND borrower_modifications.borrowernumber = borrowers.borrowernumber
-    ";
-
-    my @params;
-    if ($branchcode) {
-        $query .= " AND borrowers.branchcode = ? ";
-        push( @params, $branchcode );
-    }
-    $query .= " ORDER BY borrowers.surname, borrowers.firstname";
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@params);
-
-    my @m;
-    while ( my $row = $sth->fetchrow_hashref() ) {
-        foreach my $key ( keys %$row ) {
-            delete $row->{$key} unless defined $row->{$key};
-        }
-
-        push( @m, $row );
-    }
-
-    return \@m;
-}
-
-=head2 ApproveModifications
-
-Koha::Borrower::Modifications->ApproveModifications( $borrowernumber );
-
-Commits the pending modifications to the borrower record and removes
-them from the modifications table.
-
-=cut
-
-sub ApproveModifications {
-    my ( $self, $borrowernumber ) = @_;
-
-    $borrowernumber =
-      ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
-
-    return unless $borrowernumber;
-
-    my $data = $self->GetModifications( { borrowernumber => $borrowernumber } );
-    delete $data->{timestamp};
-    delete $data->{verification_token};
-
-    my $rs = Koha::Database->new()->schema->resultset('Borrower')->search({
-        borrowernumber => $data->{borrowernumber},
-    });
-    if( $rs->update($data) ) {
-        $self->DelModifications( { borrowernumber => $borrowernumber } );
-    }
-}
-
-=head2 DenyModifications
-
-Koha::Borrower::Modifications->DenyModifications( $borrowernumber );
-
-Removes the modifications from the table for the given borrower,
-without commiting the changes to the borrower record.
-
-=cut
-
-sub DenyModifications {
-    my ( $self, $borrowernumber ) = @_;
-
-    $borrowernumber =
-      ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
-
-    return unless $borrowernumber;
-
-    return $self->DelModifications( { borrowernumber => $borrowernumber } );
-}
-
-=head2 DelModifications
-
-Koha::Borrower::Modifications->DelModifications({
-  [ borrowernumber => $borrowernumber ],
-  [ verification_token => $verification_token ]
-});
-
-Deletes the modifications for the given borrowernumber or verification token.
-
-=cut
-
-sub DelModifications {
-    my ( $self, $params ) = @_;
-
-    my ( $field, $value );
-
-    if ( $params->{'borrowernumber'} ) {
-        $field = 'borrowernumber';
-        $value = $params->{'borrowernumber'};
-    }
-    elsif ( $params->{'verification_token'} ) {
-        $field = 'verification_token';
-        $value = $params->{'verification_token'};
-    }
-
-    return unless $value;
-
-    my $dbh = C4::Context->dbh;
-
-    $field = $dbh->quote_identifier($field);
-
-    my $query = "
-        DELETE
-        FROM borrower_modifications
-        WHERE $field = ?
-    ";
-
-    my $sth = $dbh->prepare($query);
-    return $sth->execute($value);
-}
-
-=head2 GetModifications
-
-$hashref = Koha::Borrower::Modifications->GetModifications({
-  [ borrowernumber => $borrowernumber ],
-  [ verification_token => $verification_token ]
-});
-
-Gets the modifications for the given borrowernumber or verification token.
-
-=cut
-
-sub GetModifications {
-    my ( $self, $params ) = @_;
-
-    my ( $field, $value );
-
-    if ( defined( $params->{'borrowernumber'} ) ) {
-        $field = 'borrowernumber';
-        $value = $params->{'borrowernumber'};
-    }
-    elsif ( defined( $params->{'verification_token'} ) ) {
-        $field = 'verification_token';
-        $value = $params->{'verification_token'};
-    }
-
-    return unless $value;
-
-    my $dbh = C4::Context->dbh;
-
-    $field = $dbh->quote_identifier($field);
-
-    my $query = "
-        SELECT *
-        FROM borrower_modifications
-        WHERE $field = ?
-    ";
-
-    my $sth = $dbh->prepare($query);
-    $sth->execute($value);
-    my $data = $sth->fetchrow_hashref();
-
-    foreach my $key ( keys %$data ) {
-        delete $data->{$key} unless ( defined( $data->{$key} ) );
-    }
-
-    return $data;
-}
-
-1;
diff --git a/Koha/Borrowers.pm b/Koha/Borrowers.pm
deleted file mode 100644 (file)
index f532d6f..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package Koha::Borrowers;
-
-# Copyright ByWater Solutions 2014
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Carp;
-
-use Koha::Database;
-
-use Koha::Borrower;
-
-use base qw(Koha::Objects);
-
-=head1 NAME
-
-Koha::Borrower - Koha Borrower Object class
-
-=head1 API
-
-=head2 Class Methods
-
-=cut
-
-=head3 type
-
-=cut
-
-sub _type {
-    return 'Borrower';
-}
-
-sub object_class {
-    return 'Koha::Borrower';
-}
-
-=head1 AUTHOR
-
-Kyle M Hall <kyle@bywatersolutions.com>
-
-=cut
-
-1;
index e54bc13..f4d541a 100644 (file)
@@ -24,7 +24,7 @@ use Carp;
 use C4::Context qw(preference);
 
 use Koha::DateUtils qw(dt_from_string);
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::Biblios;
 use Koha::Items;
 use Koha::Libraries;
@@ -223,14 +223,14 @@ sub branch {
 
 =head3 borrower
 
-Returns the related Koha::Borrower object for this Hold
+Returns the related Koha::Patron object for this Hold
 
 =cut
 
 sub borrower {
     my ($self) = @_;
 
-    $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() );
+    $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
 
     return $self->{_borrower};
 }
index 0199f37..d721537 100644 (file)
@@ -23,7 +23,7 @@ use Carp;
 
 use Koha::Database;
 
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::Libraries;
 
 use base qw(Koha::Object);
@@ -78,7 +78,7 @@ sub holding_branch {
 
 Gets and sets the last borrower to return an item.
 
-Accepts and returns Koha::Borrower objects
+Accepts and returns Koha::Patron objects
 
 $item->last_returned_by( $borrowernumber );
 
@@ -99,7 +99,7 @@ sub last_returned_by {
         unless ( $self->{_last_returned_by} ) {
             my $result = $items_last_returned_by_rs->single( { itemnumber => $self->id } );
             if ($result) {
-                $self->{_last_returned_by} = Koha::Borrowers->find( $result->get_column('borrowernumber') );
+                $self->{_last_returned_by} = Koha::Patrons->find( $result->get_column('borrowernumber') );
             }
         }
 
index e358f28..d722760 100644 (file)
@@ -255,7 +255,7 @@ __END__
 
 =head1 SEE ALSO
 
-Koha::Borrower::Files
+Koha::Patron::Files
 
 =head1 AUTHOR
 
diff --git a/Koha/Patron.pm b/Koha/Patron.pm
new file mode 100644 (file)
index 0000000..873ec75
--- /dev/null
@@ -0,0 +1,64 @@
+package Koha::Patron;
+
+# Copyright ByWater Solutions 2014
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Patron - Koha Patron Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 guarantor
+
+Returns a Koha::Patron object for this patron's guarantor
+
+=cut
+
+sub guarantor {
+    my ( $self ) = @_;
+
+    return Koha::Patrons->find( $self->guarantorid() );
+}
+
+=head3 type
+
+=cut
+
+sub _type {
+    return 'Borrower';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm
new file mode 100644 (file)
index 0000000..c305ba9
--- /dev/null
@@ -0,0 +1,333 @@
+package Koha::Patron::Debarments;
+
+# This file is part of Koha.
+#
+# Copyright 2013 ByWater Solutions
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use C4::Context;
+
+use parent qw( Exporter );
+
+our @EXPORT = qw(
+  GetDebarments
+
+  AddDebarment
+  DelDebarment
+  ModDebarment
+
+  AddUniqueDebarment
+  DelUniqueDebarment
+
+  IsDebarred
+);
+
+=head1 Koha::Patron::Debarments
+
+Koha::Patron::Debarments - Module for managing patron debarments
+
+=cut
+
+=head2 GetDebarments
+
+my $arrayref = GetDebarments({ borrowernumber => $borrowernumber [, key => $value ] );
+
+=cut
+
+sub GetDebarments {
+    my ($params) = @_;
+
+    return unless ( $params->{'borrowernumber'} );
+
+    my @keys   = keys %$params;
+    my @values = values %$params;
+
+    my $where = join( ' AND ', map { "$_ = ?" } @keys );
+    my $sql   = "SELECT * FROM borrower_debarments WHERE $where";
+    my $sth   = C4::Context->dbh->prepare($sql);
+    $sth->execute(@values);
+
+    return $sth->fetchall_arrayref( {} );
+}
+
+=head2 AddDebarment
+
+my $success = AddDebarment({
+    borrowernumber => $borrowernumber,
+    expiration     => $expiration,
+    type           => $type, ## enum('FINES','OVERDUES','MANUAL')
+    comment        => $comment,
+});
+
+Creates a new debarment.
+
+Required keys: borrowernumber, type
+
+=cut
+
+sub AddDebarment {
+    my ($params) = @_;
+
+    my $borrowernumber = $params->{'borrowernumber'};
+    my $expiration     = $params->{'expiration'} || undef;
+    my $type           = $params->{'type'} || 'MANUAL';
+    my $comment        = $params->{'comment'} || undef;
+
+    return unless ( $borrowernumber && $type );
+
+    my $manager_id;
+    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
+
+    my $sql = "
+        INSERT INTO borrower_debarments ( borrowernumber, expiration, type, comment, manager_id, created )
+        VALUES ( ?, ?, ?, ?, ?, NOW() )
+    ";
+
+    my $r = C4::Context->dbh->do( $sql, {}, ( $borrowernumber, $expiration, $type, $comment, $manager_id ) );
+
+    _UpdateBorrowerDebarmentFlags($borrowernumber);
+
+    return $r;
+}
+
+=head2 DelDebarment
+
+my $success = DelDebarment( $borrower_debarment_id );
+
+Deletes a debarment.
+
+=cut
+
+sub DelDebarment {
+    my ($id) = @_;
+
+    my $borrowernumber = _GetBorrowernumberByDebarmentId($id);
+
+    my $sql = "DELETE FROM borrower_debarments WHERE borrower_debarment_id = ?";
+
+    my $r = C4::Context->dbh->do( $sql, {}, ($id) );
+
+    _UpdateBorrowerDebarmentFlags($borrowernumber);
+
+    return $r;
+}
+
+=head2 ModDebarment
+
+my $success = ModDebarment({
+    borrower_debarment_id => $borrower_debarment_id,
+    expiration            => $expiration,
+    type                  => $type, ## enum('FINES','OVERDUES','MANUAL','DISCHARGE')
+    comment               => $comment,
+});
+
+Updates an existing debarment.
+
+Required keys: borrower_debarment_id
+
+=cut
+
+sub ModDebarment {
+    my ($params) = @_;
+
+    my $borrower_debarment_id = $params->{'borrower_debarment_id'};
+
+    return unless ($borrower_debarment_id);
+
+    delete( $params->{'borrower_debarment_id'} );
+
+    delete( $params->{'created'} );
+    delete( $params->{'updated'} );
+
+    $params->{'manager_id'} = C4::Context->userenv->{'number'} if C4::Context->userenv;
+
+    my @keys   = keys %$params;
+    my @values = values %$params;
+
+    my $sql = join( ',', map { "$_ = ?" } @keys );
+
+    $sql = "UPDATE borrower_debarments SET $sql, updated = NOW() WHERE borrower_debarment_id = ?";
+
+    my $r = C4::Context->dbh->do( $sql, {}, ( @values, $borrower_debarment_id ) );
+
+    _UpdateBorrowerDebarmentFlags( _GetBorrowernumberByDebarmentId($borrower_debarment_id) );
+
+    return $r;
+}
+
+=head2 IsDebarred
+
+my $debarment_expiration = IsDebarred( $borrowernumber );
+
+Returns the date a borrowers debarment will expire, or
+undef if the patron is not debarred
+
+=cut
+
+sub IsDebarred {
+    my ($borrowernumber) = @_;
+
+    return unless ($borrowernumber);
+
+    my $sql = "SELECT debarred FROM borrowers WHERE borrowernumber = ? AND debarred > CURRENT_DATE()";
+    my $sth = C4::Context->dbh->prepare($sql);
+    $sth->execute($borrowernumber);
+    my ($debarred) = $sth->fetchrow_array();
+
+    return $debarred;
+}
+
+=head2 AddUniqueDebarment
+
+my $success = AddUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    type           => $type,
+    expiration     => $expiration,
+    comment        => $comment,
+});
+
+Creates a new debarment of the type defined by the key type.
+If a unique debarment already exists of the given type, it is updated instead.
+The current unique debarment types are OVERDUES, and SUSPENSION
+
+Required keys: borrowernumber, type
+
+=cut
+
+sub AddUniqueDebarment {
+    my ($params) = @_;
+
+    my $borrowernumber = $params->{'borrowernumber'};
+    my $type           = $params->{'type'};
+
+    return unless ( $borrowernumber && $type );
+
+    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
+
+    my $r;
+    if ($debarment) {
+
+        # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead
+        $params->{'expiration'} = $debarment->{'expiration'}
+          if ( $debarment->{'expiration'}
+            && $debarment->{'expiration'} gt $params->{'expiration'} );
+
+        $params->{'borrower_debarment_id'} =
+          $debarment->{'borrower_debarment_id'};
+        $r = ModDebarment($params);
+    } else {
+
+        $r = AddDebarment($params);
+    }
+
+    _UpdateBorrowerDebarmentFlags($borrowernumber);
+
+    return $r;
+}
+
+=head2 DelUniqueDebarment
+
+my $success = _DelUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    type           => $type,
+});
+
+Deletes a unique debarment of the type defined by the key type.
+The current unique debarment types are OVERDUES, and SUSPENSION
+
+Required keys: borrowernumber, type
+
+=cut
+
+sub DelUniqueDebarment {
+    my ($params) = @_;
+
+    my $borrowernumber = $params->{'borrowernumber'};
+    my $type           = $params->{'type'};
+
+    return unless ( $borrowernumber && $type );
+
+    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
+
+    return unless ( $debarment );
+
+    return DelDebarment( $debarment->{'borrower_debarment_id'} );
+}
+
+=head2 _UpdateBorrowerDebarmentFlags
+
+my $success = _UpdateBorrowerDebarmentFlags( $borrowernumber );
+
+So as not to create additional latency, the fields borrowers.debarred
+and borrowers.debarredcomment remain in the borrowers table. Whenever
+the a borrowers debarrments are modified, this subroutine is run to
+decide if the borrower is currently debarred and update the 'quick flags'
+in the borrowers table accordingly.
+
+=cut
+
+sub _UpdateBorrowerDebarmentFlags {
+    my ($borrowernumber) = @_;
+
+    return unless ($borrowernumber);
+
+    my $dbh = C4::Context->dbh;
+
+    my $sql = q{
+        SELECT COUNT(*), COUNT(*) - COUNT(expiration), MAX(expiration), GROUP_CONCAT(comment SEPARATOR '\n') FROM borrower_debarments
+        WHERE ( expiration > CURRENT_DATE() OR expiration IS NULL ) AND borrowernumber = ?
+    };
+    my $sth = $dbh->prepare($sql);
+    $sth->execute($borrowernumber);
+    my ( $count, $indefinite_expiration, $expiration, $comment ) = $sth->fetchrow_array();
+
+    if ($count) {
+        $expiration = "9999-12-31" if ($indefinite_expiration);
+    } else {
+        $expiration = undef;
+        $comment    = undef;
+    }
+
+    return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) );
+}
+
+=head2 _GetBorrowernumberByDebarmentId
+
+my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id );
+
+=cut
+
+sub _GetBorrowernumberByDebarmentId {
+    my ($borrower_debarment_id) = @_;
+
+    return unless ($borrower_debarment_id);
+
+    my $sql = "SELECT borrowernumber FROM borrower_debarments WHERE borrower_debarment_id = ?";
+    my $sth = C4::Context->dbh->prepare($sql);
+    $sth->execute($borrower_debarment_id);
+    my ($borrowernumber) = $sth->fetchrow_array();
+
+    return $borrowernumber;
+}
+
+1;
+
+=head2 AUTHOR
+
+Kyle M Hall <kyle@bywatersoltuions.com>
+
+=cut
diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm
new file mode 100644 (file)
index 0000000..4b775dc
--- /dev/null
@@ -0,0 +1,183 @@
+package Koha::Patron::Discharge;
+
+use Modern::Perl;
+use CGI;
+use File::Temp qw( :POSIX );
+use Carp;
+
+use C4::Templates qw ( gettemplate );
+use C4::Members qw( GetPendingIssues );
+use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
+
+use Koha::Database;
+use Koha::DateUtils qw( dt_from_string output_pref );
+
+my $rs = Koha::Database->new->schema->resultset('Discharge');
+
+sub count {
+    my ($params) = @_;
+    my $values = {};
+
+    if( $params->{borrowernumber} ) {
+        $values->{borrower} = $params->{borrowernumber};
+    }
+    if( $params->{pending} ) {
+        $values->{needed} = { '!=', undef };
+        $values->{validated} = undef;
+    }
+    elsif( $params->{validated} ) {
+        $values->{validated} = { '!=', undef };
+    }
+
+    return $rs->search( $values )->count;
+}
+
+sub can_be_discharged {
+    my ($params) = @_;
+    return unless $params->{borrowernumber};
+
+    my $issues = GetPendingIssues( $params->{borrowernumber} );
+    if( @$issues ) {
+        return 0;
+    }
+    else {
+        return 1;
+    }
+}
+
+sub is_discharged {
+    my ($params) = @_;
+    return unless $params->{borrowernumber};
+    my $borrowernumber = $params->{borrowernumber};
+
+
+    my $restricted = Koha::Patron::Debarments::IsDebarred($borrowernumber);
+    my $validated = get_validated({borrowernumber => $borrowernumber});
+
+    if ($restricted && $validated) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+sub request {
+    my ($params) = @_;
+    my $borrowernumber = $params->{borrowernumber};
+    return unless $borrowernumber;
+    return unless can_be_discharged({ borrowernumber => $borrowernumber });
+
+    return $rs->create({
+        borrower => $borrowernumber,
+        needed   => dt_from_string,
+    });
+}
+
+sub discharge {
+    my ($params) = @_;
+    my $borrowernumber = $params->{borrowernumber};
+    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
+
+    # Cancel reserves
+    my @reserves = GetReservesFromBorrowernumber($borrowernumber);
+    for my $reserve (@reserves) {
+        CancelReserve( { reserve_id => $reserve->{reserve_id} } );
+    }
+
+    # Debar the member
+    Koha::Patron::Debarments::AddDebarment({
+        borrowernumber => $borrowernumber,
+        type           => 'DISCHARGE',
+    });
+
+    # Generate the discharge
+    my $discharge = $rs->search({ borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 });
+    if( $discharge->count > 0 ) {
+        $discharge->update({ validated => dt_from_string });
+    }
+    else {
+        $rs->create({
+            borrower  => $borrowernumber,
+            validated => dt_from_string,
+        });
+    }
+}
+
+sub generate_as_pdf {
+    my ($params) = @_;
+    return unless $params->{borrowernumber};
+
+    my $letter = C4::Letters::GetPreparedLetter(
+        module      => 'members',
+        letter_code => 'DISCHARGE',
+        tables      => { borrowers => $params->{borrowernumber}, branches => $params->{'branchcode'}, },
+    );
+
+    my $today = output_pref( dt_from_string() );
+    $letter->{'title'}   =~ s/<<today>>/$today/g;
+    $letter->{'content'} =~ s/<<today>>/$today/g;
+
+    my $tmpl = C4::Templates::gettemplate('batch/print-notices.tt', 'intranet', new CGI);
+    $tmpl->param(
+        stylesheet => C4::Context->preference("NoticeCSS"),
+        today      => $today,
+        messages   => [$letter],
+    );
+
+    my $html_path = tmpnam() . '.html';
+    my $pdf_path = tmpnam() . '.pdf';
+    my $html_content = $tmpl->output;
+    open my $html_fh, '>:encoding(utf8)', $html_path;
+    say $html_fh $html_content;
+    close $html_fh;
+    my $output = eval { require PDF::FromHTML; return; } || $@;
+    if ($output && $params->{testing}) {
+        carp $output;
+        $pdf_path = undef;
+    }
+    elsif ($output) {
+        die $output;
+    }
+    else {
+        my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
+        $pdf->load_file( $html_path );
+        $pdf->convert;
+        $pdf->write_file( $pdf_path );
+    }
+
+    return $pdf_path;
+}
+
+sub get_pendings {
+    my ($params)       = @_;
+    my $branchcode     = $params->{branchcode};
+    my $borrowernumber = $params->{borrowernumber};
+
+    my $cond = {
+        'me.needed'    => { '!=', undef },
+        'me.validated' => undef,
+        ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
+        ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
+    };
+
+    my @rs = $rs->search( $cond, { join => 'borrower' } );
+    return \@rs;
+}
+
+sub get_validated {
+    my ($params)       = @_;
+    my $branchcode     = $params->{branchcode};
+    my $borrowernumber = $params->{borrowernumber};
+
+    my $cond = {
+        'me.validated' => { '!=', undef },
+        ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
+        ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
+    };
+
+    my @rs = $rs->search( $cond, { join => 'borrower' } );
+    return \@rs;
+}
+
+
+1;
diff --git a/Koha/Patron/Files.pm b/Koha/Patron/Files.pm
new file mode 100644 (file)
index 0000000..9eb5d52
--- /dev/null
@@ -0,0 +1,158 @@
+package Koha::Patron::Files;
+
+# Copyright 2012 Kyle M Hall
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use vars qw($VERSION);
+
+use C4::Context;
+use C4::Output;
+use C4::Debug;
+
+BEGIN {
+
+    # set the version for version checking
+    $VERSION = 0.01;
+}
+
+=head1 NAME
+
+Koha::Patron::Files - Module for managing patron files
+
+=head1 METHODS
+
+=over
+
+=cut
+
+sub new {
+    my ( $class, %args ) = @_;
+    my $self = bless( {}, $class );
+
+    $self->{'borrowernumber'} = $args{'borrowernumber'};
+
+    return $self;
+}
+
+=item GetFilesInfo()
+
+    my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
+    my $files_hashref = $bf->GetFilesInfo
+
+=cut
+
+sub GetFilesInfo {
+    my $self = shift;
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        SELECT
+            file_id,
+            file_name,
+            file_type,
+            file_description,
+            date_uploaded
+        FROM borrower_files
+        WHERE borrowernumber = ?
+        ORDER BY file_name, date_uploaded
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $self->{'borrowernumber'} );
+    return $sth->fetchall_arrayref( {} );
+}
+
+=item AddFile()
+
+    my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
+    $bh->AddFile( name => $filename, type => $mimetype,
+                  description => $description, content => $content );
+
+=cut
+
+sub AddFile {
+    my ( $self, %args ) = @_;
+
+    my $name        = $args{'name'};
+    my $type        = $args{'type'};
+    my $description = $args{'description'};
+    my $content     = $args{'content'};
+
+    return unless ( $name && $content );
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
+        VALUES ( ?,?,?,?,? )
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $self->{'borrowernumber'},
+        $name, $type, $description, $content );
+}
+
+=item GetFile()
+
+    my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
+    my $file = $bh->GetFile( file_id => $file_id );
+
+=cut
+
+sub GetFile {
+    my ( $self, %args ) = @_;
+
+    my $file_id = $args{'id'};
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $file_id, $self->{'borrowernumber'} );
+    return $sth->fetchrow_hashref();
+}
+
+=item DelFile()
+
+    my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
+    $bh->DelFile( file_id => $file_id );
+
+=cut
+
+sub DelFile {
+    my ( $self, %args ) = @_;
+
+    my $file_id = $args{'id'};
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $file_id, $self->{'borrowernumber'} );
+}
+
+1;
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle.m.hall@gmail.com>
+
+=cut
diff --git a/Koha/Patron/Modifications.pm b/Koha/Patron/Modifications.pm
new file mode 100644 (file)
index 0000000..3d9dfdc
--- /dev/null
@@ -0,0 +1,307 @@
+package Koha::Patron::Modifications;
+
+# Copyright 2012 ByWater Solutions
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+=head1 NAME
+
+Koha::Patron::Modifications
+
+=cut
+
+use Modern::Perl;
+
+use C4::Context;
+use C4::Debug;
+
+sub new {
+    my ( $class, %args ) = @_;
+
+    return bless( \%args, $class );
+}
+
+=head2 AddModifications
+
+Koha::Patron::Modifications->AddModifications( $data );
+
+Adds or updates modifications for a patron
+
+Requires either the key borrowernumber, or verification_token
+to be part of the passed in hash.
+
+=cut
+
+sub AddModifications {
+    my ( $self, $data ) = @_;
+
+    delete $data->{borrowernumber};
+    if( $self->{borrowernumber} ) {
+        return if( not keys %$data );
+        $data->{borrowernumber} = $self->{borrowernumber};
+        $data->{verification_token} = '';
+    }
+    elsif( $self->{verification_token} ) {
+        $data->{verification_token} = $self->{verification_token};
+        $data->{borrowernumber} = 0;
+    }
+    else {
+        return;
+    }
+
+    my $rs = Koha::Database->new()->schema->resultset('BorrowerModification');
+    return $rs->update_or_create($data, { key => 'primary' } );
+}
+
+=head2 Verify
+
+$verified = Koha::Patron::Modifications->Verify( $verification_token );
+
+Returns true if the passed in token is valid.
+
+=cut
+
+sub Verify {
+    my ( $self, $verification_token ) = @_;
+
+    $verification_token =
+      ($verification_token)
+      ? $verification_token
+      : $self->{'verification_token'};
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        SELECT COUNT(*) AS count
+        FROM borrower_modifications
+        WHERE verification_token = ?
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute($verification_token);
+    my $result = $sth->fetchrow_hashref();
+
+    return $result->{'count'};
+}
+
+=head2 GetPendingModificationsCount
+
+$count = Koha::Patron::Modifications->GetPendingModificationsCount();
+
+Returns the number of pending modifications for existing patron.
+
+=cut
+
+sub GetPendingModificationsCount {
+    my ( $self, $branchcode ) = @_;
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        SELECT COUNT(*) AS count
+        FROM borrower_modifications, borrowers
+        WHERE borrower_modifications.borrowernumber > 0
+        AND borrower_modifications.borrowernumber = borrowers.borrowernumber
+    ";
+
+    my @params;
+    if ($branchcode) {
+        $query .= " AND borrowers.branchcode = ? ";
+        push( @params, $branchcode );
+    }
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@params);
+    my $result = $sth->fetchrow_hashref();
+
+    return $result->{'count'};
+}
+
+=head2 GetPendingModifications
+
+$arrayref = Koha::Patron::Modifications->GetPendingModifications();
+
+Returns an arrayref of hashrefs for all pending modifications for existing patrons.
+
+=cut
+
+sub GetPendingModifications {
+    my ( $self, $branchcode ) = @_;
+
+    my $dbh   = C4::Context->dbh;
+    my $query = "
+        SELECT borrower_modifications.*
+        FROM borrower_modifications, borrowers
+        WHERE borrower_modifications.borrowernumber > 0
+        AND borrower_modifications.borrowernumber = borrowers.borrowernumber
+    ";
+
+    my @params;
+    if ($branchcode) {
+        $query .= " AND borrowers.branchcode = ? ";
+        push( @params, $branchcode );
+    }
+    $query .= " ORDER BY borrowers.surname, borrowers.firstname";
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@params);
+
+    my @m;
+    while ( my $row = $sth->fetchrow_hashref() ) {
+        foreach my $key ( keys %$row ) {
+            delete $row->{$key} unless defined $row->{$key};
+        }
+
+        push( @m, $row );
+    }
+
+    return \@m;
+}
+
+=head2 ApproveModifications
+
+Koha::Patron::Modifications->ApproveModifications( $borrowernumber );
+
+Commits the pending modifications to the borrower record and removes
+them from the modifications table.
+
+=cut
+
+sub ApproveModifications {
+    my ( $self, $borrowernumber ) = @_;
+
+    $borrowernumber =
+      ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
+
+    return unless $borrowernumber;
+
+    my $data = $self->GetModifications( { borrowernumber => $borrowernumber } );
+    delete $data->{timestamp};
+    delete $data->{verification_token};
+
+    my $rs = Koha::Database->new()->schema->resultset('Borrower')->search({
+        borrowernumber => $data->{borrowernumber},
+    });
+    if( $rs->update($data) ) {
+        $self->DelModifications( { borrowernumber => $borrowernumber } );
+    }
+}
+
+=head2 DenyModifications
+
+Koha::Patron::Modifications->DenyModifications( $borrowernumber );
+
+Removes the modifications from the table for the given patron,
+without committing the changes to the patron record.
+
+=cut
+
+sub DenyModifications {
+    my ( $self, $borrowernumber ) = @_;
+
+    $borrowernumber =
+      ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
+
+    return unless $borrowernumber;
+
+    return $self->DelModifications( { borrowernumber => $borrowernumber } );
+}
+
+=head2 DelModifications
+
+Koha::Patron::Modifications->DelModifications({
+  [ borrowernumber => $borrowernumber ],
+  [ verification_token => $verification_token ]
+});
+
+Deletes the modifications for the given borrowernumber or verification token.
+
+=cut
+
+sub DelModifications {
+    my ( $self, $params ) = @_;
+
+    my ( $field, $value );
+
+    if ( $params->{'borrowernumber'} ) {
+        $field = 'borrowernumber';
+        $value = $params->{'borrowernumber'};
+    }
+    elsif ( $params->{'verification_token'} ) {
+        $field = 'verification_token';
+        $value = $params->{'verification_token'};
+    }
+
+    return unless $value;
+
+    my $dbh = C4::Context->dbh;
+
+    $field = $dbh->quote_identifier($field);
+
+    my $query = "
+        DELETE
+        FROM borrower_modifications
+        WHERE $field = ?
+    ";
+
+    my $sth = $dbh->prepare($query);
+    return $sth->execute($value);
+}
+
+=head2 GetModifications
+
+$hashref = Koha::Patron::Modifications->GetModifications({
+  [ borrowernumber => $borrowernumber ],
+  [ verification_token => $verification_token ]
+});
+
+Gets the modifications for the given borrowernumber or verification token.
+
+=cut
+
+sub GetModifications {
+    my ( $self, $params ) = @_;
+
+    my ( $field, $value );
+
+    if ( defined( $params->{'borrowernumber'} ) ) {
+        $field = 'borrowernumber';
+        $value = $params->{'borrowernumber'};
+    }
+    elsif ( defined( $params->{'verification_token'} ) ) {
+        $field = 'verification_token';
+        $value = $params->{'verification_token'};
+    }
+
+    return unless $value;
+
+    my $dbh = C4::Context->dbh;
+
+    $field = $dbh->quote_identifier($field);
+
+    my $query = "
+        SELECT *
+        FROM borrower_modifications
+        WHERE $field = ?
+    ";
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute($value);
+    my $data = $sth->fetchrow_hashref();
+
+    foreach my $key ( keys %$data ) {
+        delete $data->{$key} unless ( defined( $data->{$key} ) );
+    }
+
+    return $data;
+}
+
+1;
diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm
new file mode 100644 (file)
index 0000000..e001b84
--- /dev/null
@@ -0,0 +1,58 @@
+package Koha::Patrons;
+
+# Copyright ByWater Solutions 2014
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use Koha::Patron;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Patron - Koha Patron Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub _type {
+    return 'Borrower';
+}
+
+sub object_class {
+    return 'Koha::Patron';
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle@bywatersolutions.com>
+
+=cut
+
+1;
index 62f7693..b692a38 100644 (file)
@@ -20,7 +20,7 @@ use Mojo::Base 'Mojolicious';
 
 use C4::Auth qw( check_cookie_auth get_session );
 use C4::Context;
-use Koha::Borrowers;
+use Koha::Patrons;
 
 sub startup {
     my $self = shift;
@@ -32,7 +32,7 @@ sub startup {
             my ($status, $sessionID) = check_cookie_auth($c->cookie('CGISESSID'));
             if ($status eq "ok") {
                 my $session = get_session($sessionID);
-                my $user = Koha::Borrowers->find($session->param('number'));
+                my $user = Koha::Patrons->find($session->param('number'));
                 $c->stash('koha.user' => $user);
             }
 
index 6468bba..426145f 100644 (file)
@@ -20,7 +20,7 @@ use Modern::Perl;
 use Mojo::Base 'Mojolicious::Controller';
 
 use C4::Auth qw( haspermission );
-use Koha::Borrowers;
+use Koha::Patrons;
 
 sub list_patrons {
     my ($c, $args, $cb) = @_;
@@ -30,7 +30,7 @@ sub list_patrons {
         return $c->$cb({error => "You don't have the required permission"}, 403);
     }
 
-    my $patrons = Koha::Borrowers->search;
+    my $patrons = Koha::Patrons->search;
 
     $c->$cb($patrons->unblessed, 200);
 }
@@ -47,7 +47,7 @@ sub get_patron {
         return $c->$cb({error => "You don't have the required permission"}, 403);
     }
 
-    my $patron = Koha::Borrowers->find($args->{borrowernumber});
+    my $patron = Koha::Patrons->find($args->{borrowernumber});
     unless ($patron) {
         return $c->$cb({error => "Patron not found"}, 404);
     }
index 44c76fc..d6b87d4 100644 (file)
@@ -22,7 +22,7 @@ use Modern::Perl;
 
 use base qw( Template::Plugin );
 
-use Koha::Borrower::Debarments qw();
+use Koha::Patron::Debarments qw();
 use C4::Members qw();
 
 =pod
@@ -46,7 +46,7 @@ sub IsDebarred {
 
     return unless $borrower;
 
-    return Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber});
+    return Koha::Patron::Debarments::IsDebarred($borrower->{borrowernumber});
 }
 
 sub HasOverdues {
index 4049e56..a693eba 100644 (file)
@@ -21,7 +21,7 @@ use Carp;
 
 use C4::Auth;
 
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::Exceptions;
@@ -238,7 +238,7 @@ sub can_be_deleted {
     return 0 unless $borrowernumber;
     return 1 if $self->owner == $borrowernumber;
 
-    my $patron = Koha::Borrowers->find( $borrowernumber );
+    my $patron = Koha::Patrons->find( $borrowernumber );
 
     return 1 if $self->category == $PUBLIC and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } );
 
index 4587e27..6b77677 100755 (executable)
--- a/about.pl
+++ b/about.pl
@@ -35,7 +35,7 @@ use C4::Installer;
 
 use Koha;
 use Koha::Acquisition::Currencies;
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::Config::SysPrefs;
 
 #use Smart::Comments '####';
@@ -82,8 +82,8 @@ my $warnPrefAnonymousPatron = (
         and not C4::Context->preference('AnonymousPatron')
 );
 
-my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
-my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
+my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
+my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
 
 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
 
index 1370b58..e439a62 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Auth;
 use C4::Branch;
 use C4::Output;
 use C4::Form::MessagingPreferences;
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::Database;
 use Koha::DateUtils;
 use Koha::Patron::Categories;
@@ -162,7 +162,7 @@ elsif ( $op eq 'add_validate' ) {
 }
 elsif ( $op eq 'delete_confirm' ) {
 
-    my $count = Koha::Borrowers->search({
+    my $count = Koha::Patrons->search({
         categorycode => $categorycode
     })->count;
 
index 3e433b4..8a52c8c 100755 (executable)
@@ -43,7 +43,7 @@ use Koha::Holds;
 use C4::Context;
 use CGI::Session;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
-use Koha::Borrower::Debarments qw(GetDebarments IsDebarred);
+use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
 use Koha::DateUtils;
 use Koha::Database;
 use Koha::Patron::Messages;
index ad53752..37eaed4 100755 (executable)
@@ -28,7 +28,7 @@ use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Auth qw/check_cookie_auth/;
-use Koha::Borrowers;
+use Koha::Patrons;
 use Koha::DateUtils qw/format_sqldatetime/;
 
 use JSON qw( to_json );
@@ -67,7 +67,7 @@ foreach my $p (@parts) {
 
 push( @params, { branchcode => C4::Context->userenv->{branch} } ) if $limit_on_branch;
 
-my $borrowers_rs = Koha::Borrowers->search(
+my $borrowers_rs = Koha::Patrons->search(
     { -and => \@params },
     {
         # Get the first 10 results
index e2651d8..d9e01b7 100755 (executable)
@@ -28,8 +28,8 @@ use C4::NewsChannels; # GetNewsToDisplay
 use C4::Review qw/numberofreviews/;
 use C4::Suggestions qw/CountSuggestion/;
 use C4::Tags qw/get_count_by_tag_status/;
-use Koha::Borrower::Modifications;
-use Koha::Borrower::Discharge;
+use Koha::Patron::Modifications;
+use Koha::Patron::Discharge;
 
 my $query = new CGI;
 
@@ -66,8 +66,8 @@ my $pendingcomments    = numberofreviews(0);
 my $pendingtags        = get_count_by_tag_status(0);
 my $pendingsuggestions = CountSuggestion("ASKED");
 my $pending_borrower_modifications =
-  Koha::Borrower::Modifications->GetPendingModificationsCount( $branch );
-my $pending_discharge_requests = Koha::Borrower::Discharge::count({ pending => 1 });
+  Koha::Patron::Modifications->GetPendingModificationsCount( $branch );
+my $pending_discharge_requests = Koha::Patron::Discharge::count({ pending => 1 });
 
 $template->param(
     pendingcomments                => $pendingcomments,
index 466c119..5684a37 100755 (executable)
@@ -36,7 +36,7 @@ use C4::Output;
 use C4::Members;
 use C4::Reserves;
 use C4::Letters;
-use Koha::Borrower::Discharge;
+use Koha::Patron::Discharge;
 
 use Koha::DateUtils;
 
@@ -57,7 +57,7 @@ if ( $input->param('borrowernumber') ) {
     # Getting member data
     $data = GetMember( borrowernumber => $borrowernumber );
 
-    my $can_be_discharged = Koha::Borrower::Discharge::can_be_discharged({
+    my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({
         borrowernumber => $borrowernumber
     });
 
@@ -67,16 +67,16 @@ if ( $input->param('borrowernumber') ) {
 
     # Generating discharge if needed
     if ( $input->param('discharge') and $can_be_discharged ) {
-        my $is_discharged = Koha::Borrower::Discharge::is_discharged({
+        my $is_discharged = Koha::Patron::Discharge::is_discharged({
             borrowernumber => $borrowernumber,
         });
         unless ($is_discharged) {
-            Koha::Borrower::Discharge::discharge({
+            Koha::Patron::Discharge::discharge({
                 borrowernumber => $borrowernumber
             });
         }
         eval {
-            my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf(
+            my $pdf_path = Koha::Patron::Discharge::generate_as_pdf(
                 { borrowernumber => $borrowernumber, branchcode => $data->{'branchcode'} } );
 
             binmode(STDOUT);
@@ -98,7 +98,7 @@ if ( $input->param('borrowernumber') ) {
     }
 
     # Already generated discharges
-    my $validated_discharges = Koha::Borrower::Discharge::get_validated({
+    my $validated_discharges = Koha::Patron::Discharge::get_validated({
         borrowernumber => $borrowernumber,
     });
 
index d318e00..4029c74 100755 (executable)
@@ -23,7 +23,7 @@ use CGI;
 use C4::Auth;
 use C4::Output;
 use C4::Context;
-use Koha::Borrower::Discharge;
+use Koha::Patron::Discharge;
 
 my $input = new CGI;
 my $op = $input->param('op') // 'list';
@@ -44,12 +44,12 @@ my $branchcode =
 
 if( $op eq 'allow' ) {
     my $borrowernumber = $input->param('borrowernumber');
-    Koha::Borrower::Discharge::discharge({
+    Koha::Patron::Discharge::discharge({
         borrowernumber => $borrowernumber
     }) if $borrowernumber;
 }
 
-my $pending_discharges = Koha::Borrower::Discharge::get_pendings({
+my $pending_discharges = Koha::Patron::Discharge::get_pendings({
     branchcode => $branchcode
 });
 
index 45ed50d..d71fa57 100755 (executable)
@@ -30,7 +30,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes);
 use C4::Debug;
 
 use Koha::DateUtils;
-use Koha::Borrower::Files;
+use Koha::Patron::Files;
 
 my $cgi = CGI->new;
 
@@ -47,7 +47,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 $template->param( 'borrower_files' => 1 );
 
 my $borrowernumber = $cgi->param('borrowernumber');
-my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
+my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
 
 my $op = $cgi->param('op') || '';
 
@@ -119,7 +119,7 @@ else {
     $template->param( picture => 1 ) if $picture;
 
     $template->param(
-        files => Koha::Borrower::Files->new( borrowernumber => $borrowernumber )
+        files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )
           ->GetFilesInfo(),
 
         errors => \%errors,
index 5486928..f14770b 100755 (executable)
@@ -39,7 +39,7 @@ use C4::Log;
 use C4::Letters;
 use C4::Branch; # GetBranches
 use C4::Form::MessagingPreferences;
-use Koha::Borrower::Debarments;
+use Koha::Patron::Debarments;
 use Koha::Cities;
 use Koha::DateUtils;
 use Email::Valid;
index 89b9793..247cc00 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Context;
 use C4::Members;
 use C4::Branch;
 use C4::Category;
-use Koha::Borrower::Modifications;
+use Koha::Patron::Modifications;
 use Koha::Libraries;
 use Koha::List::Patron;
 
@@ -89,7 +89,7 @@ else {
 
 
 my $pending_borrower_modifications =
-  Koha::Borrower::Modifications->GetPendingModificationsCount( $branch );
+  Koha::Patron::Modifications->GetPendingModificationsCount( $branch );
 
 $template->param( 
         no_add => $no_add,
index 03af1cd..f55b7ab 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Context;
 use C4::Members;
 use C4::Branch;
 use C4::Category;
-use Koha::Borrower::Modifications;
+use Koha::Patron::Modifications;
 
 my $query = new CGI;
 
@@ -50,10 +50,10 @@ foreach my $param (@params) {
         my $action = $query->param($param);
 
         if ( $action eq 'approve' ) {
-            Koha::Borrower::Modifications->ApproveModifications( $borrowernumber );
+            Koha::Patron::Modifications->ApproveModifications( $borrowernumber );
         }
         elsif ( $action eq 'deny' ) {
-            Koha::Borrower::Modifications->DenyModifications( $borrowernumber );
+            Koha::Patron::Modifications->DenyModifications( $borrowernumber );
         }
         elsif ( $action eq 'ignore' ) {
 
index 1ab8131..1441346 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Context;
 use C4::Members;
 use C4::Branch;
 use C4::Category;
-use Koha::Borrower::Modifications;
+use Koha::Patron::Modifications;
 
 my $query = new CGI;
 
@@ -49,7 +49,7 @@ my $branch =
   : undef;
 
 my $pending_modifications =
-  Koha::Borrower::Modifications->GetPendingModifications($branch);
+  Koha::Patron::Modifications->GetPendingModifications($branch);
 
 my $borrowers;
 foreach my $pm (@$pending_modifications) {
index 98ad5ee..444114e 100755 (executable)
@@ -23,7 +23,7 @@ use CGI qw ( -utf8 );
 
 use C4::Auth;
 use Koha::DateUtils;
-use Koha::Borrower::Debarments;
+use Koha::Patron::Debarments;
 
 my $cgi = new CGI;
 
index e233b46..6a3de7e 100755 (executable)
@@ -51,8 +51,7 @@ use C4::Branch; # GetBranchName
 use C4::Form::MessagingPreferences;
 use List::MoreUtils qw/uniq/;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
-use Koha::Borrower::Debarments qw(GetDebarments IsDebarred);
-use Koha::Libraries;
+use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
 use Module::Load;
 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
     load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber );
index 9374018..bb54256 100755 (executable)
@@ -364,7 +364,7 @@ sub PurgeZ3950 {
 }
 
 sub PurgeDebarments {
-    require Koha::Borrower::Debarments;
+    require Koha::Patron::Debarments;
     my $days = shift;
     $count = 0;
     $sth   = $dbh->prepare(
@@ -376,7 +376,7 @@ sub PurgeDebarments {
     );
     $sth->execute($days) or die $dbh->errstr;
     while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) {
-        Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id);
+        Koha::Patron::Debarments::DelDebarment($borrower_debarment_id);
         $count++;
     }
     return $count;
index b73d31f..a0907a2 100755 (executable)
@@ -39,7 +39,7 @@ use C4::Circulation qw/LostItem/;
 use Getopt::Long;
 use C4::Log;
 use Pod::Usage;
-use Koha::Borrowers;
+use Koha::Patrons;
 
 my  $lost;  #  key=lost value,  value=num days.
 my ($charge, $verbose, $confirm, $quiet);
@@ -302,7 +302,7 @@ foreach my $startrange (sort keys %$lost) {
         $count=0;
         ITEM: while (my $row=$sth_items->fetchrow_hashref) {
             if( $filter_borrower_categories ) {
-                my $category = uc Koha::Borrowers->find( $row->{borrowernumber} )->categorycode();
+                my $category = uc Koha::Patrons->find( $row->{borrowernumber} )->categorycode();
                 next ITEM unless ( $category_to_process{ $category } );
             }
             printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
index b6c643d..f77e3bb 100755 (executable)
@@ -38,7 +38,7 @@ use C4::Context;
 use C4::Letters;
 use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_letter);
 use C4::Log;
-use Koha::Borrower::Debarments qw(AddUniqueDebarment);
+use Koha::Patron::Debarments qw(AddUniqueDebarment);
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::Libraries;
index da4238e..c9dea91 100755 (executable)
@@ -28,7 +28,7 @@ use C4::Log;
 use C4::Debug;
 use C4::Branch;
 use C4::Members;
-use Koha::Borrower::Discharge;
+use Koha::Patron::Discharge;
 use Koha::DateUtils;
 
 my $input = new CGI;
@@ -44,7 +44,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
 });
 
 if ( $op eq 'request' ) {
-    my $success = Koha::Borrower::Discharge::request({
+    my $success = Koha::Patron::Discharge::request({
         borrowernumber => $loggedinuser,
     });
 
@@ -60,7 +60,7 @@ elsif ( $op eq 'get' ) {
 
         # Getting member data
         my $data = GetMember( borrowernumber => $loggedinuser );
-        my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf({
+        my $pdf_path = Koha::Patron::Discharge::generate_as_pdf({
             borrowernumber => $loggedinuser,
             branchcode => $data->{'branchcode'},
         });
@@ -83,16 +83,16 @@ elsif ( $op eq 'get' ) {
     }
 }
 else {
-    my $pending = Koha::Borrower::Discharge::count({
+    my $pending = Koha::Patron::Discharge::count({
         borrowernumber => $loggedinuser,
         pending        => 1,
     });
-    my $available = Koha::Borrower::Discharge::count({
+    my $available = Koha::Patron::Discharge::count({
         borrowernumber => $loggedinuser,
         validated      => 1,
     });
     $template->param(
-        available => $available && Koha::Borrower::Discharge::is_discharged({borrowernumber => $loggedinuser}),
+        available => $available && Koha::Patron::Discharge::is_discharged({borrowernumber => $loggedinuser}),
         pending   => $pending,
     );
 }
index b7dac77..80516c1 100755 (executable)
@@ -25,8 +25,8 @@ use C4::Auth;
 use C4::Output;
 use C4::Members;
 use C4::Form::MessagingPreferences;
-use Koha::Borrowers;
-use Koha::Borrower::Modifications;
+use Koha::Patrons;
+use Koha::Patron::Modifications;
 use C4::Branch qw(GetBranchesLoop);
 use C4::Scrubber;
 use Email::Valid;
@@ -126,7 +126,8 @@ if ( $action eq 'create' ) {
 
             my $verification_token = md5_hex( \%borrower );
             $borrower{'password'} = random_string("..........");
-            Koha::Borrower::Modifications->new(
+
+            Koha::Patron::Modifications->new(
                 verification_token => $verification_token )
               ->AddModifications(\%borrower);
 
@@ -207,7 +208,7 @@ elsif ( $action eq 'update' ) {
             );
 
             my $m =
-              Koha::Borrower::Modifications->new(
+              Koha::Patron::Modifications->new(
                 borrowernumber => $borrowernumber );
 
             $m->DelModifications;
@@ -238,7 +239,7 @@ elsif ( $action eq 'edit' ) {    #Display logged in borrower's data
 
     $template->param(
         borrower  => $borrower,
-        guarantor => scalar Koha::Borrowers->find($borrowernumber)->guarantor(),
+        guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(),
         hidden => GetHiddenFields( $mandatory, 'modification' ),
     );
 
index 2215892..969c46a 100755 (executable)
@@ -24,7 +24,7 @@ use C4::Context;
 use C4::Circulation;
 use C4::Members;
 use C4::Output;
-use Koha::Borrowers;
+use Koha::Patrons;
 
 my $query = new CGI;
 
@@ -75,7 +75,7 @@ elsif ( $op eq "delete_record" ) {
 }
 
 # get borrower privacy ....
-my $borrower = Koha::Borrowers->find( $borrowernumber );;
+my $borrower = Koha::Patrons->find( $borrowernumber );;
 
 $template->param(
     'Ask_data'                       => 1,
index 15d57cd..5ceff26 100755 (executable)
@@ -23,7 +23,7 @@ use C4::Auth;
 use C4::Output;
 use C4::Members;
 use C4::Form::MessagingPreferences;
-use Koha::Borrower::Modifications;
+use Koha::Patron::Modifications;
 
 my $cgi = new CGI;
 my $dbh = C4::Context->dbh;
@@ -34,7 +34,7 @@ unless ( C4::Context->preference('PatronSelfRegistration') ) {
 }
 
 my $token = $cgi->param('token');
-my $m = Koha::Borrower::Modifications->new( verification_token => $token );
+my $m = Koha::Patron::Modifications->new( verification_token => $token );
 
 my ( $template, $borrowernumber, $cookie );
 if ( $m->Verify() ) {
@@ -50,13 +50,13 @@ if ( $m->Verify() ) {
     $template->param(
         OpacPasswordChange => C4::Context->preference('OpacPasswordChange') );
 
-    my $borrower = Koha::Borrower::Modifications->GetModifications({ verification_token => $token });
+    my $borrower = Koha::Patron::Modifications->GetModifications({ verification_token => $token });
 
     my $password;
     ( $borrowernumber, $password ) = AddMember_Opac(%$borrower);
 
     if ($borrowernumber) {
-        Koha::Borrower::Modifications->DelModifications({ verification_token => $token });
+        Koha::Patron::Modifications->DelModifications({ verification_token => $token });
         C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
 
         $template->param( password_cleartext => $password );
index c7bc236..0f753d8 100755 (executable)
@@ -34,8 +34,8 @@ use C4::Branch; # GetBranches
 use C4::Overdues;
 use C4::Debug;
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
 use Koha::Libraries;
+use Koha::Patron::Debarments qw(IsDebarred);
 use Date::Calc qw/Today Date_to_Days/;
 
 my $maxreserves = C4::Context->preference("maxreserves");
index 3a79296..0828739 100755 (executable)
@@ -35,7 +35,7 @@ use C4::Items;
 use C4::Letters;
 use C4::Branch; # GetBranches
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Patron::Debarments qw(IsDebarred);
 use Koha::Holds;
 use Koha::Database;
 use Koha::Patron::Messages;
index effae5e..970596f 100755 (executable)
@@ -44,7 +44,7 @@ use C4::Utils::DataTables::Members;
 use C4::Members;
 use C4::Search;                # enabled_staff_search_views
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Patron::Debarments qw(IsDebarred);
 use Koha::Holds;
 use Koha::Libraries;
 
diff --git a/t/Borrower.t b/t/Borrower.t
deleted file mode 100755 (executable)
index 4181942..0000000
+++ /dev/null
@@ -1,343 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use Test::More tests => 18;
-use Test::Warn;
-use t::lib::Mocks;
-
-BEGIN {
-    t::lib::Mocks::mock_dbh;
-    use_ok('Koha::Object');
-    use_ok('Koha::Borrower');
-}
-
-my $object = Koha::Borrower->new( { surname => 'Test Borrower' } );
-is( $object->surname(), 'Test Borrower', "Accessor returns correct value" );
-$object->surname('Test Borrower Surname');
-is( $object->surname(), 'Test Borrower Surname', "Accessor returns correct value after set" );
-
-my $object2 = Koha::Borrower->new( { surname => 'Test Borrower 2' } );
-is( $object2->surname(), 'Test Borrower 2', "Accessor returns correct value" );
-$object2->surname('Test Borrower Surname 2');
-is( $object2->surname(), 'Test Borrower Surname 2', "Accessor returns correct value after set" );
-
-my $ret;
-$ret = $object2->set( { surname => "Test Borrower Surname 3", firstname => "Test Firstname" } );
-ok( ref($ret) eq 'Koha::Borrower', "Set returns object on success" );
-is( $object2->surname(),   "Test Borrower Surname 3", "Set sets first field correctly" );
-is( $object2->firstname(), "Test Firstname",          "Set sets second field correctly" );
-
-warning_is { $ret = $object->set({ surname => "Test Borrower Surname 4", bork => "bork" }) }
-            "No property bork!",
-            "Expected 'No property bork!' caught";
-is( $object2->surname(), "Test Borrower Surname 3", "Bad Set does not set field" );
-is( $ret, 0, "Set returns 0 when passed a bad property" );
-
-warning_is { $ret = $object->bork() }
-            "No method bork!",
-            "Expected 'No method bork!' caught for getter.";
-ok( ! defined $ret, 'Bad getter returns undef' );
-
-warning_is { $ret = $object->bork('bork') }
-            "No method bork!",
-            "Expected 'No method bork!' caught for setter.";
-ok( ! defined $ret, 'Bad setter returns undef' );
-
-my $borrower = Koha::Borrower->new(
-    {
-        borrowernumber      => '12345',
-        cardnumber          => '1234567890',
-        surname             => 'mySurname',
-        firstname           => 'myFirstname',
-        title               => 'Mr.',
-        othernames          => 'myOthernames',
-        initials            => 'MM',
-        streetnumber        => '100',
-        streettype          => 'Blvd',
-        address             => 'my personnal address',
-        address2            => 'my adress2',
-        city                => 'Marseille',
-        state               => 'mystate',
-        zipcode             => '13006',
-        country             => 'France',
-        email               => 'mySurname.myFirstname@email.com',
-        phone               => '0402872934',
-        mobile              => '0627884632',
-        fax                 => '0402872935',
-        emailpro            => 'myEmailPro@email.com',
-        phonepro            => '0402873334',
-        B_streetnumber      => '101',
-        B_streettype        => 'myB_streettype',
-        B_address           => 'myB_address',
-        B_address2          => 'myB_address2',
-        B_city              => 'myB_city',
-        B_state             => 'myB_state',
-        B_zipcode           => '23456',
-        B_country           => 'myB_country',
-        B_email             => 'myB_email',
-        B_phone             => '0678353935',
-        dateofbirth         => '1990-07-16',
-        branchcode          => 'myBranCode',
-        categorycode        => 'myCatCode',
-        dateenrolled        => '2015-03-19',
-        dateexpiry          => '2016-03-19',
-        gonenoaddress       => '0',
-        lost                => '0',
-        debarred            => '2015-04-19',
-        debarredcomment     => 'You are debarred',
-        contactname         => 'myContactname',
-        contactfirstname    => 'myContactfirstname',
-        contacttitle        => 'myContacttitle',
-        guarantorid         => '123454321',
-        borrowernotes       => 'borrowernotes',
-        relationship        => 'myRelationship',
-        sex                 => 'M',
-        password            => 'hfkurhfe976634èj!',
-        flags               => '55555',
-        userid              => '87987',
-        opacnote            => 'myOpacnote',
-        contactnote         => 'myContactnote',
-        sort1               => 'mySort1',
-        sort2               => 'mySort2',
-        altcontactfirstname => 'myAltcontactfirstname',
-        altcontactsurname   => 'myAltcontactsurname',
-        altcontactaddress1  => 'myAltcontactaddress1',
-        altcontactaddress2  => 'myAltcontactaddress2',
-        altcontactaddress3  => 'myAltcontactaddress3',
-        altcontactstate     => 'myAltcontactstate',
-        altcontactzipcode   => '465843',
-        altcontactcountry   => 'myOtherCountry',
-        altcontactphone     => 'myOtherphone',
-        smsalertnumber      => '0683027346',
-        privacy             => '667788',
-    }
-);
-
-#borrower Accessor tests
-subtest 'Accessor tests' => sub {
-    plan tests => 65;
-    is( $borrower->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
-    is( $borrower->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
-    is( $borrower->surname,        'mySurname',                       'surname accessor returns correct value' );
-    is( $borrower->firstname,      'myFirstname',                     'firstname accessor returns correct value' );
-    is( $borrower->title,          'Mr.',                             'title accessor returns correct value' );
-    is( $borrower->othernames,     'myOthernames',                    'othernames accessor returns correct value' );
-    is( $borrower->initials,       'MM',                              'initials accessor returns correct value' );
-    is( $borrower->streetnumber,   '100',                             'streetnumber accessor returns correct value' );
-    is( $borrower->streettype,     'Blvd',                            'streettype accessor returns correct value' );
-    is( $borrower->address,        'my personnal address',            'address accessor returns correct value' );
-    is( $borrower->address2,       'my adress2',                      'address2 accessor returns correct value' );
-    is( $borrower->city,           'Marseille',                       'city accessor returns correct value' );
-    is( $borrower->state,          'mystate',                         'state accessor returns correct value' );
-    is( $borrower->zipcode,        '13006',                           'zipcode accessor returns correct value' );
-    is( $borrower->country,        'France',                          'country accessor returns correct value' );
-    is( $borrower->email,          'mySurname.myFirstname@email.com', 'email accessor returns correct value' );
-    is( $borrower->phone,          '0402872934',                      'phone accessor returns correct value' );
-    is( $borrower->mobile,         '0627884632',                      'mobile accessor returns correct value' );
-    is( $borrower->fax,            '0402872935',                      'fax accessor returns correct value' );
-    is( $borrower->emailpro,       'myEmailPro@email.com',            'emailpro accessor returns correct value' );
-    is( $borrower->phonepro,       '0402873334',                      'phonepro accessor returns correct value' );
-    is( $borrower->B_streetnumber, '101',                             'B_streetnumber accessor returns correct value' );
-    is( $borrower->B_streettype,   'myB_streettype',                  'B_streettype accessor returns correct value' );
-    is( $borrower->B_address,      'myB_address',                     'B_address accessor returns correct value' );
-    is( $borrower->B_address2,     'myB_address2',                    'B_address2 accessor returns correct value' );
-    is( $borrower->B_city,         'myB_city',                        'B_city accessor returns correct value' );
-    is( $borrower->B_state,        'myB_state',                       'B_state accessor returns correct value' );
-    is( $borrower->B_zipcode,      '23456',                           'B_zipcode accessor returns correct value' );
-    is( $borrower->B_country,      'myB_country',                     'B_country accessor returns correct value' );
-    is( $borrower->B_email,        'myB_email',                       'B_email accessor returns correct value' );
-    is( $borrower->B_phone,        '0678353935',                      'B_phone accessor returns correct value' );
-    is( $borrower->dateofbirth,    '1990-07-16',                      'dateofbirth accessor returns correct value' );
-    is( $borrower->branchcode,     'myBranCode',                      'branchcode accessor returns correct value' );
-    is( $borrower->categorycode,   'myCatCode',                       'categorycode accessor returns correct value' );
-    is( $borrower->dateenrolled,   '2015-03-19',                      'dateenrolled accessor returns correct value' );
-    is( $borrower->dateexpiry,     '2016-03-19',                      'dateexpiry accessor returns correct value' );
-    is( $borrower->gonenoaddress,  '0',                               'gonenoaddress accessor returns correct value' );
-    is( $borrower->lost,           '0',                               'lost accessor returns correct value' );
-    is( $borrower->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
-    is( $borrower->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
-    is( $borrower->contactname,         'myContactname',         'contactname accessor returns correct value' );
-    is( $borrower->contactfirstname,    'myContactfirstname',    'contactfirstname accessor returns correct value' );
-    is( $borrower->contacttitle,        'myContacttitle',        'contacttitle accessor returns correct value' );
-    is( $borrower->guarantorid,         '123454321',             'guarantorid accessor returns correct value' );
-    is( $borrower->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
-    is( $borrower->relationship,        'myRelationship',        'relationship accessor returns correct value' );
-    is( $borrower->sex,                 'M',                     'sex accessor returns correct value' );
-    is( $borrower->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
-    is( $borrower->flags,               '55555',                 'flags accessor returns correct value' );
-    is( $borrower->userid,              '87987',                 'userid accessor returns correct value' );
-    is( $borrower->opacnote,            'myOpacnote',            'opacnote accessor returns correct value' );
-    is( $borrower->contactnote,         'myContactnote',         'contactnote accessor returns correct value' );
-    is( $borrower->sort1,               'mySort1',               'sort1 accessor returns correct value' );
-    is( $borrower->sort2,               'mySort2',               'sort2 accessor returns correct value' );
-    is( $borrower->altcontactfirstname, 'myAltcontactfirstname', 'altcontactfirstname accessor returns correct value' );
-    is( $borrower->altcontactsurname,   'myAltcontactsurname',   'altcontactsurname accessor returns correct value' );
-    is( $borrower->altcontactaddress1,  'myAltcontactaddress1',  'altcontactaddress1 accessor returns correct value' );
-    is( $borrower->altcontactaddress2,  'myAltcontactaddress2',  'altcontactaddress2 accessor returns correct value' );
-    is( $borrower->altcontactaddress3,  'myAltcontactaddress3',  'altcontactaddress3 accessor returns correct value' );
-    is( $borrower->altcontactstate,     'myAltcontactstate',     'altcontactstate accessor returns correct value' );
-    is( $borrower->altcontactzipcode,   '465843',                'altcontactzipcode accessor returns correct value' );
-    is( $borrower->altcontactcountry,   'myOtherCountry',        'altcontactcountry accessor returns correct value' );
-    is( $borrower->altcontactphone,     'myOtherphone',          'altcontactphone accessor returns correct value' );
-    is( $borrower->smsalertnumber,      '0683027346',            'smsalertnumber accessor returns correct value' );
-    is( $borrower->privacy,             '667788',                'privacy accessor returns correct value' );
-};
-
-#borrower Set tests
-subtest 'Set tests' => sub {
-    plan tests => 65;
-
-    $borrower->set(
-        {
-            borrowernumber      => '12346',
-            cardnumber          => '1234567891',
-            surname             => 'SmySurname',
-            firstname           => 'SmyFirstname',
-            title               => 'Mme.',
-            othernames          => 'SmyOthernames',
-            initials            => 'SS',
-            streetnumber        => '200',
-            streettype          => 'Rue',
-            address             => 'Smy personnal address',
-            address2            => 'Smy adress2',
-            city                => 'Lyon',
-            state               => 'Smystate',
-            zipcode             => '69000',
-            country             => 'France',
-            email               => 'SmySurname.myFirstname@email.com',
-            phone               => '0402872935',
-            mobile              => '0627884633',
-            fax                 => '0402872936',
-            emailpro            => 'SmyEmailPro@email.com',
-            phonepro            => '0402873335',
-            B_streetnumber      => '102',
-            B_streettype        => 'SmyB_streettype',
-            B_address           => 'SmyB_address',
-            B_address2          => 'SmyB_address2',
-            B_city              => 'SmyB_city',
-            B_state             => 'SmyB_state',
-            B_zipcode           => '12333',
-            B_country           => 'SmyB_country',
-            B_email             => 'SmyB_email',
-            B_phone             => '0678353936',
-            dateofbirth         => '1991-07-16',
-            branchcode          => 'SmyBranCode',
-            categorycode        => 'SmyCatCode',
-            dateenrolled        => '2014-03-19',
-            dateexpiry          => '2017-03-19',
-            gonenoaddress       => '1',
-            lost                => '1',
-            debarred            => '2016-04-19',
-            debarredcomment     => 'You are still debarred',
-            contactname         => 'SmyContactname',
-            contactfirstname    => 'SmyContactfirstname',
-            contacttitle        => 'SmyContacttitle',
-            guarantorid         => '223454321',
-            borrowernotes       => 'Sborrowernotes',
-            relationship        => 'SmyRelationship',
-            sex                 => 'F',
-            password            => 'zerzerzer#',
-            flags               => '666666',
-            userid              => '98233',
-            opacnote            => 'SmyOpacnote',
-            contactnote         => 'SmyContactnote',
-            sort1               => 'SmySort1',
-            sort2               => 'SmySort2',
-            altcontactfirstname => 'SmyAltcontactfirstname',
-            altcontactsurname   => 'SmyAltcontactsurname',
-            altcontactaddress1  => 'SmyAltcontactaddress1',
-            altcontactaddress2  => 'SmyAltcontactaddress2',
-            altcontactaddress3  => 'SmyAltcontactaddress3',
-            altcontactstate     => 'SmyAltcontactstate',
-            altcontactzipcode   => '565843',
-            altcontactcountry   => 'SmyOtherCountry',
-            altcontactphone     => 'SmyOtherphone',
-            smsalertnumber      => '0683027347',
-            privacy             => '667789'
-        }
-    );
-
-    is( $borrower->borrowernumber,      '12346',                            'borrowernumber field set ok' );
-    is( $borrower->cardnumber,          '1234567891',                       'cardnumber field set ok' );
-    is( $borrower->surname,             'SmySurname',                       'surname field set ok' );
-    is( $borrower->firstname,           'SmyFirstname',                     'firstname field set ok' );
-    is( $borrower->title,               'Mme.',                             'title field set ok' );
-    is( $borrower->othernames,          'SmyOthernames',                    'othernames field set ok' );
-    is( $borrower->initials,            'SS',                               'initials field set ok' );
-    is( $borrower->streetnumber,        '200',                              'streetnumber field set ok' );
-    is( $borrower->streettype,          'Rue',                              'streettype field set ok' );
-    is( $borrower->address,             'Smy personnal address',            'address field set ok' );
-    is( $borrower->address2,            'Smy adress2',                      'address2 field set ok' );
-    is( $borrower->city,                'Lyon',                             'city field set ok' );
-    is( $borrower->state,               'Smystate',                         'state field set ok' );
-    is( $borrower->zipcode,             '69000',                            'zipcode field set ok' );
-    is( $borrower->country,             'France',                           'country field set ok' );
-    is( $borrower->email,               'SmySurname.myFirstname@email.com', 'email field set ok' );
-    is( $borrower->phone,               '0402872935',                       'phone field set ok' );
-    is( $borrower->mobile,              '0627884633',                       'mobile field set ok' );
-    is( $borrower->fax,                 '0402872936',                       'fax field set ok' );
-    is( $borrower->emailpro,            'SmyEmailPro@email.com',            'emailpro field set ok' );
-    is( $borrower->phonepro,            '0402873335',                       'phonepro field set ok' );
-    is( $borrower->B_streetnumber,      '102',                              'B_streetnumber field set ok' );
-    is( $borrower->B_streettype,        'SmyB_streettype',                  'B_streettype field set ok' );
-    is( $borrower->B_address,           'SmyB_address',                     'B_address field set ok' );
-    is( $borrower->B_address2,          'SmyB_address2',                    'B_address2 field set ok' );
-    is( $borrower->B_city,              'SmyB_city',                        'B_city field set ok' );
-    is( $borrower->B_state,             'SmyB_state',                       'B_state field set ok' );
-    is( $borrower->B_zipcode,           '12333',                            'B_zipcode field set ok' );
-    is( $borrower->B_country,           'SmyB_country',                     'B_country field set ok' );
-    is( $borrower->B_email,             'SmyB_email',                       'B_email field set ok' );
-    is( $borrower->B_phone,             '0678353936',                       'B_phone field set ok' );
-    is( $borrower->dateofbirth,         '1991-07-16',                       'dateofbirth field set ok' );
-    is( $borrower->branchcode,          'SmyBranCode',                      'branchcode field set ok' );
-    is( $borrower->categorycode,        'SmyCatCode',                       'categorycode field set ok' );
-    is( $borrower->dateenrolled,        '2014-03-19',                       'dateenrolled field set ok' );
-    is( $borrower->dateexpiry,          '2017-03-19',                       'dateexpiry field set ok' );
-    is( $borrower->gonenoaddress,       '1',                                'gonenoaddress field set ok' );
-    is( $borrower->lost,                '1',                                'lost field set ok' );
-    is( $borrower->debarred,            '2016-04-19',                       'debarred field set ok' );
-    is( $borrower->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
-    is( $borrower->contactname,         'SmyContactname',                   'contactname field set ok' );
-    is( $borrower->contactfirstname,    'SmyContactfirstname',              'contactfirstname field set ok' );
-    is( $borrower->contacttitle,        'SmyContacttitle',                  'contacttitle field set ok' );
-    is( $borrower->guarantorid,         '223454321',                        'guarantorid field set ok' );
-    is( $borrower->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
-    is( $borrower->relationship,        'SmyRelationship',                  'relationship field set ok' );
-    is( $borrower->sex,                 'F',                                'sex field set ok' );
-    is( $borrower->password,            'zerzerzer#',                       'password field set ok' );
-    is( $borrower->flags,               '666666',                           'flags field set ok' );
-    is( $borrower->userid,              '98233',                            'userid field set ok' );
-    is( $borrower->opacnote,            'SmyOpacnote',                      'opacnote field set ok' );
-    is( $borrower->contactnote,         'SmyContactnote',                   'contactnote field set ok' );
-    is( $borrower->sort1,               'SmySort1',                         'sort1 field set ok' );
-    is( $borrower->sort2,               'SmySort2',                         'sort2 field set ok' );
-    is( $borrower->altcontactfirstname, 'SmyAltcontactfirstname',           'altcontactfirstname field set ok' );
-    is( $borrower->altcontactsurname,   'SmyAltcontactsurname',             'altcontactsurname field set ok' );
-    is( $borrower->altcontactaddress1,  'SmyAltcontactaddress1',            'altcontactaddress1 field set ok' );
-    is( $borrower->altcontactaddress2,  'SmyAltcontactaddress2',            'altcontactaddress2 field set ok' );
-    is( $borrower->altcontactaddress3,  'SmyAltcontactaddress3',            'altcontactaddress3 field set ok' );
-    is( $borrower->altcontactstate,     'SmyAltcontactstate',               'altcontactstate field set ok' );
-    is( $borrower->altcontactzipcode,   '565843',                           'altcontactzipcode field set ok' );
-    is( $borrower->altcontactcountry,   'SmyOtherCountry',                  'altcontactcountry field set ok' );
-    is( $borrower->altcontactphone,     'SmyOtherphone',                    'altcontactphone field set ok' );
-    is( $borrower->smsalertnumber,      '0683027347',                       'smsalertnumber field set ok' );
-    is( $borrower->privacy,             '667789',                           'privacy field set ok' );
-};
-
-1;
diff --git a/t/Patron.t b/t/Patron.t
new file mode 100755 (executable)
index 0000000..b62accd
--- /dev/null
@@ -0,0 +1,343 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 18;
+use Test::Warn;
+use t::lib::Mocks;
+
+BEGIN {
+    t::lib::Mocks::mock_dbh;
+    use_ok('Koha::Object');
+    use_ok('Koha::Patron');
+}
+
+my $object = Koha::Patron->new( { surname => 'Test Patron' } );
+is( $object->surname(), 'Test Patron', "Accessor returns correct value" );
+$object->surname('Test Patron Surname');
+is( $object->surname(), 'Test Patron Surname', "Accessor returns correct value after set" );
+
+my $object2 = Koha::Patron->new( { surname => 'Test Patron 2' } );
+is( $object2->surname(), 'Test Patron 2', "Accessor returns correct value" );
+$object2->surname('Test Patron Surname 2');
+is( $object2->surname(), 'Test Patron Surname 2', "Accessor returns correct value after set" );
+
+my $ret;
+$ret = $object2->set( { surname => "Test Patron Surname 3", firstname => "Test Firstname" } );
+ok( ref($ret) eq 'Koha::Patron', "Set returns object on success" );
+is( $object2->surname(),   "Test Patron Surname 3", "Set sets first field correctly" );
+is( $object2->firstname(), "Test Firstname",          "Set sets second field correctly" );
+
+warning_is { $ret = $object->set({ surname => "Test Patron Surname 4", bork => "bork" }) }
+            "No property bork!",
+            "Expected 'No property bork!' caught";
+is( $object2->surname(), "Test Patron Surname 3", "Bad Set does not set field" );
+is( $ret, 0, "Set returns 0 when passed a bad property" );
+
+warning_is { $ret = $object->bork() }
+            "No method bork!",
+            "Expected 'No method bork!' caught for getter.";
+ok( ! defined $ret, 'Bad getter returns undef' );
+
+warning_is { $ret = $object->bork('bork') }
+            "No method bork!",
+            "Expected 'No method bork!' caught for setter.";
+ok( ! defined $ret, 'Bad setter returns undef' );
+
+my $patron = Koha::Patron->new(
+    {
+        borrowernumber      => '12345',
+        cardnumber          => '1234567890',
+        surname             => 'mySurname',
+        firstname           => 'myFirstname',
+        title               => 'Mr.',
+        othernames          => 'myOthernames',
+        initials            => 'MM',
+        streetnumber        => '100',
+        streettype          => 'Blvd',
+        address             => 'my personnal address',
+        address2            => 'my adress2',
+        city                => 'Marseille',
+        state               => 'mystate',
+        zipcode             => '13006',
+        country             => 'France',
+        email               => 'mySurname.myFirstname@email.com',
+        phone               => '0402872934',
+        mobile              => '0627884632',
+        fax                 => '0402872935',
+        emailpro            => 'myEmailPro@email.com',
+        phonepro            => '0402873334',
+        B_streetnumber      => '101',
+        B_streettype        => 'myB_streettype',
+        B_address           => 'myB_address',
+        B_address2          => 'myB_address2',
+        B_city              => 'myB_city',
+        B_state             => 'myB_state',
+        B_zipcode           => '23456',
+        B_country           => 'myB_country',
+        B_email             => 'myB_email',
+        B_phone             => '0678353935',
+        dateofbirth         => '1990-07-16',
+        branchcode          => 'myBranCode',
+        categorycode        => 'myCatCode',
+        dateenrolled        => '2015-03-19',
+        dateexpiry          => '2016-03-19',
+        gonenoaddress       => '0',
+        lost                => '0',
+        debarred            => '2015-04-19',
+        debarredcomment     => 'You are debarred',
+        contactname         => 'myContactname',
+        contactfirstname    => 'myContactfirstname',
+        contacttitle        => 'myContacttitle',
+        guarantorid         => '123454321',
+        borrowernotes       => 'borrowernotes',
+        relationship        => 'myRelationship',
+        sex                 => 'M',
+        password            => 'hfkurhfe976634èj!',
+        flags               => '55555',
+        userid              => '87987',
+        opacnote            => 'myOpacnote',
+        contactnote         => 'myContactnote',
+        sort1               => 'mySort1',
+        sort2               => 'mySort2',
+        altcontactfirstname => 'myAltcontactfirstname',
+        altcontactsurname   => 'myAltcontactsurname',
+        altcontactaddress1  => 'myAltcontactaddress1',
+        altcontactaddress2  => 'myAltcontactaddress2',
+        altcontactaddress3  => 'myAltcontactaddress3',
+        altcontactstate     => 'myAltcontactstate',
+        altcontactzipcode   => '465843',
+        altcontactcountry   => 'myOtherCountry',
+        altcontactphone     => 'myOtherphone',
+        smsalertnumber      => '0683027346',
+        privacy             => '667788',
+    }
+);
+
+# patron Accessor tests
+subtest 'Accessor tests' => sub {
+    plan tests => 65;
+    is( $patron->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
+    is( $patron->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
+    is( $patron->surname,        'mySurname',                       'surname accessor returns correct value' );
+    is( $patron->firstname,      'myFirstname',                     'firstname accessor returns correct value' );
+    is( $patron->title,          'Mr.',                             'title accessor returns correct value' );
+    is( $patron->othernames,     'myOthernames',                    'othernames accessor returns correct value' );
+    is( $patron->initials,       'MM',                              'initials accessor returns correct value' );
+    is( $patron->streetnumber,   '100',                             'streetnumber accessor returns correct value' );
+    is( $patron->streettype,     'Blvd',                            'streettype accessor returns correct value' );
+    is( $patron->address,        'my personnal address',            'address accessor returns correct value' );
+    is( $patron->address2,       'my adress2',                      'address2 accessor returns correct value' );
+    is( $patron->city,           'Marseille',                       'city accessor returns correct value' );
+    is( $patron->state,          'mystate',                         'state accessor returns correct value' );
+    is( $patron->zipcode,        '13006',                           'zipcode accessor returns correct value' );
+    is( $patron->country,        'France',                          'country accessor returns correct value' );
+    is( $patron->email,          'mySurname.myFirstname@email.com', 'email accessor returns correct value' );
+    is( $patron->phone,          '0402872934',                      'phone accessor returns correct value' );
+    is( $patron->mobile,         '0627884632',                      'mobile accessor returns correct value' );
+    is( $patron->fax,            '0402872935',                      'fax accessor returns correct value' );
+    is( $patron->emailpro,       'myEmailPro@email.com',            'emailpro accessor returns correct value' );
+    is( $patron->phonepro,       '0402873334',                      'phonepro accessor returns correct value' );
+    is( $patron->B_streetnumber, '101',                             'B_streetnumber accessor returns correct value' );
+    is( $patron->B_streettype,   'myB_streettype',                  'B_streettype accessor returns correct value' );
+    is( $patron->B_address,      'myB_address',                     'B_address accessor returns correct value' );
+    is( $patron->B_address2,     'myB_address2',                    'B_address2 accessor returns correct value' );
+    is( $patron->B_city,         'myB_city',                        'B_city accessor returns correct value' );
+    is( $patron->B_state,        'myB_state',                       'B_state accessor returns correct value' );
+    is( $patron->B_zipcode,      '23456',                           'B_zipcode accessor returns correct value' );
+    is( $patron->B_country,      'myB_country',                     'B_country accessor returns correct value' );
+    is( $patron->B_email,        'myB_email',                       'B_email accessor returns correct value' );
+    is( $patron->B_phone,        '0678353935',                      'B_phone accessor returns correct value' );
+    is( $patron->dateofbirth,    '1990-07-16',                      'dateofbirth accessor returns correct value' );
+    is( $patron->branchcode,     'myBranCode',                      'branchcode accessor returns correct value' );
+    is( $patron->categorycode,   'myCatCode',                       'categorycode accessor returns correct value' );
+    is( $patron->dateenrolled,   '2015-03-19',                      'dateenrolled accessor returns correct value' );
+    is( $patron->dateexpiry,     '2016-03-19',                      'dateexpiry accessor returns correct value' );
+    is( $patron->gonenoaddress,  '0',                               'gonenoaddress accessor returns correct value' );
+    is( $patron->lost,           '0',                               'lost accessor returns correct value' );
+    is( $patron->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
+    is( $patron->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
+    is( $patron->contactname,         'myContactname',         'contactname accessor returns correct value' );
+    is( $patron->contactfirstname,    'myContactfirstname',    'contactfirstname accessor returns correct value' );
+    is( $patron->contacttitle,        'myContacttitle',        'contacttitle accessor returns correct value' );
+    is( $patron->guarantorid,         '123454321',             'guarantorid accessor returns correct value' );
+    is( $patron->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
+    is( $patron->relationship,        'myRelationship',        'relationship accessor returns correct value' );
+    is( $patron->sex,                 'M',                     'sex accessor returns correct value' );
+    is( $patron->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
+    is( $patron->flags,               '55555',                 'flags accessor returns correct value' );
+    is( $patron->userid,              '87987',                 'userid accessor returns correct value' );
+    is( $patron->opacnote,            'myOpacnote',            'opacnote accessor returns correct value' );
+    is( $patron->contactnote,         'myContactnote',         'contactnote accessor returns correct value' );
+    is( $patron->sort1,               'mySort1',               'sort1 accessor returns correct value' );
+    is( $patron->sort2,               'mySort2',               'sort2 accessor returns correct value' );
+    is( $patron->altcontactfirstname, 'myAltcontactfirstname', 'altcontactfirstname accessor returns correct value' );
+    is( $patron->altcontactsurname,   'myAltcontactsurname',   'altcontactsurname accessor returns correct value' );
+    is( $patron->altcontactaddress1,  'myAltcontactaddress1',  'altcontactaddress1 accessor returns correct value' );
+    is( $patron->altcontactaddress2,  'myAltcontactaddress2',  'altcontactaddress2 accessor returns correct value' );
+    is( $patron->altcontactaddress3,  'myAltcontactaddress3',  'altcontactaddress3 accessor returns correct value' );
+    is( $patron->altcontactstate,     'myAltcontactstate',     'altcontactstate accessor returns correct value' );
+    is( $patron->altcontactzipcode,   '465843',                'altcontactzipcode accessor returns correct value' );
+    is( $patron->altcontactcountry,   'myOtherCountry',        'altcontactcountry accessor returns correct value' );
+    is( $patron->altcontactphone,     'myOtherphone',          'altcontactphone accessor returns correct value' );
+    is( $patron->smsalertnumber,      '0683027346',            'smsalertnumber accessor returns correct value' );
+    is( $patron->privacy,             '667788',                'privacy accessor returns correct value' );
+};
+
+# patron Set tests
+subtest 'Set tests' => sub {
+    plan tests => 65;
+
+    $patron->set(
+        {
+            borrowernumber      => '12346',
+            cardnumber          => '1234567891',
+            surname             => 'SmySurname',
+            firstname           => 'SmyFirstname',
+            title               => 'Mme.',
+            othernames          => 'SmyOthernames',
+            initials            => 'SS',
+            streetnumber        => '200',
+            streettype          => 'Rue',
+            address             => 'Smy personnal address',
+            address2            => 'Smy adress2',
+            city                => 'Lyon',
+            state               => 'Smystate',
+            zipcode             => '69000',
+            country             => 'France',
+            email               => 'SmySurname.myFirstname@email.com',
+            phone               => '0402872935',
+            mobile              => '0627884633',
+            fax                 => '0402872936',
+            emailpro            => 'SmyEmailPro@email.com',
+            phonepro            => '0402873335',
+            B_streetnumber      => '102',
+            B_streettype        => 'SmyB_streettype',
+            B_address           => 'SmyB_address',
+            B_address2          => 'SmyB_address2',
+            B_city              => 'SmyB_city',
+            B_state             => 'SmyB_state',
+            B_zipcode           => '12333',
+            B_country           => 'SmyB_country',
+            B_email             => 'SmyB_email',
+            B_phone             => '0678353936',
+            dateofbirth         => '1991-07-16',
+            branchcode          => 'SmyBranCode',
+            categorycode        => 'SmyCatCode',
+            dateenrolled        => '2014-03-19',
+            dateexpiry          => '2017-03-19',
+            gonenoaddress       => '1',
+            lost                => '1',
+            debarred            => '2016-04-19',
+            debarredcomment     => 'You are still debarred',
+            contactname         => 'SmyContactname',
+            contactfirstname    => 'SmyContactfirstname',
+            contacttitle        => 'SmyContacttitle',
+            guarantorid         => '223454321',
+            borrowernotes       => 'Sborrowernotes',
+            relationship        => 'SmyRelationship',
+            sex                 => 'F',
+            password            => 'zerzerzer#',
+            flags               => '666666',
+            userid              => '98233',
+            opacnote            => 'SmyOpacnote',
+            contactnote         => 'SmyContactnote',
+            sort1               => 'SmySort1',
+            sort2               => 'SmySort2',
+            altcontactfirstname => 'SmyAltcontactfirstname',
+            altcontactsurname   => 'SmyAltcontactsurname',
+            altcontactaddress1  => 'SmyAltcontactaddress1',
+            altcontactaddress2  => 'SmyAltcontactaddress2',
+            altcontactaddress3  => 'SmyAltcontactaddress3',
+            altcontactstate     => 'SmyAltcontactstate',
+            altcontactzipcode   => '565843',
+            altcontactcountry   => 'SmyOtherCountry',
+            altcontactphone     => 'SmyOtherphone',
+            smsalertnumber      => '0683027347',
+            privacy             => '667789'
+        }
+    );
+
+    is( $patron->borrowernumber,      '12346',                            'borrowernumber field set ok' );
+    is( $patron->cardnumber,          '1234567891',                       'cardnumber field set ok' );
+    is( $patron->surname,             'SmySurname',                       'surname field set ok' );
+    is( $patron->firstname,           'SmyFirstname',                     'firstname field set ok' );
+    is( $patron->title,               'Mme.',                             'title field set ok' );
+    is( $patron->othernames,          'SmyOthernames',                    'othernames field set ok' );
+    is( $patron->initials,            'SS',                               'initials field set ok' );
+    is( $patron->streetnumber,        '200',                              'streetnumber field set ok' );
+    is( $patron->streettype,          'Rue',                              'streettype field set ok' );
+    is( $patron->address,             'Smy personnal address',            'address field set ok' );
+    is( $patron->address2,            'Smy adress2',                      'address2 field set ok' );
+    is( $patron->city,                'Lyon',                             'city field set ok' );
+    is( $patron->state,               'Smystate',                         'state field set ok' );
+    is( $patron->zipcode,             '69000',                            'zipcode field set ok' );
+    is( $patron->country,             'France',                           'country field set ok' );
+    is( $patron->email,               'SmySurname.myFirstname@email.com', 'email field set ok' );
+    is( $patron->phone,               '0402872935',                       'phone field set ok' );
+    is( $patron->mobile,              '0627884633',                       'mobile field set ok' );
+    is( $patron->fax,                 '0402872936',                       'fax field set ok' );
+    is( $patron->emailpro,            'SmyEmailPro@email.com',            'emailpro field set ok' );
+    is( $patron->phonepro,            '0402873335',                       'phonepro field set ok' );
+    is( $patron->B_streetnumber,      '102',                              'B_streetnumber field set ok' );
+    is( $patron->B_streettype,        'SmyB_streettype',                  'B_streettype field set ok' );
+    is( $patron->B_address,           'SmyB_address',                     'B_address field set ok' );
+    is( $patron->B_address2,          'SmyB_address2',                    'B_address2 field set ok' );
+    is( $patron->B_city,              'SmyB_city',                        'B_city field set ok' );
+    is( $patron->B_state,             'SmyB_state',                       'B_state field set ok' );
+    is( $patron->B_zipcode,           '12333',                            'B_zipcode field set ok' );
+    is( $patron->B_country,           'SmyB_country',                     'B_country field set ok' );
+    is( $patron->B_email,             'SmyB_email',                       'B_email field set ok' );
+    is( $patron->B_phone,             '0678353936',                       'B_phone field set ok' );
+    is( $patron->dateofbirth,         '1991-07-16',                       'dateofbirth field set ok' );
+    is( $patron->branchcode,          'SmyBranCode',                      'branchcode field set ok' );
+    is( $patron->categorycode,        'SmyCatCode',                       'categorycode field set ok' );
+    is( $patron->dateenrolled,        '2014-03-19',                       'dateenrolled field set ok' );
+    is( $patron->dateexpiry,          '2017-03-19',                       'dateexpiry field set ok' );
+    is( $patron->gonenoaddress,       '1',                                'gonenoaddress field set ok' );
+    is( $patron->lost,                '1',                                'lost field set ok' );
+    is( $patron->debarred,            '2016-04-19',                       'debarred field set ok' );
+    is( $patron->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
+    is( $patron->contactname,         'SmyContactname',                   'contactname field set ok' );
+    is( $patron->contactfirstname,    'SmyContactfirstname',              'contactfirstname field set ok' );
+    is( $patron->contacttitle,        'SmyContacttitle',                  'contacttitle field set ok' );
+    is( $patron->guarantorid,         '223454321',                        'guarantorid field set ok' );
+    is( $patron->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
+    is( $patron->relationship,        'SmyRelationship',                  'relationship field set ok' );
+    is( $patron->sex,                 'F',                                'sex field set ok' );
+    is( $patron->password,            'zerzerzer#',                       'password field set ok' );
+    is( $patron->flags,               '666666',                           'flags field set ok' );
+    is( $patron->userid,              '98233',                            'userid field set ok' );
+    is( $patron->opacnote,            'SmyOpacnote',                      'opacnote field set ok' );
+    is( $patron->contactnote,         'SmyContactnote',                   'contactnote field set ok' );
+    is( $patron->sort1,               'SmySort1',                         'sort1 field set ok' );
+    is( $patron->sort2,               'SmySort2',                         'sort2 field set ok' );
+    is( $patron->altcontactfirstname, 'SmyAltcontactfirstname',           'altcontactfirstname field set ok' );
+    is( $patron->altcontactsurname,   'SmyAltcontactsurname',             'altcontactsurname field set ok' );
+    is( $patron->altcontactaddress1,  'SmyAltcontactaddress1',            'altcontactaddress1 field set ok' );
+    is( $patron->altcontactaddress2,  'SmyAltcontactaddress2',            'altcontactaddress2 field set ok' );
+    is( $patron->altcontactaddress3,  'SmyAltcontactaddress3',            'altcontactaddress3 field set ok' );
+    is( $patron->altcontactstate,     'SmyAltcontactstate',               'altcontactstate field set ok' );
+    is( $patron->altcontactzipcode,   '565843',                           'altcontactzipcode field set ok' );
+    is( $patron->altcontactcountry,   'SmyOtherCountry',                  'altcontactcountry field set ok' );
+    is( $patron->altcontactphone,     'SmyOtherphone',                    'altcontactphone field set ok' );
+    is( $patron->smsalertnumber,      '0683027347',                       'smsalertnumber field set ok' );
+    is( $patron->privacy,             '667789',                           'privacy field set ok' );
+};
+
+1;
index 5b9c764..ee92a48 100644 (file)
@@ -27,7 +27,7 @@ use t::lib::TestBuilder;
 BEGIN {
     use_ok('C4::Accounts');
     use_ok('Koha::Object');
-    use_ok('Koha::Borrower');
+    use_ok('Koha::Patron');
     use_ok('Data::Dumper');
 }
 
@@ -107,7 +107,7 @@ my @test_data = (
     { amount => -5    , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day'  , delete => 0 }
 );
 
-my $borrower = Koha::Borrower->new( { firstname => 'Test', surname => 'Patron', categorycode => 'PT', branchcode => 'MPL' } )->store();
+my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => 'PT', branchcode => 'MPL' } )->store();
 
 for my $data ( @test_data ) {
     $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description});
@@ -144,7 +144,7 @@ subtest "recordpayment() tests" => sub {
     my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
     my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
 
-    my $borrower = Koha::Borrower->new( {
+    my $borrower = Koha::Patron->new( {
         cardnumber => '1234567890',
         surname => 'McFly',
         firstname => 'Marty',
index 7f8ef1a..be340b6 100755 (executable)
@@ -21,7 +21,7 @@ use C4::Context;
 use C4::Biblio qw( AddBiblio );
 use Koha::Database;
 use Koha::Libraries;
-use Koha::Borrowers;
+use Koha::Patrons;
 
 use Test::More tests => 4;
 
@@ -35,7 +35,7 @@ my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
 
 my @branches = Koha::Libraries->search();
-my $borrower = Koha::Borrowers->search()->next();
+my $borrower = Koha::Patrons->search()->next();
 
 my $biblio = MARC::Record->new();
 $biblio->append_fields(
diff --git a/t/db_dependent/Borrower.t b/t/db_dependent/Borrower.t
deleted file mode 100755 (executable)
index c619754..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use Test::More tests => 13;
-use Test::Warn;
-
-use C4::Context;
-use Koha::Database;
-
-BEGIN {
-    use_ok('Koha::Object');
-    use_ok('Koha::Borrower');
-}
-
-my $schema = Koha::Database->new->schema;
-$schema->storage->txn_begin;
-
-my $categorycode = $schema->resultset('Category')->first()->categorycode();
-my $branchcode = $schema->resultset('Branch')->first()->branchcode();
-
-my $object = Koha::Borrower->new();
-
-is( $object->in_storage, 0, "Object is not in storage" );
-
-$object->categorycode( $categorycode );
-$object->branchcode( $branchcode );
-$object->surname("Test Surname");
-$object->store();
-
-is( $object->in_storage, 1, "Object is now stored" );
-
-my $borrowernumber = $object->borrowernumber;
-
-my $borrower = $schema->resultset('Borrower')->find( $borrowernumber );
-is( $borrower->surname(), "Test Surname", "Object found in database" );
-
-is( $object->is_changed(), 0, "Object is unchanged" );
-$object->surname("Test Surname");
-is( $object->is_changed(), 0, "Object is still unchanged" );
-$object->surname("Test Surname 2");
-is( $object->is_changed(), 1, "Object is changed" );
-
-$object->store();
-is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
-
-$object->set({ firstname => 'Test Firstname' });
-is( $object->is_changed(), 1, "Object is changed after Set" );
-$object->store();
-is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
-
-$object->delete();
-$borrower = $schema->resultset('Borrower')->find( $borrowernumber );
-ok( ! $borrower, "Object no longer found in database" );
-is( $object->in_storage, 0, "Object is not in storage" );
-
-1;
diff --git a/t/db_dependent/Borrower_Debarments.t b/t/db_dependent/Borrower_Debarments.t
deleted file mode 100755 (executable)
index b05a57c..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/perl
-
-use Modern::Perl;
-
-use C4::Context;
-use C4::Members;
-use Koha::Database;
-
-use t::lib::TestBuilder;
-
-use Test::More tests => 31;
-
-use_ok('Koha::Borrower::Debarments');
-
-my $schema = Koha::Database->schema;
-$schema->storage->txn_begin;
-my $builder = t::lib::TestBuilder->new;
-my $dbh = C4::Context->dbh;
-
-my $library = $builder->build({
-    source => 'Branch',
-});
-
-my $borrowernumber = AddMember(
-    firstname =>  'my firstname',
-    surname => 'my surname',
-    categorycode => 'S',
-    branchcode => $library->{branchcode},
-);
-
-my $success = AddDebarment({
-    borrowernumber => $borrowernumber,
-    expiration => '9999-06-10',
-    type => 'MANUAL',
-    comment => 'Test 1',
-});
-is( $success, 1, "AddDebarment returned true" );
-
-
-my $debarments = GetDebarments({ borrowernumber => $borrowernumber });
-is( @$debarments, 1, "GetDebarments returns 1 debarment" );
-is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" );
-is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" );
-is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" );
-
-
-$success = AddDebarment({
-    borrowernumber => $borrowernumber,
-    comment => 'Test 2',
-});
-
-$debarments = GetDebarments({ borrowernumber => $borrowernumber });
-is( @$debarments, 2, "GetDebarments returns 2 debarments" );
-is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" );
-is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" );
-is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" );
-
-
-ModDebarment({
-    borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'},
-    comment => 'Test 3',
-    expiration => '9998-06-10',
-});
-$debarments = GetDebarments({ borrowernumber => $borrowernumber });
-is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" );
-
-
-my $borrower = GetMember( borrowernumber => $borrowernumber );
-is( $borrower->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly" );
-is( $borrower->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" );
-
-
-AddUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    type           => 'OVERDUES'
-});
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" );
-is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" );
-
-AddUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    expiration => '9999-11-09',
-    type => 'OVERDUES'
-});
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" );
-is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" );
-
-
-my $delUniqueDebarment = DelUniqueDebarment({
-});
-is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" );
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" );
-
-$delUniqueDebarment = DelUniqueDebarment({
-    borrowernumber => $borrowernumber,
-});
-is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" );
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" );
-
-$delUniqueDebarment = DelUniqueDebarment({
-    type => 'OVERDUES'
-});
-is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" );
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" );
-
-$delUniqueDebarment = DelUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    type => 'SUSPENSION',
-});
-is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" );
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" );
-
-$delUniqueDebarment = DelUniqueDebarment({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" );
-$debarments = GetDebarments({
-    borrowernumber => $borrowernumber,
-    type => 'OVERDUES',
-});
-is( @$debarments, 0, "DelUniqueDebarment functions correctly" );
-
-
-$debarments = GetDebarments({ borrowernumber => $borrowernumber });
-foreach my $d ( @$debarments ) {
-    DelDebarment( $d->{'borrower_debarment_id'} );
-}
-$debarments = GetDebarments({ borrowernumber => $borrowernumber });
-is( @$debarments, 0, "DelDebarment functions correctly" );
-
-$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|);
-is( IsDebarred( $borrowernumber ), undef, 'A patron with a debarred date in the past is not debarred' );
-
-$dbh->do(q|UPDATE borrowers SET debarred = NULL|);
-is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is not debarred' );
-
-$dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
-is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' );
diff --git a/t/db_dependent/Borrower_Discharge.t b/t/db_dependent/Borrower_Discharge.t
deleted file mode 100644 (file)
index 99cb58a..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-use Test::More tests => 17;
-use Test::Warn;
-use MARC::Record;
-
-use C4::Biblio qw( AddBiblio );
-use C4::Circulation qw( AddIssue AddReturn );
-use C4::Context;
-use C4::Items qw( AddItem );
-use C4::Members qw( AddMember GetMember );
-
-use Koha::Borrower::Discharge;
-use Koha::Database;
-
-use t::lib::TestBuilder;
-
-my $schema  = Koha::Database->new->schema;
-$schema->storage->txn_begin;
-
-my $builder = t::lib::TestBuilder->new;
-
-my $dbh = C4::Context->dbh;
-$dbh->do(q|DELETE FROM discharges|);
-
-my $library = $builder->build({
-    source => 'Branch',
-});
-my $another_library = $builder->build({
-    source => 'Branch',
-});
-
-C4::Context->_new_userenv('xxx');
-C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', $library->{branchcode}, $library->{branchcode}, '', '', '', '', '');
-my $borrower = $builder->build({
-    source => 'Borrower',
-    value => {
-        branchcode => $library->{branchcode},
-    }
-});
-my $borrower2 = $builder->build({
-    source => 'Borrower',
-    value => {
-        branchcode => $library->{branchcode},
-    }
-});
-my $borrower3 = $builder->build({
-    source => 'Borrower',
-    value => {
-        branchcode => $another_library->{branchcode},
-    }
-});
-
-# Discharge not possible with issues
-my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
-my $barcode = 'BARCODE42';
-my ( undef, undef, $itemnumber ) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $barcode }, $biblionumber);
-AddIssue( $borrower, $barcode );
-is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
-
-is( Koha::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No request done if patron has issues' );
-is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No discharge done if patron has issues' );
-is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request' );
-is_deeply( Koha::Borrower::Discharge::get_validated(), [], 'There is no validated discharge' );
-
-AddReturn( $barcode );
-
-# Discharge possible without issue
-is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 1, 'A patron without issues can be discharged' );
-
-is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
-
-# Verify that the user is not discharged anymore if the restriction has been lifted
-Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower->{borrowernumber} } );
-Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower2->{borrowernumber} } );
-Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower3->{borrowernumber} } );
-is( Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 1, 'The patron has been discharged' );
-is( Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' );
-is( scalar( @{ Koha::Borrower::Discharge::get_validated() } ),             3,            'There are 3 validated discharges' );
-is( scalar( @{ Koha::Borrower::Discharge::get_validated( { borrowernumber => $borrower->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' );
-is( scalar( @{ Koha::Borrower::Discharge::get_validated( { branchcode => $library->{branchcode} } ) } ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
-Koha::Borrower::Debarments::DelUniqueDebarment( { 'borrowernumber' => $borrower->{borrowernumber}, 'type' => 'DISCHARGE' } );
-ok( !Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), 'The debarment has been lifted' );
-ok( !Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
-
-# Verify that the discharge works multiple times
-Koha::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} });
-is(scalar( @{ Koha::Borrower::Discharge::get_pendings() }), 1, 'There is a pending discharge request (second time)');
-Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower->{borrowernumber} } );
-is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request (second time)');
-
-# Check if PDF::FromHTML is installed.
-my $check = eval { require PDF::FromHTML; };
-
-# Tests for if PDF::FromHTML is installed
-if ($check) {
-    isnt( Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber} }), undef, "Temporary PDF generated." );
-}
-# Tests for if PDF::FromHTML is not installed
-else {
-    warning_like { Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber}, testing => 1 }) }
-          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
-          "Expected failure because of missing PDF::FromHTML.";
-}
-
-# FIXME
-# At this point, there is a problem with the AutoCommit off
-# The transaction is bloked into DBIx::Class::Storage::DBI::_dbh_execute
-# line my $rv = $sth->execute();
-# We are using 2 connections and the one used by Koha::Schema has the AutoCommit set to 1
-# Even if we switch off this flag, the connection will be blocked.
-# The error is:
-# DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33
-#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), 1, 'Discharge request sent' );
-
-$schema->storage->txn_rollback;
-
-1;
diff --git a/t/db_dependent/Borrower_Files.t b/t/db_dependent/Borrower_Files.t
deleted file mode 100644 (file)
index 83bf893..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Copyright 2014  Biblibre SARL
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use C4::Context;
-use C4::Members;
-
-use Koha::Database;
-use t::lib::TestBuilder;
-
-use Test::More tests => 23;
-
-use_ok('Koha::Borrower::Files');
-
-my $schema = Koha::Database->schema;
-$schema->storage->txn_begin;
-my $builder = t::lib::TestBuilder->new;
-my $dbh = C4::Context->dbh;
-
-$dbh->do(q|DELETE FROM issues|);
-$dbh->do(q|DELETE FROM borrowers|);
-$dbh->do(q|DELETE FROM borrower_files|);
-
-my $library = $builder->build({
-    source => 'Branch',
-});
-
-my $borrowernumber = AddMember(
-    firstname =>  'my firstname',
-    surname => 'my surname',
-    categorycode => 'S',
-    branchcode => $library->{branchcode},
-);
-
-my $bf = Koha::Borrower::Files->new(
-    borrowernumber => $borrowernumber,
-);
-
-
-my $addFile = $bf->AddFile(
-    name => 'my filename',
-    type => 'text/plain',
-);
-is( $addFile, undef, 'AddFile without the required parameter content returns undef' );
-my $files = $bf->GetFilesInfo();
-is( @$files, 0, 'AddFile does not add a file without the parameter content' );
-
-$addFile = $bf->AddFile(
-    type => 'text/plain',
-    content => 'my filecontent',
-);
-is( $addFile, undef, 'AddFile without the required parameter name returns undef' );
-$files = $bf->GetFilesInfo();
-is( @$files, 0, 'AddFile does not add a file without the parameter name' );
-
-
-my $file1 = {
-    name => 'my filename1',
-    type => 'text/plain',
-    content => 'my filecontent1',
-};
-$addFile = $bf->AddFile(%$file1);
-is( $addFile, 1, 'AddFile with the required parameters returns 1' );
-$files = $bf->GetFilesInfo();
-is( @$files, 1, 'GetFilesInfo returns 1 file' );
-is( $files->[0]->{file_name}, $file1->{name}, 'Correctly stored name' );
-is( $files->[0]->{file_type}, $file1->{type}, 'Correctly stored type' );
-
-
-my $file2 = {
-    name => 'my filename2',
-    type => 'text/html',
-    description => 'my filedescription2',
-    content => 'my filecontent2',
-};
-$addFile = $bf->AddFile(%$file2);
-is( $addFile, 1, 'AddFile with the required parameters returns 1' );
-$files = $bf->GetFilesInfo();
-is( @$files, 2, "GetFilesInfo returns 2 files" );
-is( $files->[1]->{file_name}, $file2->{name}, 'Correctly stored name' );
-is( $files->[1]->{file_type}, $file2->{type}, 'Correctly stored type' );
-is( $files->[1]->{file_description}, $file2->{description}, 'Correctly stored description' );
-
-my $file = $bf->GetFile();
-is( $file, undef, 'GetFile without parameters returns undef' );
-
-$file = $bf->GetFile(
-    id => $files->[1]->{file_id},
-);
-is( $file->{file_name}, $files->[1]->{file_name}, 'GetFile returns the correct name' );
-is( $file->{file_type}, $files->[1]->{file_type}, 'GetFile returns the correct type' );
-is( $file->{file_description}, $files->[1]->{file_description}, 'GetFile returns the correct description' );
-
-
-$bf->DelFile();
-$files = $bf->GetFilesInfo();
-is( @$files, 2, 'DelFile without parameters does not delete a file' );
-
-$bf->DelFile(
-    id => $files->[1]->{file_id},
-);
-$files = $bf->GetFilesInfo();
-is( @$files, 1, 'DelFile delete a file' );
-is( $files->[0]->{file_name}, $file1->{name}, 'DelFile delete the correct entry' );
-is( $files->[0]->{file_type}, $file1->{type}, 'DelFile delete the correct entry' );
-
-$bf->DelFile(
-    id => $files->[0]->{file_id},
-);
-$files = $bf->GetFilesInfo();
-is( @$files, 0, 'DelFile delete a file' );
diff --git a/t/db_dependent/Borrowers.t b/t/db_dependent/Borrowers.t
deleted file mode 100755 (executable)
index 50d9c32..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use Test::More tests => 13;
-use Test::Warn;
-
-use C4::Context;
-use Koha::Database;
-
-BEGIN {
-    use_ok('Koha::Objects');
-    use_ok('Koha::Borrowers');
-}
-
-# Start transaction
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-$dbh->do("DELETE FROM issues");
-$dbh->do("DELETE FROM borrowers");
-
-my $categorycode =
-  Koha::Database->new()->schema()->resultset('Category')->first()
-  ->categorycode();
-my $branchcode =
-  Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
-
-my $b1 = Koha::Borrower->new(
-    {
-        surname      => 'Test 1',
-        branchcode   => $branchcode,
-        categorycode => $categorycode
-    }
-);
-$b1->store();
-my $b2 = Koha::Borrower->new(
-    {
-        surname      => 'Test 2',
-        branchcode   => $branchcode,
-        categorycode => $categorycode
-    }
-);
-$b2->store();
-my $b3 = Koha::Borrower->new(
-    {
-        surname      => 'Test 3',
-        branchcode   => $branchcode,
-        categorycode => $categorycode
-    }
-);
-$b3->store();
-
-my $b1_new = Koha::Borrowers->find( $b1->borrowernumber() );
-is( $b1->surname(), $b1_new->surname(), "Found matching borrower" );
-
-my @borrowers = Koha::Borrowers->search( { branchcode => $branchcode } );
-is( @borrowers, 3, "Found 3 borrowers with Search" );
-
-my $unexistent = Koha::Borrowers->find( '1234567890' );
-is( $unexistent, undef, 'Koha::Objects->Find should return undef if the record does not exist' );
-
-my $borrowers = Koha::Borrowers->search( { branchcode => $branchcode } );
-is( $borrowers->count( { branchcode => $branchcode } ), 3, "Counted 3 borrowers with Count" );
-
-my $b = $borrowers->next();
-is( $b->surname(), 'Test 1', "Next returns first borrower" );
-$b = $borrowers->next();
-is( $b->surname(), 'Test 2', "Next returns second borrower" );
-$b = $borrowers->next();
-is( $b->surname(), 'Test 3', "Next returns third borrower" );
-$b = $borrowers->next();
-is( $b, undef, "Next returns undef" );
-
-# Test Reset and iteration in concert
-$borrowers->reset();
-foreach my $b ( $borrowers->as_list() ) {
-    is( $b->categorycode(), $categorycode, "Iteration returns a borrower object" );
-}
-
-1;
index 5735f86..f6ab089 100644 (file)
@@ -203,7 +203,7 @@ subtest 'Test StoreLastBorrower' => sub {
 
     $item_object   = Koha::Items->find( $item->{itemnumber} );
     $patron_object = $item_object->last_returned_by();
-    is( ref($patron_object), 'Koha::Borrower', 'Koha::Item::last_returned_by returned Koha::Borrower' );
+    is( ref($patron_object), 'Koha::Patron', 'Koha::Item::last_returned_by returned Koha::Patron' );
 
     $patron = $builder->build(
         {
@@ -234,7 +234,7 @@ subtest 'Test StoreLastBorrower' => sub {
             value  => { privacy => 1, }
         }
     );
-    $patron_object = Koha::Borrowers->find( $patron->{borrowernumber} );
+    $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
 
     $item_object->last_returned_by($patron_object);
     $item_object = Koha::Items->find( $item->{itemnumber} );
index 30a336f..78e268d 100644 (file)
@@ -12,7 +12,7 @@ use C4::Items qw( AddItem );
 use C4::Members qw( AddMember GetMember );
 use Koha::Database;
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
+use Koha::Patron::Debarments qw( GetDebarments DelDebarment );
 
 use t::lib::TestBuilder;
 
index fe6b4c9..6408c23 100644 (file)
@@ -29,7 +29,7 @@ BEGIN {
     use_ok('C4::Creators::Lib');
     use_ok('C4::Biblio');
     use_ok('C4::Context');
-    use_ok('Koha::Borrower');
+    use_ok('Koha::Patron');
     use_ok('MARC::Record');
 }
 
index 6307e5d..1395419 100755 (executable)
@@ -20,8 +20,8 @@ use Modern::Perl;
 use C4::Context;
 use C4::Biblio qw( AddBiblio );
 use Koha::Database;
-use Koha::Borrowers;
 use Koha::Libraries;
+use Koha::Patrons;
 use Koha::Item;
 use Koha::DateUtils;
 
@@ -36,7 +36,7 @@ my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
 
 my @branches = Koha::Libraries->search();
-my $borrower = Koha::Borrowers->search()->next();
+my $borrower = Koha::Patrons->search()->next();
 
 my $biblio = MARC::Record->new();
 my $title  = 'Silence in the library';
index ff5d194..73220f8 100755 (executable)
@@ -6,7 +6,7 @@ use Test::More tests => 14;
 use C4::Context;
 use C4::Members;
 
-use Koha::Borrower::Modifications;
+use Koha::Patron::Modifications;
 
 my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
@@ -15,11 +15,11 @@ $dbh->{AutoCommit} = 0;
 $dbh->do("DELETE FROM borrower_modifications");
 
 ## Create new pending modification
-Koha::Borrower::Modifications->new( verification_token => '1234567890' )
+Koha::Patron::Modifications->new( verification_token => '1234567890' )
   ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
 
 ## Get the new pending modification
-my $borrower = Koha::Borrower::Modifications->GetModifications(
+my $borrower = Koha::Patron::Modifications->GetModifications(
     { verification_token => '1234567890' } );
 
 ## Verify we get the same data
@@ -28,65 +28,65 @@ ok( $borrower->{'surname'} = 'Hall',
 
 ## Check the Verify method
 ok(
-    Koha::Borrower::Modifications->Verify('1234567890'),
+    Koha::Patron::Modifications->Verify('1234567890'),
     'Test that Verify() succeeds with a valid token'
 );
 
 ## Delete the pending modification
-$borrower = Koha::Borrower::Modifications->DelModifications(
+$borrower = Koha::Patron::Modifications->DelModifications(
     { verification_token => '1234567890' } );
 
 ## Verify it's no longer in the database
-$borrower = Koha::Borrower::Modifications->GetModifications(
+$borrower = Koha::Patron::Modifications->GetModifications(
     { verification_token => '1234567890' } );
 ok( !defined( $borrower->{'surname'} ), 'Test DelModifications()' );
 
 ## Check the Verify method
 ok(
-    !Koha::Borrower::Modifications->Verify('1234567890'),
+    !Koha::Patron::Modifications->Verify('1234567890'),
     'Test that Verify() method fails for a bad token'
 );
 
 ## Create new pending modification, but for an existing borrower
-Koha::Borrower::Modifications->new( borrowernumber => '2' )
+Koha::Patron::Modifications->new( borrowernumber => '2' )
   ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
 
 ## Test the counter
-ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
+ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1,
     'Test GetPendingModificationsCount()' );
 
 ## Create new pending modification for another existing borrower
-Koha::Borrower::Modifications->new( borrowernumber => '3' )
+Koha::Patron::Modifications->new( borrowernumber => '3' )
   ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
 
 ## Test the counter
 ok(
-    Koha::Borrower::Modifications->GetPendingModificationsCount() == 2,
+    Koha::Patron::Modifications->GetPendingModificationsCount() == 2,
 'Add a new pending modification and test GetPendingModificationsCount() again'
 );
 
 ## Check GetPendingModifications
-my $pendings = Koha::Borrower::Modifications->GetPendingModifications();
+my $pendings = Koha::Patron::Modifications->GetPendingModifications();
 my @firstnames_mod = sort ( $pendings->[0]->{firstname}, $pendings->[1]->{firstname} );
 ok( $firstnames_mod[0] eq 'Kyle', 'Test GetPendingModifications()' );
 ok( $firstnames_mod[1] eq 'Sandy', 'Test GetPendingModifications() again' );
 
 ## This should delete the row from the table
-Koha::Borrower::Modifications->DenyModifications('3');
+Koha::Patron::Modifications->DenyModifications('3');
 
 ## Test the counter
-ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
+ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1,
     'Test DenyModifications()' );
 
 ## Save a copy of the borrowers original data
 my $old_borrower = GetMember( borrowernumber => '2' );
 
 ## Apply the modifications
-Koha::Borrower::Modifications->ApproveModifications('2');
+Koha::Patron::Modifications->ApproveModifications('2');
 
 ## Test the counter
 ok(
-    Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
+    Koha::Patron::Modifications->GetPendingModificationsCount() == 0,
     'Test ApproveModifications() removes pending modification from db'
 );
 
@@ -98,7 +98,7 @@ ok( $new_borrower->{'surname'} eq 'Hall',
     'Test ApproveModifications() applys modification to borrower' );
 
 ## Now let's put it back the way it was
-Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications(
+Koha::Patron::Modifications->new( borrowernumber => '2' )->AddModifications(
     {
         surname   => $old_borrower->{'surname'},
         firstname => $old_borrower->{'firstname'}
@@ -106,15 +106,15 @@ Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications(
 );
 
 ## Test the counter
-ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
+ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1,
     'Test GetPendingModificationsCount()' );
 
 ## Apply the modifications
-Koha::Borrower::Modifications->ApproveModifications('2');
+Koha::Patron::Modifications->ApproveModifications('2');
 
 ## Test the counter
 ok(
-    Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
+    Koha::Patron::Modifications->GetPendingModificationsCount() == 0,
     'Test ApproveModifications() removes pending modification from db, again'
 );
 
diff --git a/t/db_dependent/Patron.t b/t/db_dependent/Patron.t
new file mode 100755 (executable)
index 0000000..11c57fe
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 13;
+use Test::Warn;
+
+use C4::Context;
+use Koha::Database;
+
+BEGIN {
+    use_ok('Koha::Object');
+    use_ok('Koha::Patron');
+}
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $categorycode = $schema->resultset('Category')->first()->categorycode();
+my $branchcode = $schema->resultset('Branch')->first()->branchcode();
+
+my $object = Koha::Patron->new();
+
+is( $object->in_storage, 0, "Object is not in storage" );
+
+$object->categorycode( $categorycode );
+$object->branchcode( $branchcode );
+$object->surname("Test Surname");
+$object->store();
+
+is( $object->in_storage, 1, "Object is now stored" );
+
+my $borrowernumber = $object->borrowernumber;
+
+my $patron = $schema->resultset('Borrower')->find( $borrowernumber );
+is( $patron->surname(), "Test Surname", "Object found in database" );
+
+is( $object->is_changed(), 0, "Object is unchanged" );
+$object->surname("Test Surname");
+is( $object->is_changed(), 0, "Object is still unchanged" );
+$object->surname("Test Surname 2");
+is( $object->is_changed(), 1, "Object is changed" );
+
+$object->store();
+is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
+
+$object->set({ firstname => 'Test Firstname' });
+is( $object->is_changed(), 1, "Object is changed after Set" );
+$object->store();
+is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
+
+$object->delete();
+$patron = $schema->resultset('Borrower')->find( $borrowernumber );
+ok( ! $patron, "Object no longer found in database" );
+is( $object->in_storage, 0, "Object is not in storage" );
+
+1;
diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t
new file mode 100755 (executable)
index 0000000..bb92094
--- /dev/null
@@ -0,0 +1,163 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+
+use C4::Context;
+use C4::Members;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+use Test::More tests => 31;
+
+use_ok('Koha::Patron::Debarments');
+
+my $schema = Koha::Database->schema;
+$schema->storage->txn_begin;
+my $builder = t::lib::TestBuilder->new;
+my $dbh = C4::Context->dbh;
+
+my $library = $builder->build({
+    source => 'Branch',
+});
+
+my $borrowernumber = AddMember(
+    firstname =>  'my firstname',
+    surname => 'my surname',
+    categorycode => 'S',
+    branchcode => $library->{branchcode},
+);
+
+my $success = AddDebarment({
+    borrowernumber => $borrowernumber,
+    expiration => '9999-06-10',
+    type => 'MANUAL',
+    comment => 'Test 1',
+});
+is( $success, 1, "AddDebarment returned true" );
+
+
+my $debarments = GetDebarments({ borrowernumber => $borrowernumber });
+is( @$debarments, 1, "GetDebarments returns 1 debarment" );
+is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" );
+is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" );
+is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" );
+
+
+$success = AddDebarment({
+    borrowernumber => $borrowernumber,
+    comment => 'Test 2',
+});
+
+$debarments = GetDebarments({ borrowernumber => $borrowernumber });
+is( @$debarments, 2, "GetDebarments returns 2 debarments" );
+is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" );
+is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" );
+is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" );
+
+
+ModDebarment({
+    borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'},
+    comment => 'Test 3',
+    expiration => '9998-06-10',
+});
+$debarments = GetDebarments({ borrowernumber => $borrowernumber });
+is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" );
+
+
+my $patron = GetMember( borrowernumber => $borrowernumber );
+is( $patron->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly" );
+is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" );
+
+
+AddUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    type           => 'OVERDUES'
+});
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" );
+is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" );
+
+AddUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    expiration => '9999-11-09',
+    type => 'OVERDUES'
+});
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" );
+is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" );
+
+
+my $delUniqueDebarment = DelUniqueDebarment({
+});
+is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" );
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" );
+
+$delUniqueDebarment = DelUniqueDebarment({
+    borrowernumber => $borrowernumber,
+});
+is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" );
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" );
+
+$delUniqueDebarment = DelUniqueDebarment({
+    type => 'OVERDUES'
+});
+is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" );
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" );
+
+$delUniqueDebarment = DelUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    type => 'SUSPENSION',
+});
+is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" );
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" );
+
+$delUniqueDebarment = DelUniqueDebarment({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" );
+$debarments = GetDebarments({
+    borrowernumber => $borrowernumber,
+    type => 'OVERDUES',
+});
+is( @$debarments, 0, "DelUniqueDebarment functions correctly" );
+
+
+$debarments = GetDebarments({ borrowernumber => $borrowernumber });
+foreach my $d ( @$debarments ) {
+    DelDebarment( $d->{'borrower_debarment_id'} );
+}
+$debarments = GetDebarments({ borrowernumber => $borrowernumber });
+is( @$debarments, 0, "DelDebarment functions correctly" );
+
+$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|);
+is( IsDebarred( $borrowernumber ), undef, 'A patron with a debarred date in the past is not debarred' );
+
+$dbh->do(q|UPDATE borrowers SET debarred = NULL|);
+is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is not debarred' );
+
+$dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
+is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' );
diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t
new file mode 100644 (file)
index 0000000..4090475
--- /dev/null
@@ -0,0 +1,133 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+use Test::More tests => 17;
+use Test::Warn;
+use MARC::Record;
+
+use C4::Biblio qw( AddBiblio );
+use C4::Circulation qw( AddIssue AddReturn );
+use C4::Context;
+use C4::Items qw( AddItem );
+use C4::Members qw( AddMember GetMember );
+
+use Koha::Patron::Discharge;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+my $schema  = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+
+my $dbh = C4::Context->dbh;
+$dbh->do(q|DELETE FROM discharges|);
+
+my $library = $builder->build({
+    source => 'Branch',
+});
+my $another_library = $builder->build({
+    source => 'Branch',
+});
+
+C4::Context->_new_userenv('xxx');
+C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', $library->{branchcode}, $library->{branchcode}, '', '', '', '', '');
+my $patron = $builder->build({
+    source => 'Borrower',
+    value => {
+        branchcode => $library->{branchcode},
+    }
+});
+my $patron2 = $builder->build({
+    source => 'Borrower',
+    value => {
+        branchcode => $library->{branchcode},
+    }
+});
+my $patron3 = $builder->build({
+    source => 'Borrower',
+    value => {
+        branchcode => $another_library->{branchcode},
+    }
+});
+
+# Discharge not possible with issues
+my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
+my $barcode = 'BARCODE42';
+my ( undef, undef, $itemnumber ) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $barcode }, $biblionumber);
+AddIssue( $patron, $barcode );
+is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
+
+is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' );
+is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' );
+is_deeply( Koha::Patron::Discharge::get_pendings(), [], 'There is no pending discharge request' );
+is_deeply( Koha::Patron::Discharge::get_validated(), [], 'There is no validated discharge' );
+
+AddReturn( $barcode );
+
+# Discharge possible without issue
+is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 1, 'A patron without issues can be discharged' );
+
+is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
+
+# Verify that the user is not discharged anymore if the restriction has been lifted
+Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
+Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumber} } );
+Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } );
+is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' );
+is( Koha::Patron::Debarments::IsDebarred( $patron->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' );
+is( scalar( @{ Koha::Patron::Discharge::get_validated() } ),             3,            'There are 3 validated discharges' );
+is( scalar( @{ Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' );
+is( scalar( @{ Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) } ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
+Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } );
+ok( !Koha::Patron::Debarments::IsDebarred( $patron->{borrowernumber} ), 'The debarment has been lifted' );
+ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
+
+# Verify that the discharge works multiple times
+Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
+is(scalar( @{ Koha::Patron::Discharge::get_pendings() }), 1, 'There is a pending discharge request (second time)');
+Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
+is_deeply( Koha::Patron::Discharge::get_pendings(), [], 'There is no pending discharge request (second time)');
+
+# Check if PDF::FromHTML is installed.
+my $check = eval { require PDF::FromHTML; };
+
+# Tests for if PDF::FromHTML is installed
+if ($check) {
+    isnt( Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber} }), undef, "Temporary PDF generated." );
+}
+# Tests for if PDF::FromHTML is not installed
+else {
+    warning_like { Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber}, testing => 1 }) }
+          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
+          "Expected failure because of missing PDF::FromHTML.";
+}
+
+# FIXME
+# At this point, there is a problem with the AutoCommit off
+# The transaction is bloked into DBIx::Class::Storage::DBI::_dbh_execute
+# line my $rv = $sth->execute();
+# We are using 2 connections and the one used by Koha::Schema has the AutoCommit set to 1
+# Even if we switch off this flag, the connection will be blocked.
+# The error is:
+# DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33
+#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), 1, 'Discharge request sent' );
+
+$schema->storage->txn_rollback;
+
+1;
diff --git a/t/db_dependent/Patron/Borrower_Files.t b/t/db_dependent/Patron/Borrower_Files.t
new file mode 100644 (file)
index 0000000..251f20a
--- /dev/null
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright 2014  Biblibre SARL
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use C4::Context;
+use C4::Members;
+
+use Koha::Database;
+use t::lib::TestBuilder;
+
+use Test::More tests => 23;
+
+use_ok('Koha::Patron::Files');
+
+my $schema = Koha::Database->schema;
+$schema->storage->txn_begin;
+my $builder = t::lib::TestBuilder->new;
+my $dbh = C4::Context->dbh;
+
+$dbh->do(q|DELETE FROM issues|);
+$dbh->do(q|DELETE FROM borrowers|);
+$dbh->do(q|DELETE FROM borrower_files|);
+
+my $library = $builder->build({
+    source => 'Branch',
+});
+
+my $borrowernumber = AddMember(
+    firstname =>  'my firstname',
+    surname => 'my surname',
+    categorycode => 'S',
+    branchcode => $library->{branchcode},
+);
+
+my $bf = Koha::Patron::Files->new(
+    borrowernumber => $borrowernumber,
+);
+
+
+my $addFile = $bf->AddFile(
+    name => 'my filename',
+    type => 'text/plain',
+);
+is( $addFile, undef, 'AddFile without the required parameter content returns undef' );
+my $files = $bf->GetFilesInfo();
+is( @$files, 0, 'AddFile does not add a file without the parameter content' );
+
+$addFile = $bf->AddFile(
+    type => 'text/plain',
+    content => 'my filecontent',
+);
+is( $addFile, undef, 'AddFile without the required parameter name returns undef' );
+$files = $bf->GetFilesInfo();
+is( @$files, 0, 'AddFile does not add a file without the parameter name' );
+
+
+my $file1 = {
+    name => 'my filename1',
+    type => 'text/plain',
+    content => 'my filecontent1',
+};
+$addFile = $bf->AddFile(%$file1);
+is( $addFile, 1, 'AddFile with the required parameters returns 1' );
+$files = $bf->GetFilesInfo();
+is( @$files, 1, 'GetFilesInfo returns 1 file' );
+is( $files->[0]->{file_name}, $file1->{name}, 'Correctly stored name' );
+is( $files->[0]->{file_type}, $file1->{type}, 'Correctly stored type' );
+
+
+my $file2 = {
+    name => 'my filename2',
+    type => 'text/html',
+    description => 'my filedescription2',
+    content => 'my filecontent2',
+};
+$addFile = $bf->AddFile(%$file2);
+is( $addFile, 1, 'AddFile with the required parameters returns 1' );
+$files = $bf->GetFilesInfo();
+is( @$files, 2, "GetFilesInfo returns 2 files" );
+is( $files->[1]->{file_name}, $file2->{name}, 'Correctly stored name' );
+is( $files->[1]->{file_type}, $file2->{type}, 'Correctly stored type' );
+is( $files->[1]->{file_description}, $file2->{description}, 'Correctly stored description' );
+
+my $file = $bf->GetFile();
+is( $file, undef, 'GetFile without parameters returns undef' );
+
+$file = $bf->GetFile(
+    id => $files->[1]->{file_id},
+);
+is( $file->{file_name}, $files->[1]->{file_name}, 'GetFile returns the correct name' );
+is( $file->{file_type}, $files->[1]->{file_type}, 'GetFile returns the correct type' );
+is( $file->{file_description}, $files->[1]->{file_description}, 'GetFile returns the correct description' );
+
+
+$bf->DelFile();
+$files = $bf->GetFilesInfo();
+is( @$files, 2, 'DelFile without parameters does not delete a file' );
+
+$bf->DelFile(
+    id => $files->[1]->{file_id},
+);
+$files = $bf->GetFilesInfo();
+is( @$files, 1, 'DelFile delete a file' );
+is( $files->[0]->{file_name}, $file1->{name}, 'DelFile delete the correct entry' );
+is( $files->[0]->{file_type}, $file1->{type}, 'DelFile delete the correct entry' );
+
+$bf->DelFile(
+    id => $files->[0]->{file_id},
+);
+$files = $bf->GetFilesInfo();
+is( @$files, 0, 'DelFile delete a file' );
diff --git a/t/db_dependent/Patrons.t b/t/db_dependent/Patrons.t
new file mode 100755 (executable)
index 0000000..b22a6e8
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 13;
+use Test::Warn;
+
+use C4::Context;
+use Koha::Database;
+
+BEGIN {
+    use_ok('Koha::Objects');
+    use_ok('Koha::Patrons');
+}
+
+# Start transaction
+my $dbh = C4::Context->dbh;
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+$dbh->do("DELETE FROM issues");
+$dbh->do("DELETE FROM borrowers");
+
+my $categorycode =
+  Koha::Database->new()->schema()->resultset('Category')->first()
+  ->categorycode();
+my $branchcode =
+  Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
+
+my $b1 = Koha::Patron->new(
+    {
+        surname      => 'Test 1',
+        branchcode   => $branchcode,
+        categorycode => $categorycode
+    }
+);
+$b1->store();
+my $b2 = Koha::Patron->new(
+    {
+        surname      => 'Test 2',
+        branchcode   => $branchcode,
+        categorycode => $categorycode
+    }
+);
+$b2->store();
+my $b3 = Koha::Patron->new(
+    {
+        surname      => 'Test 3',
+        branchcode   => $branchcode,
+        categorycode => $categorycode
+    }
+);
+$b3->store();
+
+my $b1_new = Koha::Patrons->find( $b1->borrowernumber() );
+is( $b1->surname(), $b1_new->surname(), "Found matching patron" );
+
+my @patrons = Koha::Patrons->search( { branchcode => $branchcode } );
+is( @patrons, 3, "Found 3 patrons with Search" );
+
+my $unexistent = Koha::Patrons->find( '1234567890' );
+is( $unexistent, undef, 'Koha::Objects->Find should return undef if the record does not exist' );
+
+my $patrons = Koha::Patrons->search( { branchcode => $branchcode } );
+is( $patrons->count( { branchcode => $branchcode } ), 3, "Counted 3 patrons with Count" );
+
+my $b = $patrons->next();
+is( $b->surname(), 'Test 1', "Next returns first patron" );
+$b = $patrons->next();
+is( $b->surname(), 'Test 2', "Next returns second patron" );
+$b = $patrons->next();
+is( $b->surname(), 'Test 3', "Next returns third patron" );
+$b = $patrons->next();
+is( $b, undef, "Next returns undef" );
+
+# Test Reset and iteration in concert
+$patrons->reset();
+foreach my $b ( $patrons->as_list() ) {
+    is( $b->categorycode(), $categorycode, "Iteration returns a patron object" );
+}
+
+1;
index 381f5e8..248fe3e 100644 (file)
@@ -27,7 +27,7 @@ use Time::Piece;
 BEGIN {
     use_ok('C4::Biblio');
     use_ok('C4::Review');
-    use_ok('Koha::Borrower');
+    use_ok('Koha::Patron');
     use_ok('MARC::Record');
 }
 
@@ -59,7 +59,7 @@ my $builder = t::lib::TestBuilder->new;
 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
 my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
 
-my $b1 = Koha::Borrower->new(
+my $b1 = Koha::Patron->new(
     {   surname      => 'Borrower 1',
         branchcode   => $branchcode,
         categorycode => $categorycode
@@ -67,7 +67,7 @@ my $b1 = Koha::Borrower->new(
 );
 $b1->store();
 
-my $b2 = Koha::Borrower->new(
+my $b2 = Koha::Patron->new(
     {   surname      => 'Borrower 2',
         branchcode   => $branchcode,
         categorycode => $categorycode
@@ -75,7 +75,7 @@ my $b2 = Koha::Borrower->new(
 );
 $b2->store();
 
-my $b3 = Koha::Borrower->new(
+my $b3 = Koha::Patron->new(
     {   surname      => 'Borrower 3',
         branchcode   => $branchcode,
         categorycode => $categorycode
index 344cac9..6bd4e1a 100644 (file)
@@ -25,7 +25,7 @@ use C4::Auth;
 use C4::Context;
 
 use Koha::Database;
-use Koha::Borrower;
+use Koha::Patron;
 
 my $builder = t::lib::TestBuilder->new();
 
index 42e7a8e..e92137e 100755 (executable)
@@ -47,7 +47,7 @@ use C4::Members::AttributeTypes;
 use C4::Members::Messaging;
 use C4::Reports::Guided;
 use C4::Templates;
-use Koha::Borrower::Debarments;
+use Koha::Patron::Debarments;
 use Koha::DateUtils;
 
 use Text::CSV;