|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 4; |
23 |
use Test::More tests => 5; |
| 24 |
|
24 |
|
| 25 |
use Koha::Edifact::Order; |
25 |
use Koha::Edifact::Order; |
| 26 |
|
26 |
|
|
Lines 138-143
subtest 'order_line() tests' => sub {
Link Here
|
| 138 |
# Set EdifactLSQ field to default |
138 |
# Set EdifactLSQ field to default |
| 139 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
139 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
| 140 |
|
140 |
|
|
|
141 |
# Ensure EdifactLSL is empty to maintain backwards compatibility |
| 142 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); |
| 143 |
|
| 141 |
$order->basket->create_items('ordering')->store; |
144 |
$order->basket->create_items('ordering')->store; |
| 142 |
is( |
145 |
is( |
| 143 |
$edi_order->order_line( 1, $orders[0] ), |
146 |
$edi_order->order_line( 1, $orders[0] ), |
|
Lines 217-222
subtest 'order_line() tests' => sub {
Link Here
|
| 217 |
# Set EdifactLSQ field to ccode |
220 |
# Set EdifactLSQ field to ccode |
| 218 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'ccode' ); |
221 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'ccode' ); |
| 219 |
|
222 |
|
|
|
223 |
# Ensure EdifactLSL is empty to maintain backwards compatibility |
| 224 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); |
| 225 |
|
| 220 |
$order->basket->create_items('ordering')->store; |
226 |
$order->basket->create_items('ordering')->store; |
| 221 |
is( |
227 |
is( |
| 222 |
$edi_order->order_line( 1, $orders[0] ), |
228 |
$edi_order->order_line( 1, $orders[0] ), |
|
Lines 280-282
subtest 'filename() tests' => sub {
Link Here
|
| 280 |
|
286 |
|
| 281 |
$schema->storage->txn_rollback; |
287 |
$schema->storage->txn_rollback; |
| 282 |
}; |
288 |
}; |
| 283 |
- |
289 |
|
|
|
290 |
subtest 'gir_segments() with LSL and LSQ preferences' => sub { |
| 291 |
plan tests => 20; |
| 292 |
|
| 293 |
$schema->storage->txn_begin; |
| 294 |
|
| 295 |
# Test LSL and LSQ preferences |
| 296 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
| 297 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'ccode' ); |
| 298 |
|
| 299 |
# Create test items with both location and ccode |
| 300 |
my @test_items = ( |
| 301 |
{ |
| 302 |
branchcode => 'BRANCH1', |
| 303 |
itype => 'BOOK', |
| 304 |
itemcallnumber => 'CALL1', |
| 305 |
location => 'FICTION', # Will be used for LSQ |
| 306 |
ccode => 'ADULT', # Will be used for LSL |
| 307 |
}, |
| 308 |
{ |
| 309 |
branchcode => 'BRANCH2', |
| 310 |
itype => 'DVD', |
| 311 |
itemcallnumber => 'CALL2', |
| 312 |
location => 'MEDIA', # Will be used for LSQ |
| 313 |
ccode => 'CHILD', # Will be used for LSL |
| 314 |
} |
| 315 |
); |
| 316 |
|
| 317 |
my $params = { |
| 318 |
ol_fields => { budget_code => 'FUND123' }, |
| 319 |
items => \@test_items |
| 320 |
}; |
| 321 |
|
| 322 |
my @segments = Koha::Edifact::Order::gir_segments($params); |
| 323 |
|
| 324 |
ok( scalar @segments >= 2, 'At least two segments created for two items' ); |
| 325 |
|
| 326 |
# Check first item's GIR segment (segments are strings in EDI format) |
| 327 |
my $first_gir = $segments[0]; |
| 328 |
ok( $first_gir, 'First segment exists' ); |
| 329 |
|
| 330 |
# Check that the segment contains expected data |
| 331 |
like( $first_gir, qr/GIR/, 'Segment contains GIR tag' ); |
| 332 |
like( $first_gir, qr/FUND123:LFN/, 'Budget code included in first segment' ); |
| 333 |
like( $first_gir, qr/BRANCH1:LLO/, 'Branch code included in first segment' ); |
| 334 |
like( $first_gir, qr/BOOK:LST/, 'Item type included in first segment' ); |
| 335 |
like( $first_gir, qr/FICTION:LSQ/, 'LSQ field contains location value' ); |
| 336 |
like( $first_gir, qr/ADULT:LSL/, 'LSL field contains collection code value' ); |
| 337 |
|
| 338 |
# Test reversed preferences |
| 339 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'ccode' ); # LSQ -> collection |
| 340 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'location' ); # LSL -> location |
| 341 |
|
| 342 |
my @test_items_rev = ( |
| 343 |
{ |
| 344 |
branchcode => 'BRANCH3', |
| 345 |
itype => 'BOOK', |
| 346 |
itemcallnumber => 'CALL3', |
| 347 |
location => 'REFERENCE', # Will be used for LSL |
| 348 |
ccode => 'RARE', # Will be used for LSQ |
| 349 |
} |
| 350 |
); |
| 351 |
|
| 352 |
my $params_rev = { |
| 353 |
ol_fields => { budget_code => 'FUND456' }, |
| 354 |
items => \@test_items_rev |
| 355 |
}; |
| 356 |
|
| 357 |
@segments = Koha::Edifact::Order::gir_segments($params_rev); |
| 358 |
my $gir_rev = $segments[0]; |
| 359 |
|
| 360 |
# Check that the segment contains expected reversed mappings |
| 361 |
like( $gir_rev, qr/RARE:LSQ/, 'LSQ field contains collection code when preference is ccode' ); |
| 362 |
like( $gir_rev, qr/REFERENCE:LSL/, 'LSL field contains location when preference is location' ); |
| 363 |
|
| 364 |
# Test with one preference empty |
| 365 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
| 366 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); # Empty = ignore |
| 367 |
|
| 368 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 369 |
my $gir_partial = $segments[0]; |
| 370 |
|
| 371 |
like( $gir_partial, qr/FICTION:LSQ/, 'LSQ field included when preference is set' ); |
| 372 |
unlike( $gir_partial, qr/:LSL/, 'LSL field not included when preference is empty' ); |
| 373 |
|
| 374 |
# Test with both preferences empty |
| 375 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', '' ); |
| 376 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); |
| 377 |
|
| 378 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 379 |
my $gir_empty = $segments[0]; |
| 380 |
|
| 381 |
unlike( $gir_empty, qr/:LSQ/, 'LSQ field not included when preference is empty' ); |
| 382 |
unlike( $gir_empty, qr/:LSL/, 'LSL field not included when preference is empty' ); |
| 383 |
|
| 384 |
# Test with LSQ empty but LSL set |
| 385 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', '' ); # Empty = ignore |
| 386 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'ccode' ); # LSL -> collection |
| 387 |
|
| 388 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 389 |
my $gir_lsl_only = $segments[0]; |
| 390 |
|
| 391 |
unlike( $gir_lsl_only, qr/:LSQ/, 'LSQ field not included when preference is empty' ); |
| 392 |
like( $gir_lsl_only, qr/ADULT:LSL/, 'LSL field included when preference is set' ); |
| 393 |
|
| 394 |
# Test with both preferences set to same field (location) |
| 395 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); # LSQ -> location |
| 396 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'location' ); # LSL -> location |
| 397 |
|
| 398 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 399 |
my $gir_both_location = $segments[0]; |
| 400 |
|
| 401 |
like( $gir_both_location, qr/FICTION:LSQ/, 'LSQ field contains location value when both map to location' ); |
| 402 |
like( $gir_both_location, qr/FICTION:LSL/, 'LSL field contains location value when both map to location' ); |
| 403 |
|
| 404 |
# Test with both preferences set to same field (ccode) |
| 405 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'ccode' ); # LSQ -> collection |
| 406 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'ccode' ); # LSL -> collection |
| 407 |
|
| 408 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 409 |
my $gir_both_ccode = $segments[0]; |
| 410 |
|
| 411 |
like( $gir_both_ccode, qr/ADULT:LSQ/, 'LSQ field contains collection code value when both map to ccode' ); |
| 412 |
like( $gir_both_ccode, qr/ADULT:LSL/, 'LSL field contains collection code value when both map to ccode' ); |
| 413 |
|
| 414 |
$schema->storage->txn_rollback; |
| 415 |
}; |