3 # This file is part of Koha.
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
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.
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>.
19 use Test::More tests => 8;
25 use t::lib::TestBuilder;
29 use_ok('Koha::Template::Plugin::ItemTypes');
32 my $schema = Koha::Database->schema;
33 my $builder = t::lib::TestBuilder->new;
35 $schema->storage->txn_begin;
37 my $plugin = Koha::Template::Plugin::ItemTypes->new();
38 ok( $plugin, "initialized ItemTypes plugin" );
40 my $GetDescriptionUndef = $plugin->GetDescription(undef);
41 is($GetDescriptionUndef, q{}, "GetDescription call with undef");
43 my $GetDescriptionUnknown = $plugin->GetDescription("deliriumtremenssyndrome");
44 is($GetDescriptionUnknown, q{}, "GetDescription call with unknown type");
46 my $itemtypeA = $builder->build_object(
48 class => 'Koha::ItemTypes',
51 description => "Desc itemtype A",
55 Koha::Localization->new(
57 entity => 'itemtypes',
58 code => $itemtypeA->itemtype,
60 translation => 'Translated itemtype A'
63 my $itemtypeB = $builder->build_object(
65 class => 'Koha::ItemTypes',
67 parent_type => $itemtypeA->itemtype,
68 description => "Desc itemtype B",
72 Koha::Localization->new(
74 entity => 'itemtypes',
75 code => $itemtypeB->itemtype,
77 translation => 'Translated itemtype B'
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");
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");
91 $schema->storage->txn_rollback;