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
=> 9;
21 use t
::lib
::TestBuilder
;
25 use Koha
::List
::Patron
26 qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList );
28 my $schema = Koha
::Database
->schema;
29 $schema->storage->txn_begin;
31 my $builder = t
::lib
::TestBuilder
->new;
33 t
::lib
::Mocks
::mock_userenv
();
35 # Create 10 sample borrowers
38 push @borrowers, $builder->build({ source
=> 'Borrower' });
41 my $owner = $borrowers[0]->{borrowernumber
};
42 my $owner2 = $borrowers[1]->{borrowernumber
};
44 my @lists = GetPatronLists
( { owner
=> $owner } );
45 my $list_count_original = @lists;
47 my $list1 = AddPatronList
( { name
=> 'Test List 1', owner
=> $owner } );
48 is
( $list1->name(), 'Test List 1', 'AddPatronList works' );
50 my $list2 = AddPatronList
( { name
=> 'Test List 2', owner
=> $owner } );
54 patron_list_id
=> $list2->patron_list_id(),
55 name
=> 'Test List 3',
59 $list2->discard_changes();
60 is
( $list2->name(), 'Test List 3', 'ModPatronList works' );
63 { list
=> $list1, cardnumbers
=> [ map { $_->{cardnumber
} } @borrowers ] }
67 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
68 'AddPatronsToList works for cardnumbers'
74 borrowernumbers
=> [ map { $_->{borrowernumber
} } @borrowers ]
79 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
80 'AddPatronsToList works for borrowernumbers'
84 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
88 patron_list_patrons
=> \
@ids,
91 $list1->discard_changes();
92 is
( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' );
94 @lists = GetPatronLists
( { owner
=> $owner } );
95 is
( scalar @lists, $list_count_original + 2, 'GetPatronLists works' );
97 my $list3 = AddPatronList
( { name
=> 'Test List 3', owner
=> $owner2, shared
=> 0 } );
98 @lists = GetPatronLists
( { owner
=> $owner } );
99 is
( scalar @lists, $list_count_original + 2, 'GetPatronLists does not return non-shared list' );
101 my $list4 = AddPatronList
( { name
=> 'Test List 4', owner
=> $owner2, shared
=> 1 } );
102 @lists = GetPatronLists
( { owner
=> $owner } );
103 is
( scalar @lists, $list_count_original + 3, 'GetPatronLists does return shared list' );
105 DelPatronList
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
106 DelPatronList
( { patron_list_id
=> $list2->patron_list_id(), owner
=> $owner } );
109 GetPatronLists
( { patron_list_id
=> $list1->patron_list_id(), owner
=> $owner } );
110 is
( scalar @lists, 0, 'DelPatronList works' );
112 $schema->storage->txn_rollback;