Lines 1-201
Link Here
|
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 25; |
6 |
use Test::Warn; |
7 |
|
8 |
use C4::Context; |
9 |
|
10 |
BEGIN { |
11 |
use_ok('C4::ClassSource'); |
12 |
} |
13 |
can_ok( 'C4::ClassSource', |
14 |
qw( AddClassSortRule |
15 |
AddClassSource |
16 |
GetClassSort |
17 |
GetClassSortRule |
18 |
GetClassSortRules |
19 |
GetClassSource |
20 |
GetClassSources |
21 |
DelClassSortRule |
22 |
DelClassSource |
23 |
GetSourcesForSortRule |
24 |
ModClassSortRule |
25 |
ModClassSource) |
26 |
); |
27 |
|
28 |
#Start transaction |
29 |
my $dbh = C4::Context->dbh; |
30 |
$dbh->{RaiseError} = 1; |
31 |
$dbh->{AutoCommit} = 0; |
32 |
|
33 |
#Start tests |
34 |
$dbh->do(q|DELETE FROM class_sources|); |
35 |
$dbh->do(q|DELETE FROM class_sort_rules|); |
36 |
|
37 |
#Test AddClassSortRule |
38 |
my $countSources = scalar( keys(%{ GetClassSources() }) ); |
39 |
my $countSources2 = scalar( keys(%{ GetClassSortRules() }) ); |
40 |
AddClassSortRule( 'sortrule1', 'description1', 'routine1' ); |
41 |
AddClassSortRule( 'sortrule2', 'description2', 'routine2' ); |
42 |
is( |
43 |
scalar( keys(%{ GetClassSortRules() }) ), |
44 |
$countSources + 2, |
45 |
"SortRule1 and SortRules2 have been added" |
46 |
); |
47 |
|
48 |
#Test AddClassSource |
49 |
AddClassSource( 'source1', 'Description_source1', 1, 'sortrule1' ); |
50 |
AddClassSource( 'source2', 'Description_source2', 0, 'sortrule1' ); |
51 |
is( |
52 |
scalar( keys(%{ GetClassSources() }) ), |
53 |
$countSources2 + 2, |
54 |
"Source1 and source2 have been added" |
55 |
); |
56 |
|
57 |
#Test GetClassSortRule |
58 |
is_deeply( |
59 |
GetClassSortRule('sortrule1'), |
60 |
{ |
61 |
class_sort_rule => 'sortrule1', |
62 |
description => 'description1', |
63 |
sort_routine => 'routine1' |
64 |
}, |
65 |
"GetClassSort gives sortrule1's information" |
66 |
); |
67 |
is_deeply( GetClassSortRule(), undef, |
68 |
"GetClassSort without params returns undef" ); |
69 |
is_deeply( GetClassSortRule('doesnt_exist'), |
70 |
undef, "GetClassSort with an id which doesn't exist returns undef" ); |
71 |
|
72 |
#Test GetClassSortRules |
73 |
my $getsortrules = GetClassSortRules(); |
74 |
is_deeply( |
75 |
$getsortrules, |
76 |
{ |
77 |
sortrule1 => { |
78 |
class_sort_rule => 'sortrule1', |
79 |
description => 'description1', |
80 |
sort_routine => 'routine1' |
81 |
}, |
82 |
sortrule2 => { |
83 |
class_sort_rule => 'sortrule2', |
84 |
description => 'description2', |
85 |
sort_routine => 'routine2' |
86 |
} |
87 |
}, |
88 |
"GetClassSortRules returns the id off all SortRule and their information" |
89 |
); |
90 |
|
91 |
#Test GetClassSource |
92 |
my $getsource1 = GetClassSource('source1'); |
93 |
is_deeply( |
94 |
$getsource1, |
95 |
{ |
96 |
cn_source => 'source1', |
97 |
description => 'Description_source1', |
98 |
used => 1, |
99 |
class_sort_rule => 'sortrule1' |
100 |
}, |
101 |
"GetClassSource gives source1's information" |
102 |
); |
103 |
is_deeply( GetClassSource(), undef, |
104 |
"GetClassSource without params returns undef" ); |
105 |
is_deeply( GetClassSource('doesnt_exist'), |
106 |
undef, "GetClassSource with an id which doesn't exist returns undef" ); |
107 |
|
108 |
#Test GetClassSources |
109 |
my $getsources = GetClassSources(); |
110 |
is_deeply( |
111 |
$getsources, |
112 |
{ |
113 |
source1 => { |
114 |
cn_source => 'source1', |
115 |
description => 'Description_source1', |
116 |
used => 1, |
117 |
class_sort_rule => 'sortrule1' |
118 |
}, |
119 |
source2 => { |
120 |
cn_source => 'source2', |
121 |
description => 'Description_source2', |
122 |
used => 0, |
123 |
class_sort_rule => 'sortrule1' |
124 |
} |
125 |
}, |
126 |
"GetClassSources returns the id off all sources and their information" |
127 |
); |
128 |
|
129 |
#Test GetClassSort |
130 |
my $getclassSort; |
131 |
warning_like |
132 |
{ $getclassSort = GetClassSort( 'source1', 'sortrule1', 'item1' ) } |
133 |
qr/attempting to use non-existent class sorting routine/, |
134 |
'Non-existent class warning caught'; |
135 |
is( $getclassSort, "SORTRULE1_ITEM1", |
136 |
" the sort key corresponding to Source1 and sortrule1 and item1 is SORTRULE1_ITEM1" |
137 |
); |
138 |
|
139 |
#Test GetSourcesForSorSortRule |
140 |
my @sources = GetSourcesForSortRule('sortrule1'); |
141 |
is_deeply( |
142 |
\@sources, |
143 |
[ 'source1', 'source2' ], |
144 |
"Sortrule1 has source1 and source2" |
145 |
); |
146 |
@sources = GetSourcesForSortRule(); |
147 |
is_deeply( \@sources, [], |
148 |
"Without params GetSourcesForSortRule returns an empty array" ); |
149 |
@sources = GetSourcesForSortRule('doesnt_exist'); |
150 |
is_deeply( \@sources, [], |
151 |
"With a wrong params GetSourcesForSortRule returns an empty array" ); |
152 |
|
153 |
#Test DelClassSortRule |
154 |
#DelClassSortRule ('sortrule1'); |
155 |
#is(scalar (keys (%{ GetClassSortRules() })),1,"SortRule1 has been deleted");#FIXME : impossible if some sources exist |
156 |
DelClassSortRule('sortrule2'); |
157 |
is( scalar( keys(%{ GetClassSortRules() }) ), 1, "SortRule2 has been deleted" ); |
158 |
DelClassSortRule(); |
159 |
is( scalar( keys(%{ GetClassSortRules() }) ), |
160 |
1, "Without params DelClassSortRule doesn't do anything" ); |
161 |
DelClassSortRule('doesnt_exist'); |
162 |
is( scalar( keys(%{ GetClassSortRules() }) ), |
163 |
1, "With wrong id, DelClassSortRule doesn't do anything" ); |
164 |
|
165 |
#Test DelClassSource |
166 |
DelClassSource('source2'); |
167 |
is( scalar( keys(%{ GetClassSources() }) ), 1, "Source2 has been deleted" ); |
168 |
DelClassSource(); |
169 |
is( scalar( keys(%{ GetClassSources() }) ), |
170 |
1, "Without params DelClassSource doesn't do anything" ); |
171 |
DelClassSource('doesnt_exist'); |
172 |
is( scalar( keys(%{ GetClassSources() }) ), |
173 |
1, "With wrong id, DelClassSource doesn't do anything" ); |
174 |
|
175 |
#Test ModClassSortRule |
176 |
ModClassSortRule( 'sortrule1', 'description1_modified', 'routine1_modified' ); |
177 |
is_deeply( |
178 |
GetClassSortRule('sortrule1'), |
179 |
{ |
180 |
class_sort_rule => 'sortrule1', |
181 |
description => 'description1_modified', |
182 |
sort_routine => 'routine1_modified' |
183 |
}, |
184 |
"Sortrule1 has been modified" |
185 |
); |
186 |
|
187 |
#Test ModClassSource |
188 |
ModClassSource( 'source1', 'Description_source1_modified', 0, 'sortrule1' ); |
189 |
is_deeply( |
190 |
GetClassSource('source1'), |
191 |
{ |
192 |
cn_source => 'source1', |
193 |
description => 'Description_source1_modified', |
194 |
used => 0, |
195 |
class_sort_rule => 'sortrule1' |
196 |
}, |
197 |
"Source1 has been modified" |
198 |
); |
199 |
|
200 |
#End transaction |
201 |
$dbh->rollback; |
202 |
- |