|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use RT::IR::Test tests => undef; |
| 5 | + |
| 6 | +my $dbtype = RT->Config->Get('DatabaseType'); |
| 7 | +if ( $dbtype eq 'SQLite' ) { |
| 8 | + diag "Indexed FTS is not supported on SQLite, skipping FTS-dependent assertions"; |
| 9 | + done_testing; |
| 10 | + exit 0; |
| 11 | +} |
| 12 | + |
| 13 | +# Configure FTS for the active database type, mirroring RT's per-DB FTS |
| 14 | +# test setup (t/fts/indexed_mysql.t, indexed_pg.t, indexed_oracle.t). |
| 15 | +my %fts_config = ( Enable => 1, Indexed => 1 ); |
| 16 | +if ( $dbtype eq 'Pg' ) { |
| 17 | + $fts_config{Column} = 'ContentIndex'; |
| 18 | + $fts_config{Table} = 'AttachmentsIndex'; |
| 19 | +} |
| 20 | +elsif ( $dbtype eq 'Oracle' ) { |
| 21 | + $fts_config{IndexName} = 'rt_fts_index'; |
| 22 | +} |
| 23 | +else { |
| 24 | + # mysql/mariadb |
| 25 | + $fts_config{Table} = 'AttachmentsIndex'; |
| 26 | +} |
| 27 | +RT->Config->Set( FullTextSearch => %fts_config ); |
| 28 | + |
| 29 | +use RT::Test::FTS; |
| 30 | +RT::Test::FTS->setup_indexing(); |
| 31 | + |
| 32 | +RT::Test->started_ok; |
| 33 | +my $agent = default_agent(); |
| 34 | + |
| 35 | +my $email = 'lookup-test@example.com'; |
| 36 | + |
| 37 | +my $ir = $agent->create_ir( |
| 38 | + { Subject => 'Email lookup FTS test', Content => "Investigation involving $email" }, |
| 39 | +); |
| 40 | + |
| 41 | +RT::Test::FTS->sync_index(); |
| 42 | + |
| 43 | +diag "Test Lookup page with an email address (containing '\@') and FTS enabled"; |
| 44 | +{ |
| 45 | + $agent->get_ok( |
| 46 | + "/RTIR/Tools/Lookup.html?ticket=$ir&type=email&q=$email", |
| 47 | + "Loaded Lookup page for $email", |
| 48 | + ); |
| 49 | + $agent->content_contains( $email, 'Lookup page rendered for the email' ); |
| 50 | + $agent->content_like( |
| 51 | + qr{Incident Reports: \Q$email\E.*?Email lookup FTS test}s, |
| 52 | + 'Found the test ticket in search results on lookup', |
| 53 | + ); |
| 54 | + |
| 55 | + $agent->content_lacks( |
| 56 | + '(no Incident Reports)', |
| 57 | + 'IR appears in the Incident Reports lookup results', |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | +my $host = 'bad-host.example.com'; |
| 62 | + |
| 63 | +my $host_ir = $agent->create_ir( |
| 64 | + { Subject => 'Host lookup FTS test', Content => "Investigation involving $host" }, |
| 65 | +); |
| 66 | + |
| 67 | +RT::Test::FTS->sync_index(); |
| 68 | + |
| 69 | +diag "Test Lookup page with a hostname (containing '-') and FTS enabled"; |
| 70 | +{ |
| 71 | + $agent->get_ok( |
| 72 | + "/RTIR/Tools/Lookup.html?ticket=$host_ir&type=host&q=$host", |
| 73 | + "Loaded Lookup page for $host", |
| 74 | + ); |
| 75 | + $agent->content_contains( $host, 'Lookup page rendered for the host' ); |
| 76 | + $agent->content_like( |
| 77 | + qr{Incident Reports: \Q$host\E.*?Host lookup FTS test}s, |
| 78 | + 'Found the test ticket in search results on lookup', |
| 79 | + ); |
| 80 | + |
| 81 | + $agent->content_lacks( |
| 82 | + '(no Incident Reports)', |
| 83 | + 'IR appears in the Incident Reports lookup results', |
| 84 | + ); |
| 85 | +} |
| 86 | + |
| 87 | +diag "Test Lookup page with values that do not appear in any ticket"; |
| 88 | +{ |
| 89 | + my $missing_email = 'nomatch-test@example.org'; |
| 90 | + $agent->get_ok( |
| 91 | + "/RTIR/Tools/Lookup.html?ticket=$ir&type=email&q=$missing_email", |
| 92 | + "Loaded Lookup page for $missing_email", |
| 93 | + ); |
| 94 | + $agent->content_contains( |
| 95 | + '(no Incident Reports)', |
| 96 | + 'No IR is reported for an email that is not indexed', |
| 97 | + ); |
| 98 | + |
| 99 | + my $missing_host = 'nonexistent-host.example.org'; |
| 100 | + $agent->get_ok( |
| 101 | + "/RTIR/Tools/Lookup.html?ticket=$host_ir&type=host&q=$missing_host", |
| 102 | + "Loaded Lookup page for $missing_host", |
| 103 | + ); |
| 104 | + $agent->content_contains( |
| 105 | + '(no Incident Reports)', |
| 106 | + 'No IR is reported for a host that is not indexed', |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +done_testing; |
0 commit comments