|
Lines 1-120
Link Here
|
| 1 |
#!/usr/bin/perl |
|
|
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 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. |
| 9 |
# |
| 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. |
| 14 |
# |
| 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>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More; |
| 21 |
use t::lib::Mocks; |
| 22 |
|
| 23 |
use Module::Load::Conditional qw/check_install/; |
| 24 |
|
| 25 |
BEGIN { |
| 26 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
| 27 |
plan tests => 25; |
| 28 |
} else { |
| 29 |
plan skip_all => "Need Test::DBIx::Class" |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
use_ok('C4::ItemType'); |
| 34 |
|
| 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', |
| 40 |
}, 'Itemtype' ; |
| 41 |
|
| 42 |
sub fixtures { |
| 43 |
my ( $data ) = @_; |
| 44 |
fixtures_ok [ |
| 45 |
Itemtype => [ |
| 46 |
[ |
| 47 |
'itemtype', 'description', 'rentalcharge', 'notforloan', |
| 48 |
'imageurl', 'summary', 'checkinmsg' |
| 49 |
], |
| 50 |
@$data, |
| 51 |
], |
| 52 |
], 'add fixtures'; |
| 53 |
} |
| 54 |
|
| 55 |
my $db = Test::MockModule->new('Koha::Database'); |
| 56 |
$db->mock( _new_schema => sub { return Schema(); } ); |
| 57 |
|
| 58 |
# Mock data |
| 59 |
my $itemtypes = [ |
| 60 |
[ 'BK', 'Books', 0, 0, '', '', 'foo' ], |
| 61 |
[ 'CD', 'CDRom', 0, 0, '', '', 'bar' ] |
| 62 |
]; |
| 63 |
|
| 64 |
my @itemtypes = C4::ItemType->all(); |
| 65 |
is( @itemtypes, 0, 'Testing all itemtypes is empty' ); |
| 66 |
|
| 67 |
# Now lets mock some data |
| 68 |
fixtures($itemtypes); |
| 69 |
|
| 70 |
@itemtypes = C4::ItemType->all(); |
| 71 |
|
| 72 |
is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' ); |
| 73 |
|
| 74 |
is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' ); |
| 75 |
|
| 76 |
is( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' ); |
| 77 |
|
| 78 |
is( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' ); |
| 79 |
|
| 80 |
is( $itemtypes[0]->description, 'Books', 'First description is books' ); |
| 81 |
|
| 82 |
is( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' ); |
| 83 |
|
| 84 |
is( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' ); |
| 85 |
|
| 86 |
is( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' ); |
| 87 |
|
| 88 |
is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' ); |
| 89 |
|
| 90 |
is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' ); |
| 91 |
|
| 92 |
is( $itemtypes[0]->imageurl, '', 'first imageurl is undef' ); |
| 93 |
|
| 94 |
is( $itemtypes[1]->imageurl, '', 'second imageurl is undef' ); |
| 95 |
|
| 96 |
is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' ); |
| 97 |
|
| 98 |
is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' ); |
| 99 |
|
| 100 |
# Test get(), which should return one itemtype |
| 101 |
my $itemtype = C4::ItemType->get( 'BK' ); |
| 102 |
|
| 103 |
is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' ); |
| 104 |
|
| 105 |
is( $itemtype->itemtype, 'BK', 'itemtype is bk' ); |
| 106 |
|
| 107 |
is( $itemtype->description, 'Books', 'description is books' ); |
| 108 |
|
| 109 |
is( $itemtype->rentalcharge, '0', 'rental charge is 0' ); |
| 110 |
|
| 111 |
is( $itemtype->notforloan, '0', 'not for loan is 0' ); |
| 112 |
|
| 113 |
is( $itemtype->imageurl, '', ' not for loan is undef' ); |
| 114 |
|
| 115 |
is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' ); |
| 116 |
|
| 117 |
$itemtype = C4::ItemType->get; |
| 118 |
is( $itemtype, undef, 'C4::ItemType->get should return unless if no parameter is given' ); |
| 119 |
|
| 120 |
1; |
| 121 |
- |