Skip to content

Commit

Permalink
Merge branch '4.4/simple-search-redirect-results' into 4.4-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Aug 4, 2023
2 parents ac1ebf0 + dab3355 commit 6206f13
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
8 changes: 4 additions & 4 deletions share/html/Search/Simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@

$m->callback( %ARGS, CallbackName => 'SearchArgs', args => \%args);

my $search = RT::Search::Simple->new(%args);

$m->comp( "Results.html", Query => $search->QueryToSQL() );
$m->comp( "/Elements/Footer" );
my $search = RT::Search::Simple->new(%args);
my $query = $m->comp('/Elements/QueryString', %ARGS, Query => $search->QueryToSQL() );
my $result_path = RT->Config->Get('WebURL') . "Search/Results.html?$query";
RT::Interface::Web::Redirect( $result_path );
$m->abort();
}
</%INIT>
Expand Down
62 changes: 27 additions & 35 deletions t/web/simple_search.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ my $two_words_queue = RT::Test->load_or_create_queue(
);
ok $two_words_queue && $two_words_queue->id, 'loaded or created a queue';

my $root = RT::Test->load_or_create_user( Name => 'root' );

{
my $tickets = RT::Tickets->new( RT->SystemUser );
Expand Down Expand Up @@ -68,38 +69,29 @@ ok $two_words_queue && $two_words_queue->id, 'loaded or created a queue';
is $parser->QueryToSQL(q{cf."don't foo?":'bar n\\' baz'}), qq/( 'CF.{don\\'t foo?}' LIKE 'bar n\\' baz' ) AND ( Status = '__Active__' )/, "correct parsing of CFs with quotes";
}

my $ticket_found_1 = RT::Ticket->new($RT::SystemUser);
my $ticket_found_2 = RT::Ticket->new($RT::SystemUser);
my $ticket_not_found = RT::Ticket->new($RT::SystemUser);

$ticket_found_1->Create(
my $ticket_found_1 = RT::Test->create_ticket(
Subject => 'base ticket 1'.$$,
Queue => 'general',
Owner => 'root',
Owner => $root->Id,
Requestor => 'customsearch@localhost',
Content => 'this is base ticket 1',
);
ok( $ticket_found_1->id, 'created ticket for custom search');


$ticket_found_2->Create(
my $ticket_found_2 = RT::Test->create_ticket(
Subject => 'base ticket 2'.$$,
Queue => 'general',
Owner => 'root',
Owner => $root->Id,
Requestor => 'customsearch@localhost',
Content => 'this is base ticket 2',
);
ok( $ticket_found_2->id, 'created ticket for custom search');

$ticket_not_found = RT::Ticket->new($RT::SystemUser);
$ticket_not_found->Create(
my $ticket_not_found = RT::Test->create_ticket(
Subject => 'not found subject' . $$,
Queue => 'other',
Owner => 'nobody',
Owner => RT->Nobody->Id,
Requestor => 'notfound@localhost',
Content => 'this is not found content',
);
ok( $ticket_not_found->id, 'created ticket for custom search');

ok($m->login, 'logged in');

Expand All @@ -114,9 +106,10 @@ for my $q (@queries) {
$m->form_with_fields('q');
$m->field( q => $q );
$m->submit;
$m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->content_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->content_lacks( 'not found subject', 'not found ticket is not found' );
$m->text_contains( 'Found 2 tickets' );
$m->text_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->text_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->text_lacks( 'not found subject', 'not found ticket is not found' );
}

$ticket_not_found->SetStatus('open');
Expand All @@ -126,19 +119,21 @@ for my $q (@queries) {
$m->form_with_fields('q');
$m->field( q => $q );
$m->submit;
$m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->content_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->content_lacks( 'not found subject', 'not found ticket is not found' );
$m->text_contains( 'Found 2 tickets' );
$m->text_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->text_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->text_lacks( 'not found subject', 'not found ticket is not found' );
}

@queries = ( 'fulltext:"base ticket 1"', "'base ticket 1'" );
for my $q (@queries) {
$m->form_with_fields('q');
$m->field( q => $q );
$m->submit;
$m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->content_lacks( 'base ticket 2', 'base ticket 2 is not found' );
$m->content_lacks( 'not found subject', 'not found ticket is not found' );
$m->text_contains( 'Found 1 ticket' );
$m->text_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->text_lacks( 'base ticket 2', 'base ticket 2 is not found' );
$m->text_lacks( 'not found subject', 'not found ticket is not found' );
}

# now let's test with ' or "
Expand All @@ -158,17 +153,15 @@ for my $quote ( q{'}, q{"} ) {



my $ticket_quote = RT::Ticket->new($RT::SystemUser);
$ticket_quote->Create(
RT::Test->create_ticket(
Subject => qq!base${quote}ticket $$!,
Queue => 'general',
Owner => $user->Name,
Owner => $user->Id,
( $quote eq q{'}
? (Requestor => qq!custom${quote}search\@localhost!)
: () ),
Content => qq!this is base${quote}ticket with quote inside!,
);
ok( $ticket_quote->id, 'created ticket with quote for custom search' );

@queries = (
qq!fulltext:base${quote}ticket!,
Expand All @@ -188,10 +181,8 @@ for my $quote ( q{'}, q{"} ) {
$m->form_with_fields('q');
$m->field( q => $q );
$m->submit;
my $escape_quote = $quote;
RT::Interface::Web::EscapeHTML(\$escape_quote);
$m->content_contains( "base${escape_quote}ticket",
"base${quote}ticket is found" );
$m->text_contains( 'Found 1 ticket' );
$m->text_contains( "base${quote}ticket", "base${quote}ticket is found" );
}
}

Expand All @@ -213,9 +204,10 @@ for my $quote ( q{'}, q{"} ) {
$m->form_with_fields('q');
$m->field( q => $q );
$m->submit;
$m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->content_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->content_lacks( 'not found subject', 'not found ticket is not found' );
$m->text_contains( 'Found 2 tickets' );
$m->text_contains( 'base ticket 1', 'base ticket 1 is found' );
$m->text_contains( 'base ticket 2', 'base ticket 2 is found' );
$m->text_lacks( 'not found subject', 'not found ticket is not found' );
}
}

Expand Down

0 comments on commit 6206f13

Please sign in to comment.