3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test
::More tests
=> 7;
21 use t
::lib
::TestBuilder
;
24 use Koha
::List
::Patron
25 qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList );
27 my $schema = Koha
::Database
->schema;
28 $schema->storage->txn_begin;
30 my $builder = t
::lib
::TestBuilder
->new;
32 C4
::Context
->_new_userenv('DUMMY SESSION');
33 C4
::Context
->set_userenv( 0 ); # Koha::List::Patron only needs a number
35 # Create 10 sample borrowers
38 push @borrowers, $builder->build({ source
=> 'Borrower' });
41 my $owner = $borrowers[0]->{borrowernumber
};
43 my @lists = GetPatronLists
( { owner
=> $owner } );
44 my $list_count_original = @lists;
46 my $list1 = AddPatronList
( { name
=> 'Test List 1', owner
=> $owner } );
47 ok
( $list1->name() eq 'Test List 1', 'AddPatronList works' );
49 my $list2 = AddPatronList
( { name
=> 'Test List 2', owner
=> $owner } );
53 patron_list_id
=> $list2->patron_list_id(),
54 name
=> 'Test List 3',
58 $list2->discard_changes();
59 ok
( $list2->name() eq 'Test List 3', 'ModPatronList works' );
62 { list
=> $list1, cardnumbers
=> [ map { $_->{cardnumber
} } @borrowers ] }
66 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
67 'AddPatronsToList works for cardnumbers'
73 borrowernumbers
=> [ map { $_->{borrowernumber
} } @borrowers ]
78 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
79 'AddPatronsToList works for borrowernumbers'
83 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
87 patron_list_patrons
=> \
@ids,
90 $list1->discard_changes();
91 ok
( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
93 @lists = GetPatronLists
( { owner
=> $owner } );
94 ok
( @lists == $list_count_original + 2, 'GetPatronLists works' );
96 DelPatronList
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
97 DelPatronList
( { patron_list_id
=> $list2->patron_list_id(), owner
=> $owner } );
100 GetPatronLists
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
101 ok
( !@lists, 'DelPatronList works' );
103 $schema->storage->txn_rollback;