|
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 280-282
subtest 'filename() tests' => sub {
Link Here
|
| 280 |
|
280 |
|
| 281 |
$schema->storage->txn_rollback; |
281 |
$schema->storage->txn_rollback; |
| 282 |
}; |
282 |
}; |
| 283 |
- |
283 |
|
|
|
284 |
subtest 'gir_segments() with LSL and LSQ preferences' => sub { |
| 285 |
plan tests => 14; |
| 286 |
|
| 287 |
$schema->storage->txn_begin; |
| 288 |
|
| 289 |
# Test LSL and LSQ preferences |
| 290 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
| 291 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'ccode' ); |
| 292 |
|
| 293 |
# Create test items with both location and ccode |
| 294 |
my @test_items = ( |
| 295 |
{ |
| 296 |
branchcode => 'BRANCH1', |
| 297 |
itype => 'BOOK', |
| 298 |
itemcallnumber => 'CALL1', |
| 299 |
location => 'FICTION', # Will be used for LSQ |
| 300 |
ccode => 'ADULT', # Will be used for LSL |
| 301 |
}, |
| 302 |
{ |
| 303 |
branchcode => 'BRANCH2', |
| 304 |
itype => 'DVD', |
| 305 |
itemcallnumber => 'CALL2', |
| 306 |
location => 'MEDIA', # Will be used for LSQ |
| 307 |
ccode => 'CHILD', # Will be used for LSL |
| 308 |
} |
| 309 |
); |
| 310 |
|
| 311 |
my $params = { |
| 312 |
ol_fields => { budget_code => 'FUND123' }, |
| 313 |
items => \@test_items |
| 314 |
}; |
| 315 |
|
| 316 |
my @segments = Koha::Edifact::Order::gir_segments($params); |
| 317 |
|
| 318 |
ok( scalar @segments >= 2, 'At least two segments created for two items' ); |
| 319 |
|
| 320 |
# Check first item's GIR segment (segments are strings in EDI format) |
| 321 |
my $first_gir = $segments[0]; |
| 322 |
ok( $first_gir, 'First segment exists' ); |
| 323 |
|
| 324 |
# Check that the segment contains expected data |
| 325 |
like( $first_gir, qr/GIR/, 'Segment contains GIR tag' ); |
| 326 |
like( $first_gir, qr/FUND123:LFN/, 'Budget code included in first segment' ); |
| 327 |
like( $first_gir, qr/BRANCH1:LLO/, 'Branch code included in first segment' ); |
| 328 |
like( $first_gir, qr/BOOK:LST/, 'Item type included in first segment' ); |
| 329 |
like( $first_gir, qr/FICTION:LSQ/, 'LSQ field contains location value' ); |
| 330 |
like( $first_gir, qr/ADULT:LSL/, 'LSL field contains collection code value' ); |
| 331 |
|
| 332 |
# Test reversed preferences |
| 333 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'ccode' ); # LSQ -> collection |
| 334 |
t::lib::Mocks::mock_preference( 'EdifactLSL', 'location' ); # LSL -> location |
| 335 |
|
| 336 |
my @test_items_rev = ( |
| 337 |
{ |
| 338 |
branchcode => 'BRANCH3', |
| 339 |
itype => 'BOOK', |
| 340 |
itemcallnumber => 'CALL3', |
| 341 |
location => 'REFERENCE', # Will be used for LSL |
| 342 |
ccode => 'RARE', # Will be used for LSQ |
| 343 |
} |
| 344 |
); |
| 345 |
|
| 346 |
my $params_rev = { |
| 347 |
ol_fields => { budget_code => 'FUND456' }, |
| 348 |
items => \@test_items_rev |
| 349 |
}; |
| 350 |
|
| 351 |
@segments = Koha::Edifact::Order::gir_segments($params_rev); |
| 352 |
my $gir_rev = $segments[0]; |
| 353 |
|
| 354 |
# Check that the segment contains expected reversed mappings |
| 355 |
like( $gir_rev, qr/RARE:LSQ/, 'LSQ field contains collection code when preference is ccode' ); |
| 356 |
like( $gir_rev, qr/REFERENCE:LSL/, 'LSL field contains location when preference is location' ); |
| 357 |
|
| 358 |
# Test with one preference empty |
| 359 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', 'location' ); |
| 360 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); # Empty = ignore |
| 361 |
|
| 362 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 363 |
my $gir_partial = $segments[0]; |
| 364 |
|
| 365 |
like( $gir_partial, qr/FICTION:LSQ/, 'LSQ field included when preference is set' ); |
| 366 |
unlike( $gir_partial, qr/:LSL/, 'LSL field not included when preference is empty' ); |
| 367 |
|
| 368 |
# Test with both preferences empty |
| 369 |
t::lib::Mocks::mock_preference( 'EdifactLSQ', '' ); |
| 370 |
t::lib::Mocks::mock_preference( 'EdifactLSL', '' ); |
| 371 |
|
| 372 |
@segments = Koha::Edifact::Order::gir_segments($params); |
| 373 |
my $gir_empty = $segments[0]; |
| 374 |
|
| 375 |
unlike( $gir_empty, qr/:LSQ/, 'LSQ field not included when preference is empty' ); |
| 376 |
unlike( $gir_empty, qr/:LSL/, 'LSL field not included when preference is empty' ); |
| 377 |
|
| 378 |
$schema->storage->txn_rollback; |
| 379 |
}; |