Lines 1-98
Link Here
|
1 |
#!/usr/bin/perl |
|
|
2 |
# |
3 |
# |
4 |
|
5 |
use strict; |
6 |
use warnings; |
7 |
|
8 |
use Test::More tests => 11; |
9 |
|
10 |
BEGIN { |
11 |
use_ok('C4::Members::Attributes', qw(:all)); |
12 |
} |
13 |
|
14 |
INIT { |
15 |
$C4::Members::Attributes::AttributeTypes = { |
16 |
'grade' => { |
17 |
'opac_display' => '1', |
18 |
'staff_searchable' => '1', |
19 |
'description' => 'Grade level', |
20 |
'authorised_value_category' => '', |
21 |
'repeatable' => '0', |
22 |
'code' => 'grade', |
23 |
'unique_id' => '0' |
24 |
}, |
25 |
'deanslist' => { |
26 |
'opac_display' => '0', |
27 |
'staff_searchable' => '1', |
28 |
'description' => 'Deans List (annual)', |
29 |
'authorised_value_category' => '', |
30 |
'repeatable' => '1', |
31 |
'code' => 'deanslist', |
32 |
'unique_id' => '0' |
33 |
}, |
34 |
'somedata' => { |
35 |
'opac_display' => '0', |
36 |
'staff_searchable' => '0', |
37 |
'description' => 'Some Ext. Attribute', |
38 |
'authorised_value_category' => '', |
39 |
'repeatable' => '0', |
40 |
'code' => 'somedata', |
41 |
'unique_id' => '0' |
42 |
}, |
43 |
'extradata' => { |
44 |
'opac_display' => '0', |
45 |
'staff_searchable' => '0', |
46 |
'description' => 'Another Ext. Attribute', |
47 |
'authorised_value_category' => '', |
48 |
'repeatable' => '0', |
49 |
'code' => 'extradata', |
50 |
'unique_id' => '0' |
51 |
}, |
52 |
'school_id' => { |
53 |
'opac_display' => '1', |
54 |
'staff_searchable' => '1', |
55 |
'description' => 'School ID Number', |
56 |
'authorised_value_category' => '', |
57 |
'repeatable' => '0', |
58 |
'code' => 'school_id', |
59 |
'unique_id' => '1' |
60 |
}, |
61 |
'homeroom' => { |
62 |
'opac_display' => '1', |
63 |
'staff_searchable' => '1', |
64 |
'description' => 'Homeroom', |
65 |
'authorised_value_category' => '', |
66 |
'repeatable' => '0', |
67 |
'code' => 'homeroom', |
68 |
'unique_id' => '0' |
69 |
} |
70 |
}; # This is important to prevent extended_attributes_merge from touching DB. |
71 |
} |
72 |
|
73 |
|
74 |
my @merge_tests = ( |
75 |
{ |
76 |
line1 => "homeroom:501", |
77 |
line2 => "grade:01", |
78 |
merge => "homeroom:501,grade:01", |
79 |
}, |
80 |
{ |
81 |
line1 => "homeroom:224,grade:04,deanslist:2008,deanslist:2007,somedata:xxx", |
82 |
line2 => "homeroom:115,grade:05,deanslist:2009,extradata:foobar", |
83 |
merge => "homeroom:115,grade:05,deanslist:2008,deanslist:2007,deanslist:2009,extradata:foobar,somedata:xxx", |
84 |
}, |
85 |
); |
86 |
|
87 |
can_ok('C4::Members::Attributes', qw(extended_attributes_merge extended_attributes_code_value_arrayref)); |
88 |
|
89 |
ok(ref($C4::Members::Attributes::AttributeTypes) eq 'HASH', '$C4::Members::Attributes::AttributeTypes is a hashref'); |
90 |
|
91 |
foreach my $test (@merge_tests) { |
92 |
my ($old, $new, $merged); |
93 |
ok($old = extended_attributes_code_value_arrayref($test->{line1}), "extended_attributes_code_value_arrayref('$test->{line1}')"); |
94 |
ok($new = extended_attributes_code_value_arrayref($test->{line2}), "extended_attributes_code_value_arrayref('$test->{line2}')"); |
95 |
ok($merged = extended_attributes_merge($old, $new), "extended_attributes_merge(\$old, \$new)"); |
96 |
ok($merged = extended_attributes_merge($old, $new, 1), "extended_attributes_merge(\$old, \$new, 1)"); |
97 |
} |
98 |
|
99 |
- |