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>.
25 use t::lib::TestBuilder;
27 use Test::More tests => 2;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 use_ok("Koha::Item::Templates");
34 subtest 'get_available' => sub {
37 $schema->storage->txn_begin;
39 Koha::Item::Templates->search->delete;
41 my $library = $builder->build( { source => 'Branch' } );
42 my $category = $builder->build( { source => 'Category' } );
43 my $patron_1 = Koha::Patron->new(
45 branchcode => $library->{branchcode},
46 categorycode => $category->{categorycode},
47 surname => 'surname for patron1',
48 firstname => 'firstname for patron1',
51 my $patron_2 = Koha::Patron->new(
53 branchcode => $library->{branchcode},
54 categorycode => $category->{categorycode},
55 surname => 'surname for patron2',
56 firstname => 'firstname for patron2',
60 my $owner_template = Koha::Item::Template->new(
62 patron_id => $patron_1->id,
63 name => 'My template',
64 contents => { location => 'test' },
69 my $shared_template = Koha::Item::Template->new(
71 patron_id => $patron_2->id,
72 name => 'My template',
73 contents => { location => 'test' },
78 my $unshared_template = Koha::Item::Template->new(
80 patron_id => $patron_2->id,
81 name => 'My template',
82 contents => { location => 'test🙂' },
86 $unshared_template->discard_changes; # refresh
87 is( $unshared_template->decoded_contents->{location}, 'test🙂', 'Tested encoding/decoding' );
89 my $templates = Koha::Item::Templates->get_available( $patron_1->id );
90 is( $templates->{owned}->count, 1, "Got back one owned template" );
91 is( $templates->{shared}->count, 1, "Got back one shared templated" );
93 $schema->storage->txn_rollback;