Bug 16911: Koha::Patron::Categories - Add tests for ->get_expiry_date
[koha.git] / t / Members_AttributeTypes.t
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::MockModule;
21 use Test::More;
22
23 use Module::Load::Conditional qw/check_install/;
24
25 BEGIN {
26     if ( check_install( module => 'Test::DBIx::Class' ) ) {
27         plan tests => 10;
28     } else {
29         plan skip_all => "Need Test::DBIx::Class"
30     }
31 }
32
33 use_ok('C4::Members::AttributeTypes');
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 }, 'BorrowerAttributeType', 'Category' ;
41
42 fixtures_ok [
43     Category => [
44         ['categorycode'],
45         ['orange'], ['yellow'],
46     ],
47     BorrowerAttributeType => [
48     [
49         'code',             'description',
50         'repeatable',       'unique_id',
51         'opac_display',
52         'staff_searchable', 'authorised_value_category',
53         'display_checkout', 'category_code',
54         'class'
55     ],
56     [ 'one', 'ISBN', '1', '1', '1', '1', 'red',  '1', 'orange', 'green' ],
57     [ 'two', 'ISSN', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ]
58
59     ],
60 ], 'add fixtures';
61
62 my $db = Test::MockModule->new('Koha::Database');
63 $db->mock( _new_schema => sub { return Schema(); } );
64
65 my @members_attributetypes = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1);
66
67 is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' );
68
69 is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' );
70
71 is( $members_attributetypes[0]->{'class'},
72     'green', 'First class value is green' );
73
74 is( $members_attributetypes[1]->{'class'},
75     'silver', 'Second class value is silver' );
76
77 ok( C4::Members::AttributeTypes::AttributeTypeExists('one'),
78     'checking an attribute type exists' );
79
80 ok(
81     !C4::Members::AttributeTypes::AttributeTypeExists('three'),
82     "checking a attribute that isn't in the code doesn't exist"
83 );
84
85 ok( C4::Members::AttributeTypes->fetch('one'), "testing fetch feature" );
86
87 ok( !C4::Members::AttributeTypes->fetch('FAKE'),
88     "testing fetch feature doesn't work if value not in database" );