|
Lines 449-461
subtest 'build_query tests' => sub {
Link Here
|
| 449 |
"query of boolean type field is not truncated even if QueryAutoTruncate is set" |
449 |
"query of boolean type field is not truncated even if QueryAutoTruncate is set" |
| 450 |
); |
450 |
); |
| 451 |
|
451 |
|
| 452 |
( undef, $query ) = |
452 |
subtest 'removal of punctuation surrounded by spaces when autotruncate enabled' => sub { |
| 453 |
$qb->build_query_compat( undef, ['First title ; Second title : some & subtitle / Authors Name'] ); |
453 |
plan tests => 7; |
| 454 |
is( |
454 |
t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); |
| 455 |
$query->{query}{query_string}{query}, |
455 |
t::lib::Mocks::mock_preference( 'QueryRegexEscapeOptions', 'escape' ); |
| 456 |
'(First* title* Second* title* some* subtitle* Authors* Name*)', |
456 |
( undef, $query ) = $qb->build_query_compat( |
| 457 |
"ISBD punctualtion and problematic characters properly removed" |
457 |
undef, |
| 458 |
); |
458 |
['First title ; subtitle : some & subtitle / Authors Name. Second title ; Third title / Second Author'] |
|
|
459 |
); |
| 460 |
is( |
| 461 |
$query->{query}{query_string}{query}, |
| 462 |
'(First* title* subtitle* some* subtitle* Authors* Name. Second* title* Third* title* Second* Author*)', |
| 463 |
"ISBD punctuation and problematic characters surrounded by spaces properly removed" |
| 464 |
); |
| 465 |
|
| 466 |
t::lib::Mocks::mock_preference( 'QueryRegexEscapeOptions', 'dont_escape' ); |
| 467 |
( undef, $query ) = $qb->build_query_compat( |
| 468 |
undef, |
| 469 |
['First title ; subtitle : some & subtitle / Authors Name. Second title ; Third title / Second Author'] |
| 470 |
); |
| 471 |
is( |
| 472 |
$query->{query}{query_string}{query}, |
| 473 |
'(First* title* subtitle* some* subtitle* / Authors* Name. Second* title* ; Third* title* / Second* Author*)', |
| 474 |
"ISBD punctuation and problematic characters surrounded by spaces properly removed, RE saved" |
| 475 |
); |
| 476 |
( undef, $query ) = |
| 477 |
$qb->build_query_compat( undef, ['Lorem / ipsum dolor / sit ; / amet'] ); |
| 478 |
is( |
| 479 |
$query->{query}{query_string}{query}, |
| 480 |
'(Lorem* / ipsum* dolor* / sit* amet*)', |
| 481 |
"RE saved, last odd unescaped slash preceded by a semicolon removed" |
| 482 |
); |
| 483 |
|
| 484 |
t::lib::Mocks::mock_preference( 'QueryRegexEscapeOptions', 'escape' ); |
| 485 |
( undef, $query ) = |
| 486 |
$qb->build_query_compat( undef, ['Lorem \/ ipsum dolor \/ sit ; \/ amet'] ); |
| 487 |
is( |
| 488 |
$query->{query}{query_string}{query}, |
| 489 |
'(Lorem* ipsum* dolor* sit* amet*)', |
| 490 |
"Escaped slashes (also preceded by another punctuation followed by a space) removed" |
| 491 |
); |
| 492 |
( undef, $query ) = |
| 493 |
$qb->build_query_compat( undef, ['comma , period . equal = hyphen - slash / escaped_slash \/'] ); |
| 494 |
is( |
| 495 |
$query->{query}{query_string}{query}, |
| 496 |
'(comma* period* equal* hyphen* slash* escaped_slash* \/)', |
| 497 |
"Other problematic characters surrounded by spaces properly removed" |
| 498 |
); |
| 499 |
|
| 500 |
( undef, $query ) = |
| 501 |
$qb->build_query_compat( undef, [' &;,:=-/ // \/\/ /&&&==&& ::-:: '] ); |
| 502 |
is( |
| 503 |
$query->{query}{query_string}{query}, |
| 504 |
'()', |
| 505 |
"Repeated problematic characters surrounded by spaces removed" |
| 506 |
); |
| 507 |
|
| 508 |
( undef, $query ) = $qb->build_query_compat( |
| 509 |
undef, |
| 510 |
[ |
| 511 |
'& amp& semicolon; ;colonsemi full: :full comma, ,comma dot. .dot =equal equal= hyphen- -hypen slash\/ \/slash' |
| 512 |
] |
| 513 |
); |
| 514 |
is( |
| 515 |
$query->{query}{query_string}{query}, |
| 516 |
'(&* amp& semicolon; ;colonsemi* full* full* comma, ,comma* dot. .dot* equal* equal* hyphen- -hypen* slash\/ \/slash*)', |
| 517 |
"ISBD punctuation and problematic characters not removed when not surrounded by spaces." |
| 518 |
); |
| 519 |
|
| 520 |
# Note above: semicolons and equals removed asthose are search field indicators - terms ending in punctuation |
| 521 |
# are not truncated. |
| 522 |
# Note that (colons/equal signs)/spaces glued to words are not removed by the feature under test but before. |
| 523 |
}; |
| 459 |
|
524 |
|
| 460 |
( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] ); |
525 |
( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] ); |
| 461 |
is( |
526 |
is( |
| 462 |
- |
|
|