Bug 17835: Add an additional LEFT JOIN condition using DBIx::Class
[srvgit] / 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::ItemType->new(
61     {
62         itemtype       => 'type3',
63         description    => 'description',
64         rentalcharge   => '0.00',
65         imageurl       => 'imageurl',
66         summary        => 'summary',
67         checkinmsg     => 'checkinmsg',
68         checkinmsgtype => 'checkinmsgtype',
69     }
70 )->store;
71
72 Koha::Localization->new(
73     {
74         entity      => 'itemtypes',
75         code        => 'type1',
76         lang        => 'en',
77         translation => 'b translated itemtype desc'
78     }
79 )->store;
80 Koha::Localization->new(
81     {
82         entity      => 'itemtypes',
83         code        => 'type2',
84         lang        => 'en',
85         translation => 'a translated itemtype desc'
86     }
87 )->store;
88 Koha::Localization->new(
89     {
90         entity      => 'something_else',
91         code        => 'type2',
92         lang        => 'en',
93         translation => 'another thing'
94     }
95 )->store;
96
97 my $type = Koha::ItemTypes->find('type1');
98 ok( defined($type), 'first result' );
99 is( $type->itemtype,       'type1',          'itemtype/code' );
100 is( $type->description,    'description',    'description' );
101 is( $type->rentalcharge,   '0.0000',             'rentalcharge' );
102 is( $type->imageurl,       'imageurl',       'imageurl' );
103 is( $type->summary,        'summary',        'summary' );
104 is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
105 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
106
107 $type = Koha::ItemTypes->find('type2');
108 ok( defined($type), 'second result' );
109 is( $type->itemtype,       'type2',          'itemtype/code' );
110 is( $type->description,    'description',    'description' );
111 is( $type->rentalcharge,   '0.0000',             'rentalcharge' );
112 is( $type->imageurl,       'imageurl',       'imageurl' );
113 is( $type->summary,        'summary',        'summary' );
114 is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
115 is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
116
117 my $itemtypes = Koha::ItemTypes->search_with_localization;
118 is( $itemtypes->count, 3, 'There are 3 item types' );
119 my $first_itemtype = $itemtypes->next;
120 is(
121     $first_itemtype->translated_description,
122     'a translated itemtype desc',
123     'item types should be sorted by translated description'
124 );
125
126 $schema->txn_rollback;