Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
|
17 |
use Modern::Perl; |
18 |
|
19 |
use Test::More tests => 8; |
20 |
|
21 |
use C4::Context; |
22 |
use Koha::Database; |
23 |
use Koha::ItemTypes; |
24 |
|
25 |
use t::lib::TestBuilder; |
26 |
use t::lib::Mocks; |
27 |
|
28 |
BEGIN { |
29 |
use_ok('Koha::Template::Plugin::ItemTypes'); |
30 |
} |
31 |
|
32 |
my $schema = Koha::Database->schema; |
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
35 |
$schema->storage->txn_begin; |
36 |
|
37 |
my $plugin = Koha::Template::Plugin::ItemTypes->new(); |
38 |
ok( $plugin, "initialized ItemTypes plugin" ); |
39 |
|
40 |
my $GetDescriptionUndef = $plugin->GetDescription(undef); |
41 |
is($GetDescriptionUndef, q{}, "GetDescription call with undef"); |
42 |
|
43 |
my $GetDescriptionUnknown = $plugin->GetDescription("deliriumtremenssyndrome"); |
44 |
is($GetDescriptionUnknown, q{}, "GetDescription call with unknown type"); |
45 |
|
46 |
my $itemtypeA = $builder->build_object( |
47 |
{ |
48 |
class => 'Koha::ItemTypes', |
49 |
value => { |
50 |
parent_type => undef, |
51 |
description => "Desc itemtype A", |
52 |
} |
53 |
} |
54 |
); |
55 |
Koha::Localization->new( |
56 |
{ |
57 |
entity => 'itemtypes', |
58 |
code => $itemtypeA->itemtype, |
59 |
lang => 'en', |
60 |
translation => 'Translated itemtype A' |
61 |
} |
62 |
)->store; |
63 |
my $itemtypeB = $builder->build_object( |
64 |
{ |
65 |
class => 'Koha::ItemTypes', |
66 |
value => { |
67 |
parent_type => $itemtypeA->itemtype, |
68 |
description => "Desc itemtype B", |
69 |
} |
70 |
} |
71 |
); |
72 |
Koha::Localization->new( |
73 |
{ |
74 |
entity => 'itemtypes', |
75 |
code => $itemtypeB->itemtype, |
76 |
lang => 'en', |
77 |
translation => 'Translated itemtype B' |
78 |
} |
79 |
)->store; |
80 |
|
81 |
my $GetDescriptionA1 = $plugin->GetDescription($itemtypeA->itemtype); |
82 |
is($GetDescriptionA1, "Translated itemtype A", "ItemType without parent - GetDescription without want parent"); |
83 |
my $GetDescriptionA2 = $plugin->GetDescription($itemtypeA->itemtype, 1); |
84 |
is($GetDescriptionA2, "Translated itemtype A", "ItemType without parent - GetDescription with want parent"); |
85 |
|
86 |
my $GetDescriptionB1 = $plugin->GetDescription($itemtypeB->itemtype); |
87 |
is($GetDescriptionB1, "Translated itemtype B", "ItemType with parent - GetDescription without want parent"); |
88 |
my $GetDescriptionB2 = $plugin->GetDescription($itemtypeB->itemtype, 1); |
89 |
is($GetDescriptionB2, "Translated itemtype A->Translated itemtype B", "ItemType with parent - GetDescription with want parent"); |
90 |
|
91 |
$schema->storage->txn_rollback; |
92 |
|
93 |
1; |