Merge remote-tracking branch 'kc/master' into new/enh/bug_6716
[koha.git] / t / Members_Attributes.t
blobaafd9a9e5e865c55c25a574059394529c078bf69
1 #!/usr/bin/perl
5 use strict;
6 use warnings;
8 use Test::More tests => 11;
10 BEGIN {
11 use_ok('C4::Members::Attributes', qw(:all));
14 INIT {
15 $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'
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'
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'
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'
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'
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'
76 }; # This is important to prevent extended_attributes_merge from touching DB.
80 my @merge_tests = (
82 line1 => "homeroom:501",
83 line2 => "grade:01",
84 merge => "homeroom:501,grade:01",
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",
93 can_ok('C4::Members::Attributes', qw(extended_attributes_merge extended_attributes_code_value_arrayref));
95 ok(ref($C4::Members::Attributes::AttributeTypes) eq 'HASH', '$C4::Members::Attributes::AttributeTypes is a hashref');
97 foreach my $test (@merge_tests) {
98 my ($old, $new, $merged);
99 ok($old = extended_attributes_code_value_arrayref($test->{line1}), "extended_attributes_code_value_arrayref('$test->{line1}')");
100 ok($new = extended_attributes_code_value_arrayref($test->{line2}), "extended_attributes_code_value_arrayref('$test->{line2}')");
101 ok($merged = extended_attributes_merge($old, $new), "extended_attributes_merge(\$old, \$new)");
102 ok($merged = extended_attributes_merge($old, $new, 1), "extended_attributes_merge(\$old, \$new, 1)");