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