3 # Copyright 2014 Catalyst IT
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use Test::More tests => 20;
28 use_ok('Koha::ItemType');
29 use_ok('Koha::ItemTypes');
32 my $database = Koha::Database->new();
33 my $schema = $database->schema();
35 Koha::ItemTypes->delete;
40 description => 'description',
41 rentalcharge => '0.00',
42 imageurl => 'imageurl',
44 checkinmsg => 'checkinmsg',
45 checkinmsgtype => 'checkinmsgtype',
52 description => 'description',
53 rentalcharge => '0.00',
54 imageurl => 'imageurl',
56 checkinmsg => 'checkinmsg',
57 checkinmsgtype => 'checkinmsgtype',
64 description => 'description',
65 rentalcharge => '0.00',
66 imageurl => 'imageurl',
68 checkinmsg => 'checkinmsg',
69 checkinmsgtype => 'checkinmsgtype',
73 Koha::Localization->new(
75 entity => 'itemtypes',
78 translation => 'b translated itemtype desc'
81 Koha::Localization->new(
83 entity => 'itemtypes',
86 translation => 'a translated itemtype desc'
89 Koha::Localization->new(
91 entity => 'something_else',
94 translation => 'another thing'
98 my $type = Koha::ItemTypes->find('type1');
99 ok( defined($type), 'first result' );
100 is( $type->itemtype, 'type1', 'itemtype/code' );
101 is( $type->description, 'description', 'description' );
102 is( $type->rentalcharge, '0.0000', 'rentalcharge' );
103 is( $type->imageurl, 'imageurl', 'imageurl' );
104 is( $type->summary, 'summary', 'summary' );
105 is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' );
106 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
108 $type = Koha::ItemTypes->find('type2');
109 ok( defined($type), 'second result' );
110 is( $type->itemtype, 'type2', 'itemtype/code' );
111 is( $type->description, 'description', 'description' );
112 is( $type->rentalcharge, '0.0000', 'rentalcharge' );
113 is( $type->imageurl, 'imageurl', 'imageurl' );
114 is( $type->summary, 'summary', 'summary' );
115 is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' );
116 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
118 t::lib::Mocks::mock_preference('language', 'en');
119 t::lib::Mocks::mock_preference('opaclanguages', 'en');
120 my $itemtypes = Koha::ItemTypes->search_with_localization;
121 is( $itemtypes->count, 3, 'There are 3 item types' );
122 my $first_itemtype = $itemtypes->next;
124 $first_itemtype->translated_description,
125 'a translated itemtype desc',
126 'item types should be sorted by translated description'
129 $schema->txn_rollback;