5 use Test
::More tests
=> 25;
11 use_ok
('C4::ClassSource');
13 can_ok
( 'C4::ClassSource',
29 my $dbh = C4
::Context
->dbh;
30 $dbh->{RaiseError
} = 1;
31 $dbh->{AutoCommit
} = 0;
34 $dbh->do(q
|DELETE FROM class_sources
|);
35 $dbh->do(q
|DELETE FROM class_sort_rules
|);
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' );
43 scalar( keys(%{ GetClassSortRules
() }) ),
45 "SortRule1 and SortRules2 have been added"
49 AddClassSource
( 'source1', 'Description_source1', 1, 'sortrule1' );
50 AddClassSource
( 'source2', 'Description_source2', 0, 'sortrule1' );
52 scalar( keys(%{ GetClassSources
() }) ),
54 "Source1 and source2 have been added"
57 #Test GetClassSortRule
59 GetClassSortRule
('sortrule1'),
61 class_sort_rule
=> 'sortrule1',
62 description
=> 'description1',
63 sort_routine
=> 'routine1'
65 "GetClassSort gives sortrule1's information"
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" );
72 #Test GetClassSortRules
73 my $getsortrules = GetClassSortRules
();
78 class_sort_rule
=> 'sortrule1',
79 description
=> 'description1',
80 sort_routine
=> 'routine1'
83 class_sort_rule
=> 'sortrule2',
84 description
=> 'description2',
85 sort_routine
=> 'routine2'
88 "GetClassSortRules returns the id off all SortRule and their information"
92 my $getsource1 = GetClassSource
('source1');
96 cn_source
=> 'source1',
97 description
=> 'Description_source1',
99 class_sort_rule
=> 'sortrule1'
101 "GetClassSource gives source1's information"
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" );
108 #Test GetClassSources
109 my $getsources = GetClassSources
();
114 cn_source
=> 'source1',
115 description
=> 'Description_source1',
117 class_sort_rule
=> 'sortrule1'
120 cn_source
=> 'source2',
121 description
=> 'Description_source2',
123 class_sort_rule
=> 'sortrule1'
126 "GetClassSources returns the id off all sources and their information"
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"
139 #Test GetSourcesForSorSortRule
140 my @sources = GetSourcesForSortRule
('sortrule1');
143 [ 'source1', 'source2' ],
144 "Sortrule1 has source1 and source2"
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" );
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" );
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" );
166 DelClassSource
('source2');
167 is
( scalar( keys(%{ GetClassSources
() }) ), 1, "Source2 has been deleted" );
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" );
175 #Test ModClassSortRule
176 ModClassSortRule
( 'sortrule1', 'description1_modified', 'routine1_modified' );
178 GetClassSortRule
('sortrule1'),
180 class_sort_rule
=> 'sortrule1',
181 description
=> 'description1_modified',
182 sort_routine
=> 'routine1_modified'
184 "Sortrule1 has been modified"
188 ModClassSource
( 'source1', 'Description_source1_modified', 0, 'sortrule1' );
190 GetClassSource
('source1'),
192 cn_source
=> 'source1',
193 description
=> 'Description_source1_modified',
195 class_sort_rule
=> 'sortrule1'
197 "Source1 has been modified"