Lines 1-14
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
2 |
# |
3 |
# This Koha test module is a stub! |
3 |
# Tests 'fetch', 'fake db data', and 'checks for existant attributes' |
4 |
# Add more tests here!!! |
|
|
5 |
|
4 |
|
6 |
use strict; |
5 |
use strict; |
7 |
use warnings; |
6 |
use warnings; |
8 |
|
7 |
use Test::MockModule; |
9 |
use Test::More tests => 1; |
8 |
use Test::More tests => 9; |
10 |
|
9 |
|
11 |
BEGIN { |
10 |
BEGIN { |
12 |
use_ok('C4::Members::AttributeTypes'); |
11 |
use_ok('C4::Members::AttributeTypes'); |
13 |
} |
12 |
} |
14 |
|
13 |
|
15 |
- |
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; |
21 |
} |
22 |
); |
23 |
my $members_attributetypes = [ |
24 |
[ |
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' |
31 |
], |
32 |
[ 'one', 'ISBN', '1', '1', '1', '1', '1', 'red', '1', 'orange', 'green' ], |
33 |
[ 'two', 'ISSN', '0', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ] |
34 |
]; |
35 |
|
36 |
my $dbh = C4::Context->dbh(); |
37 |
|
38 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
39 |
|
40 |
my @members_attributetypes = C4::Members::AttributeTypes::GetAttributeTypes(); |
41 |
|
42 |
is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' ); |
43 |
|
44 |
is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' ); |
45 |
|
46 |
is( $members_attributetypes[0]->{'class'}, |
47 |
'green', 'First class value is green' ); |
48 |
|
49 |
is( $members_attributetypes[1]->{'class'}, |
50 |
'silver', 'Second class value is silver' ); |
51 |
|
52 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
53 |
|
54 |
ok( C4::Members::AttributeTypes::AttributeTypeExists('one'), |
55 |
'checking an attribute type exists' ); |
56 |
|
57 |
ok( |
58 |
!C4::Members::AttributeTypes::AttributeTypeExists('three'), |
59 |
"checking a attribute that isn't in the code doesn't exist" |
60 |
); |
61 |
|
62 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
63 |
|
64 |
ok( C4::Members::AttributeTypes->fetch('ISBN'), "testing fetch feature" ); |
65 |
|
66 |
ok( !C4::Members::AttributeTypes->fetch('FAKE'), |
67 |
"testing fetch feature doesn't work if value not in database" ); |