Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
# Copyright 2023 Hypernova Oy |
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 Test::More tests => 2; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
|
26 |
use Koha::Database; |
27 |
use Koha::Template::Plugin::Frameworks; |
28 |
|
29 |
BEGIN { |
30 |
use_ok('Koha::Template::Plugin::Frameworks'); |
31 |
} |
32 |
|
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
35 |
my $schema = Koha::Database->new->schema; |
36 |
|
37 |
subtest 'GetChildren() tests' => sub { |
38 |
|
39 |
plan tests => 7; |
40 |
|
41 |
$schema->storage->txn_begin; |
42 |
|
43 |
my $parent_framework = $builder->build_object( { class => 'Koha::BiblioFrameworks' } ); |
44 |
|
45 |
my $plugin = Koha::Template::Plugin::Frameworks->new(); |
46 |
|
47 |
is( scalar @{ $plugin->GetChildren() }, 0, 'No child frameworks' ); |
48 |
is( scalar @{ $plugin->GetChildren( $parent_framework->frameworkcode ) }, 0, 'No child frameworks' ); |
49 |
|
50 |
my $child_framework = $builder->build_object( |
51 |
{ |
52 |
class => 'Koha::BiblioFrameworks', |
53 |
value => { parent_frameworkcode => $parent_framework->frameworkcode, frameworktext => 'afirst' } |
54 |
} |
55 |
); |
56 |
is( scalar @{ $plugin->GetChildren( $parent_framework->frameworkcode ) }, 1, 'One child framework' ); |
57 |
is( |
58 |
$plugin->GetChildren( $parent_framework->frameworkcode )->[0]->{'frameworkcode'}, |
59 |
$child_framework->frameworkcode, 'No child frameworks' |
60 |
); |
61 |
my $child_framework2 = $builder->build_object( |
62 |
{ |
63 |
class => 'Koha::BiblioFrameworks', |
64 |
value => { parent_frameworkcode => $parent_framework->frameworkcode, frameworktext => 'bsecond' } |
65 |
} |
66 |
); |
67 |
is( scalar @{ $plugin->GetChildren( $parent_framework->frameworkcode ) }, 2, 'Two child frameworks' ); |
68 |
|
69 |
# note: elements returned by GetChildren() are ordered by frameworktext |
70 |
# the two following tests depend on this fact |
71 |
is( |
72 |
$plugin->GetChildren( $parent_framework->frameworkcode )->[0]->{'frameworkcode'}, |
73 |
$child_framework->frameworkcode, 'First child framework found' |
74 |
); |
75 |
is( |
76 |
$plugin->GetChildren( $parent_framework->frameworkcode )->[1]->{'frameworkcode'}, |
77 |
$child_framework2->frameworkcode, 'Second child framework found' |
78 |
); |
79 |
|
80 |
$schema->storage->txn_rollback; |
81 |
}; |