Bug 17835: Mock language pref value
[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 use t::lib::Mocks;
26
27 BEGIN {
28     use_ok('Koha::ItemType');
29     use_ok('Koha::ItemTypes');
30 }
31
32 my $database = Koha::Database->new();
33 my $schema   = $database->schema();
34 $schema->txn_begin;
35 Koha::ItemTypes->delete;
36
37 Koha::ItemType->new(
38     {
39         itemtype       => 'type1',
40         description    => 'description',
41         rentalcharge   => '0.00',
42         imageurl       => 'imageurl',
43         summary        => 'summary',
44         checkinmsg     => 'checkinmsg',
45         checkinmsgtype => 'checkinmsgtype',
46     }
47 )->store;
48
49 Koha::ItemType->new(
50     {
51         itemtype       => 'type2',
52         description    => 'description',
53         rentalcharge   => '0.00',
54         imageurl       => 'imageurl',
55         summary        => 'summary',
56         checkinmsg     => 'checkinmsg',
57         checkinmsgtype => 'checkinmsgtype',
58     }
59 )->store;
60
61 Koha::ItemType->new(
62     {
63         itemtype       => 'type3',
64         description    => 'description',
65         rentalcharge   => '0.00',
66         imageurl       => 'imageurl',
67         summary        => 'summary',
68         checkinmsg     => 'checkinmsg',
69         checkinmsgtype => 'checkinmsgtype',
70     }
71 )->store;
72
73 Koha::Localization->new(
74     {
75         entity      => 'itemtypes',
76         code        => 'type1',
77         lang        => 'en',
78         translation => 'b translated itemtype desc'
79     }
80 )->store;
81 Koha::Localization->new(
82     {
83         entity      => 'itemtypes',
84         code        => 'type2',
85         lang        => 'en',
86         translation => 'a translated itemtype desc'
87     }
88 )->store;
89 Koha::Localization->new(
90     {
91         entity      => 'something_else',
92         code        => 'type2',
93         lang        => 'en',
94         translation => 'another thing'
95     }
96 )->store;
97
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' );
107
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' );
117
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;
123 is(
124     $first_itemtype->translated_description,
125     'a translated itemtype desc',
126     'item types should be sorted by translated description'
127 );
128
129 $schema->txn_rollback;