Bug 17835: Create a ItemtypeLocalization view
[koha.git] / t / db_dependent / Koha / ItemTypes.t
1 #!/usr/bin/perl
2 #
3 # Copyright 2014 Catalyst IT
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21
22 use Test::More tests => 20;
23 use Data::Dumper;
24 use Koha::Database;
25
26 BEGIN {
27     use_ok('Koha::ItemType');
28     use_ok('Koha::ItemTypes');
29 }
30
31 my $database = Koha::Database->new();
32 my $schema   = $database->schema();
33 $schema->txn_begin;
34 Koha::ItemTypes->delete;
35
36 Koha::ItemType->new(
37     {
38         itemtype       => 'type1',
39         description    => 'description',
40         rentalcharge   => '0.00',
41         imageurl       => 'imageurl',
42         summary        => 'summary',
43         checkinmsg     => 'checkinmsg',
44         checkinmsgtype => 'checkinmsgtype',
45     }
46 )->store;
47
48 Koha::ItemType->new(
49     {
50         itemtype       => 'type2',
51         description    => 'description',
52         rentalcharge   => '0.00',
53         imageurl       => 'imageurl',
54         summary        => 'summary',
55         checkinmsg     => 'checkinmsg',
56         checkinmsgtype => 'checkinmsgtype',
57     }
58 )->store;
59
60 Koha::Localization->new(
61     {
62         entity      => 'itemtypes',
63         code        => 'type1',
64         lang        => 'en',
65         translation => 'b translated itemtype desc'
66     }
67 )->store;
68 Koha::Localization->new(
69     {
70         entity      => 'itemtypes',
71         code        => 'type2',
72         lang        => 'en',
73         translation => 'a translated itemtype desc'
74     }
75 )->store;
76 Koha::Localization->new(
77     {
78         entity      => 'something_else',
79         code        => 'type2',
80         lang        => 'en',
81         translation => 'another thing'
82     }
83 )->store;
84
85 my $type = Koha::ItemTypes->find('type1');
86 ok( defined($type), 'first result' );
87 is( $type->itemtype,       'type1',          'itemtype/code' );
88 is( $type->description,    'description',    'description' );
89 is( $type->rentalcharge,   '0.0000',             'rentalcharge' );
90 is( $type->imageurl,       'imageurl',       'imageurl' );
91 is( $type->summary,        'summary',        'summary' );
92 is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
93 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
94
95 $type = Koha::ItemTypes->find('type2');
96 ok( defined($type), 'second result' );
97 is( $type->itemtype,       'type2',          'itemtype/code' );
98 is( $type->description,    'description',    'description' );
99 is( $type->rentalcharge,   '0.0000',             'rentalcharge' );
100 is( $type->imageurl,       'imageurl',       'imageurl' );
101 is( $type->summary,        'summary',        'summary' );
102 is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
103 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
104
105 my $itemtypes = Koha::ItemTypes->search_with_localization;
106 is( $itemtypes->count, 2, 'There are 2 item types' );
107 my $first_itemtype = $itemtypes->next;
108 is(
109     $first_itemtype->translated_description,
110     'a translated itemtype desc',
111     'item types should be sorted by translated description'
112 );
113
114 $schema->txn_rollback;