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.
23 use Test
::More tests
=> 24;
26 use t
::lib
::TestBuilder
;
29 use Koha
::Biblioitems
;
32 use Koha
::DateUtils
qw(dt_from_string);;
36 use_ok
('Koha::ItemType');
37 use_ok
('Koha::ItemTypes');
40 my $database = Koha
::Database
->new();
41 my $schema = $database->schema();
43 Koha
::ItemTypes
->delete;
48 description
=> 'description',
49 rentalcharge
=> '0.00',
50 imageurl
=> 'imageurl',
52 checkinmsg
=> 'checkinmsg',
53 checkinmsgtype
=> 'checkinmsgtype',
55 defaultreplacecost
=> '0.00',
62 description
=> 'description',
63 rentalcharge
=> '0.00',
64 imageurl
=> 'imageurl',
66 checkinmsg
=> 'checkinmsg',
67 checkinmsgtype
=> 'checkinmsgtype',
69 defaultreplacecost
=> '0.00',
76 description
=> 'description',
77 rentalcharge
=> '0.00',
78 imageurl
=> 'imageurl',
80 checkinmsg
=> 'checkinmsg',
81 checkinmsgtype
=> 'checkinmsgtype',
83 defaultreplacecost
=> '0.00',
87 Koha
::Localization
->new(
89 entity
=> 'itemtypes',
92 translation
=> 'b translated itemtype desc'
95 Koha
::Localization
->new(
97 entity
=> 'itemtypes',
100 translation
=> 'a translated itemtype desc'
103 Koha
::Localization
->new(
105 entity
=> 'something_else',
108 translation
=> 'another thing'
112 my $type = Koha
::ItemTypes
->find('type1');
113 ok
( defined($type), 'first result' );
114 is
( $type->itemtype, 'type1', 'itemtype/code' );
115 is
( $type->description, 'description', 'description' );
116 is
( $type->rentalcharge, '0.000000', 'rentalcharge' );
117 is
( $type->imageurl, 'imageurl', 'imageurl' );
118 is
( $type->summary, 'summary', 'summary' );
119 is
( $type->checkinmsg, 'checkinmsg', 'checkinmsg' );
120 is
( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
122 $type = Koha
::ItemTypes
->find('type2');
123 ok
( defined($type), 'second result' );
124 is
( $type->itemtype, 'type2', 'itemtype/code' );
125 is
( $type->description, 'description', 'description' );
126 is
( $type->rentalcharge, '0.000000', 'rentalcharge' );
127 is
( $type->imageurl, 'imageurl', 'imageurl' );
128 is
( $type->summary, 'summary', 'summary' );
129 is
( $type->checkinmsg, 'checkinmsg', 'checkinmsg' );
130 is
( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
132 t
::lib
::Mocks
::mock_preference
('language', 'en');
133 t
::lib
::Mocks
::mock_preference
('opaclanguages', 'en');
134 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
135 is
( $itemtypes->count, 3, 'There are 3 item types' );
136 my $first_itemtype = $itemtypes->next;
138 $first_itemtype->translated_description,
139 'a translated itemtype desc',
140 'item types should be sorted by translated description'
143 my $builder = t
::lib
::TestBuilder
->new;
144 my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' });
146 is
( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted');
148 my $item = $builder->build_object({ class => 'Koha::Items', value
=> { itype
=> $item_type->itemtype }});
149 is
( $item_type->can_be_deleted, 0, 'An item type that is used by an item cannot be deleted' );
152 my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value
=> { itemtype
=> $item_type->itemtype }});
153 is
( $item_type->can_be_deleted, 0, 'An item type that is used by an item and a biblioitem cannot be deleted' );
156 is
( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' );
158 $schema->txn_rollback;