Bug 14778: Install fixtures for t/Members_AttributeTypes.t
[koha.git] / t / Members_AttributeTypes.t
1 #!/usr/bin/perl
2 #
3 # Tests 'fetch', 'fake db data', and 'checks for existant attributes'
4
5 use Modern::Perl;
6 use Test::MockModule;
7 use Test::More tests => 10;
8
9 BEGIN {
10     use_ok('C4::Members::AttributeTypes');
11 }
12
13 use Test::DBIx::Class {
14     schema_class => 'Koha::Schema',
15     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
16     connect_opts => { name_sep => '.', quote_char => '`', },
17     fixture_class => '::Populate',
18 }, 'BorrowerAttributeType', 'Category' ;
19
20 fixtures_ok [
21     Category => [
22         ['categorycode'],
23         ['orange'], ['yellow'],
24     ],
25     BorrowerAttributeType => [
26     [
27         'code',             'description',
28         'repeatable',       'unique_id',
29         'opac_display',     'password_allowed',
30         'staff_searchable', 'authorised_value_category',
31         'display_checkout', 'category_code',
32         'class'
33     ],
34     [ 'one', 'ISBN', '1', '1', '1', '1', '1', 'red',  '1', 'orange', 'green' ],
35     [ 'two', 'ISSN', '0', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ]
36
37     ],
38 ], 'add fixtures';
39
40 my $db = Test::MockModule->new('Koha::Database');
41 $db->mock( _new_schema => sub { return Schema(); } );
42
43 my @members_attributetypes = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1);
44
45 is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' );
46
47 is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' );
48
49 is( $members_attributetypes[0]->{'class'},
50     'green', 'First class value is green' );
51
52 is( $members_attributetypes[1]->{'class'},
53     'silver', 'Second class value is silver' );
54
55 ok( C4::Members::AttributeTypes::AttributeTypeExists('one'),
56     'checking an attribute type exists' );
57
58 ok(
59     !C4::Members::AttributeTypes::AttributeTypeExists('three'),
60     "checking a attribute that isn't in the code doesn't exist"
61 );
62
63 ok( C4::Members::AttributeTypes->fetch('one'), "testing fetch feature" );
64
65 ok( !C4::Members::AttributeTypes->fetch('FAKE'),
66     "testing fetch feature doesn't work if value not in database" );