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