Bug 17431: Remove use of C4::Items and C4::Biblio
[koha.git] / t / db_dependent / PatronLists.t
blob7b8fcf22a258f44deea5b0c267d00bd2a4cfb885
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 9;
7 BEGIN {
8 use_ok('C4::Context');
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");
17 $sth->execute();
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 } );
30 ModPatronList(
32 patron_list_id => $list2->patron_list_id(),
33 name => 'Test List 3',
34 owner => $owner
37 $list2->discard_changes();
38 ok( $list2->name() eq 'Test List 3', 'ModPatronList works' );
40 AddPatronsToList(
41 { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
43 ok(
44 scalar @borrowers ==
45 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
46 'AddPatronsToList works for cardnumbers'
49 AddPatronsToList(
51 list => $list2,
52 borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
55 ok(
56 scalar @borrowers ==
57 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
58 'AddPatronsToList works for borrowernumbers'
61 my @ids =
62 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
63 DelPatronsFromList(
65 list => $list1,
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 } );
78 @lists =
79 GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
80 ok( !@lists, 'DelPatronList works' );