Koha/t/lib/KohaTest/Overdues/GetOverdues.pm
Andrew Moore 2cae4efa0a Bug 2176 (3/5): adding methods to manage message_queue, new advance_notices.pl, new C4::SMS module
I've added methods to to C4::Letters to manage the database table
message_queue. This will let us keep track of messages sent
via email, sms, and rss to patrons. That way, we can show the history,
deal with failures, and reconstruct an RSS feed when needed.

misc/cronjobs/overduenotics.pl has been added. It prepares advance notices
and item due notices and stages messages to be sent in the message_queue
table.

C4::Overdues::Getoverdues now takes two optional arguments to tell it how
old of overdues to fetch.

Also, a C4::Circualtion::getUpcomingDueIssues method was added that
advance_notices.pl uses.

misc/cronjobs/process_message_queue.pl has been added. It sends the email
or SMS messages out of the message queue.

The C4::SMS module didn't work at all, and it has been rebuilt to use
an external perl module from CPAN, SMS::Send.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
2008-06-20 13:04:52 -05:00

126 lines
4.2 KiB
Perl

package KohaTest::Overdues::GetOverdues;
use base qw( KohaTest::Overdues );
use strict;
use warnings;
use C4::Overdues;
use Test::More;
=head3 create_overdue_item
=cut
sub startup_60_create_overdue_item : Test( startup => 17 ) {
my $self = shift;
$self->add_biblios( add_items => 1 );
my $biblionumber = $self->{'biblios'}[0];
ok( $biblionumber, 'biblionumber' );
my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber( $biblionumber );
ok( scalar @biblioitems > 0, 'there is at least one biblioitem' );
my $biblioitemnumber = $biblioitems[0]->{'biblioitemnumber'};
ok( $biblioitemnumber, 'got a biblioitemnumber' );
my $items = C4::Items::GetItemsByBiblioitemnumber( $biblioitemnumber);
my $item = $items->[0];
ok( $item->{'itemnumber'}, 'item number' );
$self->{'overdueitemnumber'} = $item->{'itemnumber'};
# let's use the database to do date math for us.
# This is a US date, but that's how C4::Dates likes it, apparently.
my $dbh = C4::Context->dbh();
my $date_list = $dbh->selectcol_arrayref( q( select DATE_FORMAT( FROM_DAYS( TO_DAYS( NOW() ) - 6 ), '%m/%d/%Y' ) ) );
my $six_days_ago = shift( @$date_list );
my $duedate = C4::Dates->new( $six_days_ago );
# diag( Data::Dumper->Dump( [ $duedate ], [ 'duedate' ] ) );
ok( $item->{'barcode'}, 'barcode' )
or diag( Data::Dumper->Dump( [ $item ], [ 'item' ] ) );
# my $item_from_barcode = C4::Items::GetItem( undef, $item->{'barcode'} );
# diag( Data::Dumper->Dump( [ $item_from_barcode ], [ 'item_from_barcode' ] ) );
ok( $self->{'memberid'}, 'memberid' );
my $borrower = C4::Members::GetMember( $self->{'memberid'} );
ok( $borrower->{'borrowernumber'}, 'borrowernumber' );
my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $item->{'barcode'}, $duedate, 0 );
# diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
is( keys %$issuingimpossible, 0, 'issuing is not impossible' );
is( keys %$needsconfirmation, 0, 'issuing needs no confirmation' );
C4::Circulation::AddIssue( $borrower, $item->{'barcode'}, $duedate );
}
sub basic_usage : Test( 2 ) {
my $self = shift;
my $overdues = C4::Overdues::Getoverdues();
isa_ok( $overdues, 'ARRAY' );
is( scalar @$overdues, 1, 'found our one overdue book' );
}
sub limit_minimum_and_maximum : Test( 2 ) {
my $self = shift;
my $overdues = C4::Overdues::Getoverdues( { minimumdays => 1, maximumdays => 100 } );
isa_ok( $overdues, 'ARRAY' );
is( scalar @$overdues, 1, 'found our one overdue book' );
}
sub limit_and_do_not_find_it : Test( 2 ) {
my $self = shift;
my $overdues = C4::Overdues::Getoverdues( { minimumdays => 1, maximumdays => 2 } );
isa_ok( $overdues, 'ARRAY' );
is( scalar @$overdues, 0, 'there are no overdue books in that range.' );
}
=pod
sub run_overduenotices_script : Test( 1 ) {
my $self = shift;
# make sure member wants alerts
C4::Members::Attributes::UpdateBorrowerAttribute($self->{'memberid'},
{ code => 'PREDEmail',
value => '1' } );
# we're screwing with C4::Circulation::GetUpcomingIssues by passing in a negative number.
C4::Members::Attributes::UpdateBorrowerAttribute($self->{'memberid'},
{ code => 'PREDDAYS',
value => '-6' } );
my $before_count = $self->count_message_queue();
my $output = qx( ../misc/cronjobs/advance_notices.pl -c );
my $after_count = $self->count_message_queue();
is( $after_count, $before_count + 1, 'there is one more message in the queue than there used to be.' )
or diag $output;
}
=cut
sub count_message_queue {
my $self = shift;
my $dbh = C4::Context->dbh();
my $statement = q( select count(0) from message_queue where status = 'pending' );
my $countlist = $dbh->selectcol_arrayref( $statement );
return $countlist->[0];
}
1;