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 $owner = $borrowers[0]->{borrowernumber
};
19 my @lists = GetPatronLists
( { owner
=> $owner } );
20 my $list_count_original = @lists;
22 my $list1 = AddPatronList
( { name
=> 'Test List 1', owner
=> $owner } );
23 ok
( $list1->name() eq 'Test List 1', 'AddPatronList works' );
25 my $list2 = AddPatronList
( { name
=> 'Test List 2', owner
=> $owner } );
29 patron_list_id
=> $list2->patron_list_id(),
30 name
=> 'Test List 3',
34 $list2->discard_changes();
35 ok
( $list2->name() eq 'Test List 3', 'ModPatronList works' );
38 { list
=> $list1, cardnumbers
=> [ map { $_->{cardnumber
} } @borrowers ] }
42 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
43 'AddPatronsToList works for cardnumbers'
49 borrowernumbers
=> [ map { $_->{borrowernumber
} } @borrowers ]
54 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
55 'AddPatronsToList works for borrowernumbers'
59 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
63 patron_list_patrons
=> \
@ids,
66 $list1->discard_changes();
67 ok
( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
69 @lists = GetPatronLists
( { owner
=> $owner } );
70 ok
( @lists == $list_count_original + 2, 'GetPatronLists works' );
72 DelPatronList
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
73 DelPatronList
( { patron_list_id
=> $list2->patron_list_id(), owner
=> $owner } );
76 GetPatronLists
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
77 ok
( !@lists, 'DelPatronList works' );