3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Module
::Load
::Conditional qw
/check_install/;
26 if ( check_install
( module
=> 'Test::DBIx::Class' ) ) {
29 plan skip_all
=> "Need Test::DBIx::Class"
33 use_ok
('C4::ItemType');
35 use Test
::DBIx
::Class
{
36 schema_class
=> 'Koha::Schema',
37 connect_info
=> ['dbi:SQLite:dbname=:memory:','',''],
38 connect_opts
=> { name_sep
=> '.', quote_char
=> '`', },
39 fixture_class
=> '::Populate',
47 'itemtype', 'description', 'rentalcharge', 'notforloan',
48 'imageurl', 'summary', 'checkinmsg'
55 my $db = Test
::MockModule
->new('Koha::Database');
56 $db->mock( _new_schema
=> sub { return Schema
(); } );
60 [ 'BK', 'Books', 0, 0, '', '', 'foo' ],
61 [ 'CD', 'CDRom', 0, 0, '', '', 'bar' ]
64 my @itemtypes = C4
::ItemType
->all();
65 is
( @itemtypes, 0, 'Testing all itemtypes is empty' );
67 # Now lets mock some data
70 @itemtypes = C4
::ItemType
->all();
72 is
( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' );
74 is
( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' );
76 is
( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' );
78 is
( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' );
80 is
( $itemtypes[0]->description, 'Books', 'First description is books' );
82 is
( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' );
84 is
( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' );
86 is
( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' );
88 is
( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
90 is
( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' );
92 is
( $itemtypes[0]->imageurl, '', 'first imageurl is undef' );
94 is
( $itemtypes[1]->imageurl, '', 'second imageurl is undef' );
96 is
( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' );
98 is
( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' );
100 # Test get(), which should return one itemtype
101 my $itemtype = C4
::ItemType
->get( 'BK' );
103 is
( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' );
105 is
( $itemtype->itemtype, 'BK', 'itemtype is bk' );
107 is
( $itemtype->description, 'Books', 'description is books' );
109 is
( $itemtype->rentalcharge, '0', 'rental charge is 0' );
111 is
( $itemtype->notforloan, '0', 'not for loan is 0' );
113 is
( $itemtype->imageurl, '', ' not for loan is undef' );
115 is
( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' );
117 $itemtype = C4
::ItemType
->get;
118 is
( $itemtype, undef, 'C4::ItemType->get should return unless if no parameter is given' );