Bug 23150: Do not consider gdpr_proc_consent a mandatory field
[koha.git] / t / db_dependent / PatronLists.t
blob6e4f5f8efa356c62f5683fd5b3b7daa28da437f1
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 9;
21 use t::lib::TestBuilder;
22 use t::lib::Mocks;
24 use Koha::Database;
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
36 my @borrowers = ();
37 foreach (1..10) {
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 } );
52 ModPatronList(
54 patron_list_id => $list2->patron_list_id(),
55 name => 'Test List 3',
56 owner => $owner
59 $list2->discard_changes();
60 is( $list2->name(), 'Test List 3', 'ModPatronList works' );
62 AddPatronsToList(
63 { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
65 is(
66 scalar @borrowers,
67 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
68 'AddPatronsToList works for cardnumbers'
71 AddPatronsToList(
73 list => $list2,
74 borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
77 is(
78 scalar @borrowers,
79 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
80 'AddPatronsToList works for borrowernumbers'
83 my @ids =
84 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
85 DelPatronsFromList(
87 list => $list1,
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 } );
108 @lists =
109 GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
110 is( scalar @lists, 0, 'DelPatronList works' );
112 $schema->storage->txn_rollback;