Lines 18-30
$dbh->{RaiseError} = 1;
Link Here
|
18 |
|
18 |
|
19 |
$dbh->do(q| |
19 |
$dbh->do(q| |
20 |
DELETE FROM marc_subfield_structure |
20 |
DELETE FROM marc_subfield_structure |
21 |
WHERE kohafield = 'items.new' OR kohafield = 'items.stocknumber' |
21 |
WHERE kohafield = 'items.new_status' OR kohafield = 'items.stocknumber' |
22 |
|); |
22 |
|); |
23 |
|
23 |
|
24 |
my $new_tagfield = 'i'; |
24 |
my $new_tagfield = 'i'; |
25 |
$dbh->do(qq| |
25 |
$dbh->do(qq| |
26 |
INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode) |
26 |
INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode) |
27 |
VALUES ( 952, '$new_tagfield', 'items.new', '' ) |
27 |
VALUES ( 952, '$new_tagfield', 'items.new_status', '' ) |
28 |
|); |
28 |
|); |
29 |
|
29 |
|
30 |
my $record = MARC::Record->new(); |
30 |
my $record = MARC::Record->new(); |
Lines 39-58
my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem(
Link Here
|
39 |
{ |
39 |
{ |
40 |
homebranch => 'CPL', |
40 |
homebranch => 'CPL', |
41 |
holdingbranch => 'CPL', |
41 |
holdingbranch => 'CPL', |
42 |
new => 'new_value', |
42 |
new_status => 'new_value', |
43 |
ccode => 'FIC', |
43 |
ccode => 'FIC', |
44 |
}, |
44 |
}, |
45 |
$biblionumber |
45 |
$biblionumber |
46 |
); |
46 |
); |
47 |
|
47 |
|
48 |
my $item = C4::Items::GetItem( $itemnumber ); |
48 |
my $item = C4::Items::GetItem( $itemnumber ); |
49 |
is ( $item->{new}, 'new_value', q|AddItem insert the 'new' field| ); |
49 |
is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| ); |
50 |
|
50 |
|
51 |
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', ''); |
51 |
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', ''); |
52 |
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
52 |
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
53 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|); |
53 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|); |
54 |
|
54 |
|
55 |
# Update the items.new field if items.ccode eq 'FIC' => should be updated |
55 |
# Update the items.new_status field if items.ccode eq 'FIC' => should be updated |
56 |
my @rules = ( |
56 |
my @rules = ( |
57 |
{ |
57 |
{ |
58 |
conditions => [ |
58 |
conditions => [ |
Lines 63-69
my @rules = (
Link Here
|
63 |
], |
63 |
], |
64 |
substitutions => [ |
64 |
substitutions => [ |
65 |
{ |
65 |
{ |
66 |
field => 'items.new', |
66 |
field => 'items.new_status', |
67 |
value => 'updated_value', |
67 |
value => 'updated_value', |
68 |
}, |
68 |
}, |
69 |
], |
69 |
], |
Lines 74-84
my @rules = (
Link Here
|
74 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
74 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
75 |
|
75 |
|
76 |
my $modified_item = C4::Items::GetItem( $itemnumber ); |
76 |
my $modified_item = C4::Items::GetItem( $itemnumber ); |
77 |
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is updated|); |
77 |
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|); |
78 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
78 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
79 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is updated| ); |
79 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| ); |
80 |
|
80 |
|
81 |
# Update the items.new field if items.ccode eq 'DONT_EXIST' => should not be updated |
81 |
# Update the items.new_status field if items.ccode eq 'DONT_EXIST' => should not be updated |
82 |
@rules = ( |
82 |
@rules = ( |
83 |
{ |
83 |
{ |
84 |
conditions => [ |
84 |
conditions => [ |
Lines 89-95
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew
Link Here
|
89 |
], |
89 |
], |
90 |
substitutions => [ |
90 |
substitutions => [ |
91 |
{ |
91 |
{ |
92 |
field => 'items.new', |
92 |
field => 'items.new_status', |
93 |
value => 'new_updated_value', |
93 |
value => 'new_updated_value', |
94 |
}, |
94 |
}, |
95 |
], |
95 |
], |
Lines 100-108
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew
Link Here
|
100 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
100 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
101 |
|
101 |
|
102 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
102 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
103 |
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is not updated|); |
103 |
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|); |
104 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
104 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
105 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| ); |
105 |
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| ); |
106 |
|
106 |
|
107 |
# Play with age |
107 |
# Play with age |
108 |
$item = C4::Items::GetItem( $itemnumber ); |
108 |
$item = C4::Items::GetItem( $itemnumber ); |
Lines 122-128
$item = C4::Items::GetItem( $itemnumber );
Link Here
|
122 |
], |
122 |
], |
123 |
substitutions => [ |
123 |
substitutions => [ |
124 |
{ |
124 |
{ |
125 |
field => 'items.new', |
125 |
field => 'items.new_status', |
126 |
value => 'new_updated_value', |
126 |
value => 'new_updated_value', |
127 |
}, |
127 |
}, |
128 |
], |
128 |
], |
Lines 131-155
$item = C4::Items::GetItem( $itemnumber );
Link Here
|
131 |
); |
131 |
); |
132 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
132 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
133 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
133 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
134 |
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new value is not updated|); |
134 |
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|); |
135 |
|
135 |
|
136 |
$rules[0]->{age} = 5; |
136 |
$rules[0]->{age} = 5; |
137 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5'; |
137 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5'; |
138 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
138 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
139 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
139 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
140 |
is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new value is updated|); |
140 |
is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|); |
141 |
|
141 |
|
142 |
$rules[0]->{age} = ''; |
142 |
$rules[0]->{age} = ''; |
143 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string'; |
143 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string'; |
144 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
144 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
145 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
145 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
146 |
is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new value is updated|); |
146 |
is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|); |
147 |
|
147 |
|
148 |
$rules[0]->{age} = undef; |
148 |
$rules[0]->{age} = undef; |
149 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef'; |
149 |
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef'; |
150 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
150 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
151 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
151 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
152 |
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new value is updated|); |
152 |
is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|); |
153 |
|
153 |
|
154 |
# Field deletion |
154 |
# Field deletion |
155 |
@rules = ( |
155 |
@rules = ( |
Lines 162-168
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u
Link Here
|
162 |
], |
162 |
], |
163 |
substitutions => [ |
163 |
substitutions => [ |
164 |
{ |
164 |
{ |
165 |
field => 'items.new', |
165 |
field => 'items.new_status', |
166 |
value => '', |
166 |
value => '', |
167 |
}, |
167 |
}, |
168 |
], |
168 |
], |
Lines 173-181
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u
Link Here
|
173 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
173 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
174 |
|
174 |
|
175 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
175 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
176 |
is( $modified_item->{new}, '', q|ToggleNewStatus: The new value is empty|); |
176 |
is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|); |
177 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
177 |
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
178 |
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new field is removed from the item marc| ); |
178 |
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| ); |
179 |
|
179 |
|
180 |
# conditions multiple |
180 |
# conditions multiple |
181 |
@rules = ( |
181 |
@rules = ( |
Lines 192-198
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th
Link Here
|
192 |
], |
192 |
], |
193 |
substitutions => [ |
193 |
substitutions => [ |
194 |
{ |
194 |
{ |
195 |
field => 'items.new', |
195 |
field => 'items.new_status', |
196 |
value => 'new_value', |
196 |
value => 'new_value', |
197 |
}, |
197 |
}, |
198 |
], |
198 |
], |
Lines 203-209
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th
Link Here
|
203 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
203 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
204 |
|
204 |
|
205 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
205 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
206 |
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new value is updated|); |
206 |
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|); |
207 |
|
207 |
|
208 |
@rules = ( |
208 |
@rules = ( |
209 |
{ |
209 |
{ |
Lines 219-225
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple:
Link Here
|
219 |
], |
219 |
], |
220 |
substitutions => [ |
220 |
substitutions => [ |
221 |
{ |
221 |
{ |
222 |
field => 'items.new', |
222 |
field => 'items.new_status', |
223 |
value => 'new_updated_value', |
223 |
value => 'new_updated_value', |
224 |
}, |
224 |
}, |
225 |
], |
225 |
], |
Lines 230-236
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple:
Link Here
|
230 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
230 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
231 |
|
231 |
|
232 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
232 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
233 |
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new value is not updated|); |
233 |
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|); |
234 |
|
234 |
|
235 |
@rules = ( |
235 |
@rules = ( |
236 |
{ |
236 |
{ |
Lines 246-252
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple:
Link Here
|
246 |
], |
246 |
], |
247 |
substitutions => [ |
247 |
substitutions => [ |
248 |
{ |
248 |
{ |
249 |
field => 'items.new', |
249 |
field => 'items.new_status', |
250 |
value => 'new_updated_value', |
250 |
value => 'new_updated_value', |
251 |
}, |
251 |
}, |
252 |
], |
252 |
], |
Lines 257-263
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple:
Link Here
|
257 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
257 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
258 |
|
258 |
|
259 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
259 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
260 |
is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new value is updated|); |
260 |
is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|); |
261 |
|
261 |
|
262 |
@rules = ( |
262 |
@rules = ( |
263 |
{ |
263 |
{ |
Lines 269-275
is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu
Link Here
|
269 |
], |
269 |
], |
270 |
substitutions => [ |
270 |
substitutions => [ |
271 |
{ |
271 |
{ |
272 |
field => 'items.new', |
272 |
field => 'items.new_status', |
273 |
value => 'another_new_updated_value', |
273 |
value => 'another_new_updated_value', |
274 |
}, |
274 |
}, |
275 |
], |
275 |
], |
Lines 280-283
is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu
Link Here
|
280 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
280 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
281 |
|
281 |
|
282 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
282 |
$modified_item = C4::Items::GetItem( $itemnumber ); |
283 |
is( $modified_item->{new}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); |
283 |
is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); |
284 |
- |
|
|