|
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('_new_dbh', sub { |
| 16 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
| 17 |
|| die "Cannot create handle: $DBI::errstr\n"; |
| 18 |
return $dbh }); |
| 19 |
my $members_attributetypes = [ |
| 20 |
['code','description','repeatable','unique_id','opac_display','password_allowed','staff_searchable','authorised_value_category','display_checkout','catagory_code','class'], |
| 21 |
['one','ISBN','1','1','1','1','1','red','1','orange','green'], |
| 22 |
['two','ISSN','0','0','0','0','0','blue','0','yellow','silver'] |
| 23 |
]; |
| 24 |
|
| 25 |
my $dbh = C4::Context->dbh(); |
| 26 |
|
| 27 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
| 28 |
|
| 29 |
my @members_attributetypes=C4::Members::AttributeTypes::GetAttributeTypes(); |
| 30 |
|
| 31 |
is($members_attributetypes[0]->{'code'},'one', 'First code value is one'); |
| 32 |
|
| 33 |
is($members_attributetypes[1]->{'code'},'two', 'Second code value is two'); |
| 34 |
|
| 35 |
is($members_attributetypes[0]->{'class'},'green', 'First class value is green'); |
| 36 |
|
| 37 |
is($members_attributetypes[1]->{'class'},'silver', 'Second class value is silver'); |
| 38 |
|
| 39 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
| 40 |
|
| 41 |
ok(C4::Members::AttributeTypes::AttributeTypeExists('one'),'checking an attribute type exists'); |
| 42 |
|
| 43 |
ok (! C4::Members::AttributeTypes::AttributeTypeExists('three'),"checking a attribute that isn't in the code doesn't exist"); |
| 44 |
|
| 45 |
$dbh->{mock_add_resultset} = $members_attributetypes; |
| 46 |
|
| 47 |
ok (C4::Members::AttributeTypes->fetch('ISBN'),"testing fetch feature"); |
| 48 |
|
| 49 |
ok (! C4::Members::AttributeTypes->fetch('FAKE'),"testing fetch feature doesn't work if value not in database"); |