[Rt-commit] r12835 - in rt/branches/3.8-TESTING: . t/ticket

elacour at bestpractical.com elacour at bestpractical.com
Tue Jun 3 12:11:26 EDT 2008


Author: elacour
Date: Tue Jun  3 12:11:26 2008
New Revision: 12835

Added:
   rt/branches/3.8-TESTING/t/ticket/search_long_cf_values.t
Modified:
   rt/branches/3.8-TESTING/   (props changed)
   rt/branches/3.8-TESTING/lib/RT/Tickets_Overlay.pm

Log:
 r9111 at datura:  manu | 2008-06-03 18:05:53 +0200
 * Commit back LargeContent search for customfields
 * Fix SQL for MySQL (missing quotes) so it doesn't break anymore t/ticket/search.t
 * Add tests for this


Modified: rt/branches/3.8-TESTING/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Tickets_Overlay.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Tickets_Overlay.pm	Tue Jun  3 12:11:26 2008
@@ -1291,6 +1291,8 @@
 
     $self->_OpenParen;
 
+    $self->_OpenParen;
+
     $self->_SQLLimit(
         ALIAS      => $TicketCFs,
         FIELD      => $column || 'Content',
@@ -1299,6 +1301,30 @@
         %rest
     );
 
+    $self->_OpenParen;
+
+    $self->_SQLLimit(
+        ALIAS      => $TicketCFs,
+        FIELD      => $column || 'Content',
+        OPERATOR   => '=',
+        VALUE      => '',
+        QUOTEVALUE => 1,
+        ENTRYAGGREGATOR => 'OR'
+    );
+
+    $self->_SQLLimit(
+        ALIAS => $TicketCFs,
+        FIELD => 'LargeContent',
+        OPERATOR => $op,
+        VALUE => $value,
+        QUOTEVALUE => 1,
+        ENTRYAGGREGATOR => 'AND',
+    );
+
+    $self->_CloseParen;
+
+    $self->_CloseParen;
+
     # XXX: if we join via CustomFields table then
     # because of order of left joins we get NULLs in
     # CF table and then get nulls for those records

Added: rt/branches/3.8-TESTING/t/ticket/search_long_cf_values.t
==============================================================================
--- (empty file)
+++ rt/branches/3.8-TESTING/t/ticket/search_long_cf_values.t	Tue Jun  3 12:11:26 2008
@@ -0,0 +1,80 @@
+#!/opt/perl/bin/perl -w
+
+# tests relating to searching. Especially around custom fields with long values
+# (> 255 chars)
+
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+use RT::Test;
+
+# setup the queue
+
+my $q = RT::Queue->new($RT::SystemUser);
+my $queue = 'SearchTests-'.$$;
+$q->Create(Name => $queue);
+ok ($q->id, "Created the queue");
+
+
+# setup the CF
+my $cf = RT::CustomField->new($RT::SystemUser);
+$cf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $q->id);
+ok($cf->id, "Created the SearchTest CF");
+my $cflabel = "CustomField-".$cf->id;
+
+# setup some tickets
+my $t1 = RT::Ticket->new($RT::SystemUser);
+my ( $id, undef $msg ) = $t1->Create(
+    Queue      => $q->id,
+    Subject    => 'SearchTest1',
+    Requestor  => ['search at example.com'],
+    $cflabel   => 'foo',
+);
+ok( $id, $msg );
+
+
+my $t2 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t2->Create(
+    Queue      => $q->id,
+    Subject    => 'SearchTest2',
+    Requestor  => ['searchlong at example.com'],
+    $cflabel   => 'bar' x 150,
+);
+ok( $id, $msg );
+
+my $t3 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t3->Create(
+    Queue      => $q->id,
+    Subject    => 'SearchTest3',
+    Requestor  => ['searchlong at example.com'],
+    $cflabel   => 'bar',
+);
+ok( $id, $msg );
+
+# we have tickets. start searching
+my $tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
+is($tix->Count, 1, "matched short string foo")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'bar'");
+is($tix->Count, 2, "matched long+short string bar")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND ( CF.SearchTest LIKE 'foo' OR CF.SearchTest LIKE 'bar' )");
+is($tix->Count, 3, "matched short string foo or long+short string bar")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest NOT LIKE 'foo' AND CF.SearchTest LIKE 'bar'");
+is($tix->Count, 2, "not matched short string foo and matched long+short string bar")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo' AND CF.SearchTest NOT LIKE 'bar'");
+is($tix->Count, 1, "matched short string foo and not matched long+short string bar")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+


More information about the Rt-commit mailing list