Koha/t/db_dependent/PatronLists.t
Kyle M Hall 3b70e7e62c Bug 10565: Add a "Patron List" feature for storing and manipulating collections of patrons
The patron lists feature is somewhat similar to the record lists feature
in that it allows a librarian to create a list of patrons for later
retrieval and manipluation. These lists can then be used with the batch
patron modification tool.

Test Plan:
 0) Apply the patch for Bug 8798
 1) Apply this patch
 2) Run updatedatabase.pl
 3) Access the patron lists feature from Koha's Tools menu.
 4) Create a new list via the "New patron list" button.
 5) For this list, click the "Edit" button, and change the list name.
 6) For this list, click the "Add patrons" button, and search for and
    add some patrons to your list.
 7) For this list select some patrons to remove them.
 8) Try both adding some new patrons, and removing some old patrons
    as a single action.
 9) Click the "Patrons" link on the Koha toolbar
10) Search the patrons, or browse by letter to get patron results
11) Check the checkboxes next to one or more patrons, and add the
    selected patrons to your existing list.
12) Change the "Selected patrons" pulldown to "All resultant patrons"
    and add them to your list.
13) Check the checkboxes next to one or more patrons, and add the
    selected patrons to a new list.
14) Try manipulating a list of patrons using the batch patron
    modification tool.
15) Go back to the Patron Lists feature and delete your lists.
16) Run 'prove t/db_dependent/PatronLists.t'

Signed-off-by: Nora Blake <nblake@masslibsystem.org>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2013-10-14 21:29:44 +00:00

75 lines
2 KiB
Perl
Executable file

#!/usr/bin/perl
#
use Modern::Perl;
use Test::More tests => 9;
BEGIN {
use_ok('C4::Context');
use_ok('Koha::List::Patron');
}
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
$sth->execute();
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
my @lists = GetPatronLists( { owner => 1 } );
my $list_count_original = @lists;
my $list1 = AddPatronList( { name => 'Test List 1', owner => 1 } );
ok( $list1->name() eq 'Test List 1', 'AddPatronList works' );
my $list2 = AddPatronList( { name => 'Test List 2', owner => 1 } );
ModPatronList(
{
patron_list_id => $list2->patron_list_id(),
name => 'Test List 3',
owner => 1
}
);
$list2->discard_changes();
ok( $list2->name() eq 'Test List 3', 'ModPatronList works' );
AddPatronsToList(
{ list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
);
ok(
scalar @borrowers ==
$list1->patron_list_patrons()->search_related('borrowernumber')->all(),
'AddPatronsToList works for cardnumbers'
);
AddPatronsToList(
{
list => $list2,
borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
}
);
ok(
scalar @borrowers ==
$list2->patron_list_patrons()->search_related('borrowernumber')->all(),
'AddPatronsToList works for borrowernumbers'
);
my @ids =
$list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
DelPatronsFromList(
{
list => $list1,
patron_list_patrons => \@ids,
}
);
$list1->discard_changes();
ok( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
@lists = GetPatronLists( { owner => 1 } );
ok( @lists == $list_count_original + 2, 'GetPatronLists works' );
DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => 1 } );
DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => 1 } );
@lists =
GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => 1 } );
ok( !@lists, 'DelPatronList works' );