Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2022 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Koha::Database; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
|
26 |
use Test::More tests => 2; |
27 |
|
28 |
my $schema = Koha::Database->new->schema; |
29 |
my $builder = t::lib::TestBuilder->new; |
30 |
|
31 |
use_ok("Koha::Item::Templates"); |
32 |
|
33 |
subtest 'get_available' => sub { |
34 |
plan tests => 2; |
35 |
|
36 |
$schema->storage->txn_begin; |
37 |
|
38 |
Koha::Item::Templates->search->delete; |
39 |
|
40 |
my $library = $builder->build( { source => 'Branch' } ); |
41 |
my $category = $builder->build( { source => 'Category' } ); |
42 |
my $patron_1 = Koha::Patron->new( |
43 |
{ |
44 |
branchcode => $library->{branchcode}, |
45 |
categorycode => $category->{categorycode}, |
46 |
surname => 'surname for patron1', |
47 |
firstname => 'firstname for patron1', |
48 |
} |
49 |
)->store; |
50 |
my $patron_2 = Koha::Patron->new( |
51 |
{ |
52 |
branchcode => $library->{branchcode}, |
53 |
categorycode => $category->{categorycode}, |
54 |
surname => 'surname for patron2', |
55 |
firstname => 'firstname for patron2', |
56 |
} |
57 |
)->store; |
58 |
|
59 |
my $owner_template = Koha::Item::Template->new( |
60 |
{ |
61 |
borrowernumber => $patron_1->id, |
62 |
name => 'My template', |
63 |
contents => { location => 'test' }, |
64 |
is_shared => 0, |
65 |
} |
66 |
)->store(); |
67 |
|
68 |
my $shared_template = Koha::Item::Template->new( |
69 |
{ |
70 |
borrowernumber => $patron_2->id, |
71 |
name => 'My template', |
72 |
contents => { location => 'test' }, |
73 |
is_shared => 1, |
74 |
} |
75 |
)->store(); |
76 |
|
77 |
my $unshared_template = Koha::Item::Template->new( |
78 |
{ |
79 |
borrowernumber => $patron_2->id, |
80 |
name => 'My template', |
81 |
contents => { location => 'test' }, |
82 |
is_shared => 0, |
83 |
} |
84 |
)->store(); |
85 |
|
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" ); |
89 |
|
90 |
$schema->storage->txn_rollback; |
91 |
}; |