Lines 1-6
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
|
2 |
|
3 |
use Test::More tests => 95; |
3 |
use Test::More tests => 114; |
4 |
|
4 |
|
5 |
use Koha::SimpleMARC; |
5 |
use Koha::SimpleMARC; |
6 |
|
6 |
|
Lines 42-50
is( AddModificationTemplateAction(
Link Here
|
42 |
'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX' |
42 |
'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX' |
43 |
), 1, "Add third action"); |
43 |
), 1, "Add third action"); |
44 |
|
44 |
|
|
|
45 |
is( AddModificationTemplateAction( |
46 |
$template_id, 'add_field', 0, |
47 |
'650', 'a', 'Additional', '', '', |
48 |
'', '', '', |
49 |
'unless', '650', 'a', 'exists', '', '', |
50 |
'Add field 650$aAdditional unless 650$a exists' |
51 |
), 1, "Add fourth action"); |
45 |
# Getter |
52 |
# Getter |
|
|
53 |
|
46 |
my @actions = GetModificationTemplateActions( $template_id ); |
54 |
my @actions = GetModificationTemplateActions( $template_id ); |
47 |
is( @actions, 3, "3 actions are insered"); |
55 |
is( @actions, 4, "4 actions are insered"); |
48 |
|
56 |
|
49 |
for my $action ( @actions ) { |
57 |
for my $action ( @actions ) { |
50 |
isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" ); |
58 |
isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" ); |
Lines 73-79
is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar
Link Here
|
73 |
|
81 |
|
74 |
my $third_action = $actions[2]; |
82 |
my $third_action = $actions[2]; |
75 |
is( $third_action->{ordering}, 3, "test ordering for third action" ); |
83 |
is( $third_action->{ordering}, 3, "test ordering for third action" ); |
76 |
is( $third_action->{action}, 'copy_field', "test factionor third action" ); |
84 |
is( $third_action->{action}, 'copy_field', "test action for third action" ); |
77 |
is( $third_action->{from_field}, '606', "test from_field for third action" ); |
85 |
is( $third_action->{from_field}, '606', "test from_field for third action" ); |
78 |
is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" ); |
86 |
is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" ); |
79 |
is( $third_action->{to_field}, '607', "test to_field for third action" ); |
87 |
is( $third_action->{to_field}, '607', "test to_field for third action" ); |
Lines 84-89
is( $third_action->{conditional_subfield}, 'a', "test conditional_subfield for t
Link Here
|
84 |
is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" ); |
92 |
is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" ); |
85 |
is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" ); |
93 |
is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" ); |
86 |
|
94 |
|
|
|
95 |
my $fourth_action = $actions[3]; |
96 |
is( $fourth_action->{ordering}, 4, "test ordering for fourth action" ); |
97 |
is( $fourth_action->{action}, 'add_field', "test action for fourth action" ); |
98 |
is( $fourth_action->{from_field}, '650', "test from_field for fourth action" ); |
99 |
is( $fourth_action->{from_subfield}, 'a', "test from_subfield for fourth action" ); |
100 |
is( $fourth_action->{to_field}, '', "test to_field for fourth action" ); |
101 |
is( $fourth_action->{to_subfield}, '', "test to_subfield for fourth action" ); |
102 |
is( $fourth_action->{conditional}, 'unless', "test conditional for fourth action" ); |
103 |
is( $fourth_action->{conditional_field}, '650', "test conditional_field for fourth action" ); |
104 |
is( $fourth_action->{conditional_subfield}, 'a', "test conditional_subfield for fourth action" ); |
105 |
is( $fourth_action->{conditional_comparison}, 'exists', "test conditional_comparison for fourth action" ); |
106 |
is( $fourth_action->{conditional_value}, '', "test conditional_value for fourth action" ); |
87 |
|
107 |
|
88 |
# Modifications |
108 |
# Modifications |
89 |
is( ModModificationTemplateAction( |
109 |
is( ModModificationTemplateAction( |
Lines 111-136
is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar
Link Here
|
111 |
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' ); |
131 |
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' ); |
112 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' ); |
132 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' ); |
113 |
|
133 |
|
114 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '3', 'First becomes third' ); |
134 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '4', 'First becomes fourth' ); |
115 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' ); |
135 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' ); |
116 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' ); |
136 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' ); |
|
|
137 |
is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '3', 'Fourth becomes third' ); |
117 |
|
138 |
|
|
|
139 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was fourth)' ); |
118 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' ); |
140 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' ); |
119 |
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was second)' ); |
141 |
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was first)' ); |
120 |
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was second)' ); |
|
|
121 |
|
142 |
|
122 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' ); |
143 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' ); |
123 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays again second' ); |
144 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '3', 'Second becomes third' ); |
124 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '3', 'Third becomes again third' ); |
145 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '2', 'Third becomes second' ); |
|
|
146 |
is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '4', 'Fourth becomes again fourth' ); |
125 |
|
147 |
|
126 |
# Cleaning |
148 |
# Cleaning |
127 |
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 2, "Delete the first action, 2 others are reordered" ); |
149 |
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 3, "Delete the first action, 2 others are reordered" ); |
128 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" ); |
150 |
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" ); |
129 |
|
151 |
|
130 |
is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" ); |
152 |
is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" ); |
131 |
|
153 |
|
132 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" ); |
154 |
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" ); |
133 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" ); |
155 |
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" ); |
|
|
156 |
is( GetModificationTemplateAction( $actions[3]->{mmta_id} ), undef, "fourth action does not exist anymore" ); |
134 |
|
157 |
|
135 |
is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" ); |
158 |
is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" ); |
136 |
|
159 |
|
Lines 215-222
is( AddModificationTemplateAction(
Link Here
|
215 |
'Update non existent field 999$a with "non existent"' |
238 |
'Update non existent field 999$a with "non existent"' |
216 |
), 1, 'Add eighth action: update field non existent 999$a with "non existent."'); |
239 |
), 1, 'Add eighth action: update field non existent 999$a with "non existent."'); |
217 |
|
240 |
|
218 |
my $record = new_record(); |
241 |
is( AddModificationTemplateAction( |
|
|
242 |
$template_id, 'update_field', 0, |
243 |
'999', 'a', 'existent - updated.', '', '', |
244 |
'', '', '', |
245 |
'', '', '', '', '', '', |
246 |
'Update existent field 999$a with "existent - updated."' |
247 |
), 1, 'Add ninth action: update field non existent 999$a with "existent - updated."'); |
248 |
|
249 |
is( AddModificationTemplateAction( |
250 |
$template_id, 'add_field', 0, |
251 |
'999', 'a', 'additional existent.', '', '', |
252 |
'', '', '', |
253 |
'', '', '', '', '', '', |
254 |
'Add new existent field 999$a with "additional existent"' |
255 |
), 1, 'Add tenth action: add additional field existent 999$a with "additional existent."'); |
219 |
|
256 |
|
|
|
257 |
is( AddModificationTemplateAction( |
258 |
$template_id, 'add_field', 0, |
259 |
'007', '', 'vxcdq', '', '', |
260 |
'', '', '', |
261 |
'', '', '', '', '', '', |
262 |
'Add new existent field 999$a with "additional existent"' |
263 |
), 1, 'Add eleventh action: add additional field existent 007'); |
264 |
|
265 |
my $record = new_record(); |
220 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
266 |
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); |
221 |
|
267 |
|
222 |
my $expected_record = expected_record_1(); |
268 |
my $expected_record = expected_record_1(); |
Lines 423-429
sub expected_record_1 {
Link Here
|
423 |
), |
469 |
), |
424 |
MARC::Field->new( |
470 |
MARC::Field->new( |
425 |
999, ' ', ' ', |
471 |
999, ' ', ' ', |
426 |
a => 'non existent.', |
472 |
a => 'existent - updated.', |
|
|
473 |
), |
474 |
MARC::Field->new( |
475 |
999, ' ', ' ', |
476 |
a => 'additional existent.', |
477 |
), |
478 |
MARC::Field->new( |
479 |
'007', 'vxcdq', |
427 |
), |
480 |
), |
428 |
); |
481 |
); |
429 |
$record->append_fields(@fields); |
482 |
$record->append_fields(@fields); |