5 use Test
::More tests
=> 9;
9 use_ok
('Koha::List::Patron');
12 C4
::Context
->_new_userenv('DUMMY SESSION');
13 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, ', ');
15 my $dbh = C4
::Context
->dbh;
16 my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
18 my @borrowers = @
{ $sth->fetchall_arrayref( {} ) };
20 my $owner = $borrowers[0]->{borrowernumber
};
22 my @lists = GetPatronLists
( { owner
=> $owner } );
23 my $list_count_original = @lists;
25 my $list1 = AddPatronList
( { name
=> 'Test List 1', owner
=> $owner } );
26 ok
( $list1->name() eq 'Test List 1', 'AddPatronList works' );
28 my $list2 = AddPatronList
( { name
=> 'Test List 2', owner
=> $owner } );
32 patron_list_id
=> $list2->patron_list_id(),
33 name
=> 'Test List 3',
37 $list2->discard_changes();
38 ok
( $list2->name() eq 'Test List 3', 'ModPatronList works' );
41 { list
=> $list1, cardnumbers
=> [ map { $_->{cardnumber
} } @borrowers ] }
45 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
46 'AddPatronsToList works for cardnumbers'
52 borrowernumbers
=> [ map { $_->{borrowernumber
} } @borrowers ]
57 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
58 'AddPatronsToList works for borrowernumbers'
62 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
66 patron_list_patrons
=> \
@ids,
69 $list1->discard_changes();
70 ok
( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
72 @lists = GetPatronLists
( { owner
=> $owner } );
73 ok
( @lists == $list_count_original + 2, 'GetPatronLists works' );
75 DelPatronList
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
76 DelPatronList
( { patron_list_id
=> $list2->patron_list_id(), owner
=> $owner } );
79 GetPatronLists
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
80 ok
( !@lists, 'DelPatronList works' );