Bug 9302: Use patron-title.inc
[koha.git] / t / db_dependent / PatronLists.t
blob63fbc23e8b4dae2279265c27863734e240cfe788
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 => 7;
21 use t::lib::TestBuilder;
23 use Koha::Database;
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
36 my @borrowers = ();
37 foreach (1..10) {
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 } );
51 ModPatronList(
53 patron_list_id => $list2->patron_list_id(),
54 name => 'Test List 3',
55 owner => $owner
58 $list2->discard_changes();
59 ok( $list2->name() eq 'Test List 3', 'ModPatronList works' );
61 AddPatronsToList(
62 { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
64 ok(
65 scalar @borrowers ==
66 $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
67 'AddPatronsToList works for cardnumbers'
70 AddPatronsToList(
72 list => $list2,
73 borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
76 ok(
77 scalar @borrowers ==
78 $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
79 'AddPatronsToList works for borrowernumbers'
82 my @ids =
83 $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
84 DelPatronsFromList(
86 list => $list1,
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 } );
99 @lists =
100 GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
101 ok( !@lists, 'DelPatronList works' );
103 $schema->storage->txn_rollback;