[Rt-commit] r2726 - in rt/branches/PLATANO-EXPERIMENTAL-CSS: .
lib/RT lib/t/regression
jesse at bestpractical.com
jesse at bestpractical.com
Sat Apr 16 04:19:45 EDT 2005
Author: jesse
Date: Sat Apr 16 04:19:45 2005
New Revision: 2726
Modified:
rt/branches/PLATANO-EXPERIMENTAL-CSS/ (props changed)
rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Tickets_Overlay.pm
rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/t/regression/12-search.t
Log:
r13115 at hualien: jesse | 2005-04-16 03:12:43 -0400
r13014 at hualien: jesse | 2005-04-16 02:27:35 -0400
r12788 at hualien: jesse | 2005-04-13 14:25:49 -0400
Pulling forward from 3.4
Modified: rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Tickets_Overlay.pm (original)
+++ rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Tickets_Overlay.pm Sat Apr 16 04:19:45 2005
@@ -1099,7 +1099,7 @@
my $null_columns_ok;
if ( ( $op =~ /^IS$/i ) or ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
$null_columns_ok = 1;
- }
+ }
my $cfid = 0;
if ($queue) {
@@ -1118,6 +1118,8 @@
$cfid = $cf->id;
+ } else { # if we have no id, we're going to search on name.
+ $cfid = $field;
}
my $TicketCFs;
@@ -1148,7 +1150,7 @@
VALUE => '0',
ENTRYAGGREGATOR => 'AND');
- if ($cfid) {
+ if ($cfid =~ /^\d+$/) { # we have a numerical cfid. we know which cf we want
$self->SUPER::Limit(
LEFTJOIN => $TicketCFs,
FIELD => 'CustomField',
@@ -1156,9 +1158,10 @@
ENTRYAGGREGATOR => 'AND'
);
}
- else {
+ else { # we're going to need to search on cf name
my $cfalias = $self->Join(
ALIAS1 => $TicketCFs,
+ TYPE => 'left',
FIELD1 => 'CustomField',
TABLE2 => 'CustomFields',
FIELD2 => 'id'
@@ -1182,7 +1185,7 @@
QUOTEVALUE => 1,
@rest
);
- if ($null_columns_ok) {
+ if ($null_columns_ok && ($op ne 'IS' && $value ne 'NULL')) {
$self->_SQLLimit(
ALIAS => $TicketCFs,
FIELD => 'Content',
Modified: rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/t/regression/12-search.t
==============================================================================
--- rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/t/regression/12-search.t (original)
+++ rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/t/regression/12-search.t Sat Apr 16 04:19:45 2005
@@ -1,4 +1,7 @@
-#!/usr/bin/perl -w
+#!/opt/perl/bin/perl -w
+
+# tests relating to searching. Especially around custom fields, and
+# corner cases.
use strict;
use warnings;
@@ -8,66 +11,223 @@
RT::LoadConfig();
RT::Init();
+# setup the queue
+
my $q = RT::Queue->new($RT::SystemUser);
-my $queue = 'SearchTests-'.rand(200);
+my $queue = 'SearchTests-'.$$;
$q->Create(Name => $queue);
ok ($q->id, "Created the queue");
+
+# and setup the CFs
+# we believe the Type shouldn't matter.
+
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;
-ok($cf->id, "Created the custom field");
+my $cf2 = RT::CustomField->new($RT::SystemUser);
+$cf2->Create(Name => 'SearchTest2', Type => 'Freeform', MaxValues => 0, Queue => $q->id);
+ok($cf2->id, "Created the SearchTest2 CF");
+my $cflabel2 = "CustomField-".$cf2->id;
+
+my $cf3 = RT::CustomField->new($RT::SystemUser);
+$cf3->Create(Name => 'SearchTest3', Type => 'Freeform', MaxValues => 0, Queue => $q->id);
+ok($cf3->id, "Created the SearchTest3 CF");
+my $cflabel3 = "CustomField-".$cf3->id;
+
+
+# setup some tickets
+# we'll need a small pile of them, to test various combinations and nulls.
+# there's probably a way to think harder and do this with fewer
-my $cflabel = "CustomField-".$cf->id;
my $t1 = RT::Ticket->new($RT::SystemUser);
my ( $id, undef $msg ) = $t1->Create(
Queue => $q->id,
Subject => 'SearchTest1',
- Requestor => ['search2 at example.com'],
- $cflabel => 'one'
+ Requestor => ['search1 at example.com'],
+ $cflabel => 'foo1',
+ $cflabel2 => 'bar1',
+ $cflabel3 => 'qux1',
);
ok( $id, $msg );
+
my $t2 = RT::Ticket->new($RT::SystemUser);
( $id, undef, $msg ) = $t2->Create(
Queue => $q->id,
Subject => 'SearchTest2',
- Requestor => ['search1 at example.com'],
- $cflabel => 'two'
+ Requestor => ['search2 at example.com'],
+# $cflabel => 'foo2',
+ $cflabel2 => 'bar2',
+ $cflabel3 => 'qux2',
+);
+ok( $id, $msg );
+
+my $t3 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t3->Create(
+ Queue => $q->id,
+ Subject => 'SearchTest3',
+ Requestor => ['search3 at example.com'],
+ $cflabel => 'foo3',
+# $cflabel2 => 'bar3',
+ $cflabel3 => 'qux3',
+);
+ok( $id, $msg );
+
+my $t4 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t4->Create(
+ Queue => $q->id,
+ Subject => 'SearchTest4',
+ Requestor => ['search4 at example.com'],
+ $cflabel => 'foo4',
+ $cflabel2 => 'bar4',
+# $cflabel3 => 'qux4',
+);
+ok( $id, $msg );
+
+my $t5 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t5->Create(
+ Queue => $q->id,
+# Subject => 'SearchTest5',
+ Requestor => ['search5 at example.com'],
+ $cflabel => 'foo5',
+ $cflabel2 => 'bar5',
+ $cflabel3 => 'qux5',
+);
+ok( $id, $msg );
+
+my $t6 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t6->Create(
+ Queue => $q->id,
+ Subject => 'SearchTest6',
+# Requestor => ['search6 at example.com'],
+ $cflabel => 'foo6',
+ $cflabel2 => 'bar6',
+ $cflabel3 => 'qux6',
+);
+ok( $id, $msg );
+
+my $t7 = RT::Ticket->new($RT::SystemUser);
+( $id, undef, $msg ) = $t7->Create(
+ Queue => $q->id,
+ Subject => 'SearchTest7',
+ Requestor => ['search7 at example.com'],
+# $cflabel => 'foo7',
+# $cflabel2 => 'bar7',
+ $cflabel3 => 'qux7',
);
ok( $id, $msg );
+# we have tickets. start searching
my $tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue'");
+is($tix->Count, 7, "found all the tickets");
+
-is($tix->Count, 2, "found two tickets");
+# very simple searches. both CF and normal
$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'one'");
-is($tix->Count, 1, "found one ticket");
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo1'");
+is($tix->Count, 1, "matched identical subject");
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo1'");
+is($tix->Count, 1, "matched LIKE subject");
$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'two'");
-is($tix->Count, 1, "found one ticket");
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo'");
+is($tix->Count, 0, "IS a regexp match");
$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'o'");
-is($tix->Count, 2, "found two tickets");
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
+is($tix->Count, 5, "matched LIKE subject");
+#$tix = RT::Tickets->new($RT::SystemUser);
+#$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
+#is($tix->Count, 2, "LIKE null CF");
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
+is($tix->Count, 2, "IS null CF");
+exit;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'");
-is($tix->Count, 1, "found one ticket");
+is($tix->Count, 1, "LIKE requestor");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Requestors = 'search1\@example.com'");
+is($tix->Count, 1, "IS requestor");
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'");
+is($tix->Count, 6, "LIKE requestor");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Requestors IS NULL");
+is($tix->Count, 1, "Search for no requestor");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'");
+is($tix->Count, 1, "IS subject");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest1'");
+is($tix->Count, 1, "LIKE subject");
$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search2'");
+$tix->FromSQL("Queue = '$queue' AND Subject = ''");
is($tix->Count, 1, "found one ticket");
$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'");
-is($tix->Count, 2, "found two tickets");
+$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest'");
+is($tix->Count, 6, "found two ticket");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'qwerty'");
+is($tix->Count, 0, "found zero ticket");
+
+
+
+
+# various combinations
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar1'");
+is($tix->Count, 1, "LIKE cf and LIKE cf");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest = 'foo1' AND CF.SearchTest2 = 'bar1'");
+is($tix->Count, 1, "is cf and is cf");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest = 'foo' AND CF.SearchTest2 LIKE 'bar1'");
+is($tix->Count, 0, "is cf and like cf");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar' AND CF.SearchTest3 LIKE 'qux'");
+is($tix->Count, 3, "like cf and like cf and like cf");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest LIKE 'foo' AND CF.SearchTest2 LIKE 'bar' AND CF.SearchTest3 LIKE 'qux6'");
+is($tix->Count, 1, "like cf and like cf and is cf");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest LIKE 'foo' AND Subject LIKE 'SearchTest'");
+is($tix->Count, 4, "like cf and like subject");
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar5'");
+is($tix->Count, 1, "null cf and is cf");
+
+
+
+$tix = RT::Tickets->new($RT::SystemUser);
+$tix->FromSQL("Queue = '$$' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL");
+is($tix->Count, 1, "null cf and null cf");
+
+
More information about the Rt-commit
mailing list