5 use Test::More tests => 9;
9 use_ok('Koha::List::Patron');
12 my $dbh = C4::Context->dbh;
13 my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
15 my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
17 my @lists = GetPatronLists( { owner => 1 } );
18 my $list_count_original = @lists;
20 my $list1 = AddPatronList( { name => 'Test List 1', owner => 1 } );
21 ok( $list1->name() eq 'Test List 1', 'AddPatronList works' );
23 my $list2 = AddPatronList( { name => 'Test List 2', owner => 1 } );
27 patron_list_id => $list2->patron_list_id(),
28 name => 'Test List 3',
32 $list2->discard_changes();
33 ok( $list2->name() eq 'Test List 3', 'ModPatronList works' );
36 { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
40 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
41 'AddPatronsToList works for cardnumbers'
47 borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
52 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
53 'AddPatronsToList works for borrowernumbers'
57 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
61 patron_list_patrons => \@ids,
64 $list1->discard_changes();
65 ok( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
67 @lists = GetPatronLists( { owner => 1 } );
68 ok( @lists == $list_count_original + 2, 'GetPatronLists works' );
70 DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => 1 } );
71 DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => 1 } );
74 GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => 1 } );
75 ok( !@lists, 'DelPatronList works' );