Bug 12403 [Follow-up] Batch record deletion
[koha.git] / t / Members_AttributeTypes.t
blob152fc5340d0047274efb57b202b6743b042b8a95
1 #!/usr/bin/perl
3 # Tests 'fetch', 'fake db data', and 'checks for existant attributes'
5 use strict;
6 use warnings;
7 use Test::MockModule;
8 use Test::More tests => 9;
10 BEGIN {
11 use_ok('C4::Members::AttributeTypes');
14 my $module = new Test::MockModule('C4::Context');
15 $module->mock(
16 '_new_dbh',
17 sub {
18 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19 || die "Cannot create handle: $DBI::errstr\n";
20 return $dbh;
23 my $members_attributetypes = [
25 'code', 'description',
26 'repeatable', 'unique_id',
27 'opac_display', 'password_allowed',
28 'staff_searchable', 'authorised_value_category',
29 'display_checkout', 'catagory_code',
30 'class'
32 [ 'one', 'ISBN', '1', '1', '1', '1', '1', 'red', '1', 'orange', 'green' ],
33 [ 'two', 'ISSN', '0', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ]
36 my $dbh = C4::Context->dbh();
38 $dbh->{mock_add_resultset} = $members_attributetypes;
40 my @members_attributetypes = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1);
42 is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' );
44 is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' );
46 is( $members_attributetypes[0]->{'class'},
47 'green', 'First class value is green' );
49 is( $members_attributetypes[1]->{'class'},
50 'silver', 'Second class value is silver' );
52 $dbh->{mock_add_resultset} = $members_attributetypes;
54 ok( C4::Members::AttributeTypes::AttributeTypeExists('one'),
55 'checking an attribute type exists' );
57 ok(
58 !C4::Members::AttributeTypes::AttributeTypeExists('three'),
59 "checking a attribute that isn't in the code doesn't exist"
62 $dbh->{mock_add_resultset} = $members_attributetypes;
64 ok( C4::Members::AttributeTypes->fetch('ISBN'), "testing fetch feature" );
66 ok( !C4::Members::AttributeTypes->fetch('FAKE'),
67 "testing fetch feature doesn't work if value not in database" );