Bug 20443: Move C4::Members::AttributeTypes::GetAttributeTypes to Koha::Patron::Attri...
[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 use Koha::Patron::Attribute::Types;
26
27 BEGIN {
28     if ( check_install( module => 'Test::DBIx::Class' ) ) {
29         plan tests => 8;
30     } else {
31         plan skip_all => "Need Test::DBIx::Class"
32     }
33 }
34
35 use_ok('C4::Members::AttributeTypes');
36
37 use Test::DBIx::Class;
38
39 fixtures_ok [
40     Category => [
41         ['categorycode'],
42         ['orange'], ['yellow'],
43     ],
44     BorrowerAttributeType => [
45     [
46         'code',             'description',
47         'repeatable',       'unique_id',
48         'opac_display',
49         'staff_searchable', 'authorised_value_category',
50         'display_checkout', 'category_code',
51         'class'
52     ],
53     [ 'one', 'ISBN', '1', '1', '1', '1', 'red',  '1', 'orange', 'green' ],
54     [ 'two', 'ISSN', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ]
55
56     ],
57 ], 'add fixtures';
58
59 my $db = Test::MockModule->new('Koha::Database');
60 $db->mock( _new_schema => sub { return Schema(); } );
61
62 my @members_attributetypes = @{Koha::Patron::Attribute::Types->search->unblessed};
63
64 is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' );
65
66 is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' );
67
68 is( $members_attributetypes[0]->{'class'},
69     'green', 'First class value is green' );
70
71 is( $members_attributetypes[1]->{'class'},
72     'silver', 'Second class value is silver' );
73
74 ok( C4::Members::AttributeTypes->fetch('one'), "testing fetch feature" );
75
76 ok( !C4::Members::AttributeTypes->fetch('FAKE'),
77     "testing fetch feature doesn't work if value not in database" );