3 # Copyright 2022 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use t::lib::TestBuilder;
26 use Test::More tests => 2;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new;
31 use_ok("Koha::Item::Templates");
33 subtest 'get_available' => sub {
36 $schema->storage->txn_begin;
38 Koha::Item::Templates->search->delete;
40 my $library = $builder->build( { source => 'Branch' } );
41 my $category = $builder->build( { source => 'Category' } );
42 my $patron_1 = Koha::Patron->new(
44 branchcode => $library->{branchcode},
45 categorycode => $category->{categorycode},
46 surname => 'surname for patron1',
47 firstname => 'firstname for patron1',
50 my $patron_2 = Koha::Patron->new(
52 branchcode => $library->{branchcode},
53 categorycode => $category->{categorycode},
54 surname => 'surname for patron2',
55 firstname => 'firstname for patron2',
59 my $owner_template = Koha::Item::Template->new(
61 patron_id => $patron_1->id,
62 name => 'My template',
63 contents => { location => 'test' },
68 my $shared_template = Koha::Item::Template->new(
70 patron_id => $patron_2->id,
71 name => 'My template',
72 contents => { location => 'test' },
77 my $unshared_template = Koha::Item::Template->new(
79 patron_id => $patron_2->id,
80 name => 'My template',
81 contents => { location => 'test' },
86 my $templates = Koha::Item::Templates->get_available( $patron_1->id );
87 is( $templates->{owned}->count, 1, "Got back one owned template" );
88 is( $templates->{shared}->count, 1, "Got back one shared templated" );
90 $schema->storage->txn_rollback;