summaryrefslogtreecommitdiff
path: root/rt/lib/t/regression
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/t/regression')
-rw-r--r--rt/lib/t/regression/00-mason-syntax.t4
-rw-r--r--rt/lib/t/regression/12-search.t45
-rw-r--r--rt/lib/t/regression/20-sort-by-queue.t103
-rw-r--r--rt/lib/t/regression/20-sort-by-user.t155
-rw-r--r--rt/lib/t/regression/22search_tix_by_watcher.t53
-rw-r--r--rt/lib/t/regression/23cfsort-freeform-multiple.t137
-rw-r--r--rt/lib/t/regression/23cfsort-freeform-single.t191
-rw-r--r--rt/lib/t/regression/23cfsort.t21
-rw-r--r--rt/lib/t/regression/24-watchers.t157
-rw-r--r--rt/lib/t/regression/26command_line.t7
10 files changed, 834 insertions, 39 deletions
diff --git a/rt/lib/t/regression/00-mason-syntax.t b/rt/lib/t/regression/00-mason-syntax.t
index a94c7efc1..ce692a3b1 100644
--- a/rt/lib/t/regression/00-mason-syntax.t
+++ b/rt/lib/t/regression/00-mason-syntax.t
@@ -12,10 +12,6 @@ find( {
no_chdir => 1,
wanted => sub {
return if /\.(?:jpe?g|png|gif|rej|\~)$/i;
- if (m!/\.svn$!) {
- $File::Find::prune = 1;
- return;
- }
return unless -f $_;
diag "testing $_" if $ENV{'TEST_VERBOSE'};
eval { compile_file($_) } and return;
diff --git a/rt/lib/t/regression/12-search.t b/rt/lib/t/regression/12-search.t
index 210d4fe33..c775f9372 100644
--- a/rt/lib/t/regression/12-search.t
+++ b/rt/lib/t/regression/12-search.t
@@ -142,67 +142,82 @@ 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, 7, "found all the tickets")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
# very simple searches. both CF and normal
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo1'");
-is($tix->Count, 1, "matched identical subject");
+is($tix->Count, 1, "matched identical subject")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo1'");
-is($tix->Count, 1, "matched LIKE subject");
+is($tix->Count, 1, "matched LIKE subject")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo'");
-is($tix->Count, 0, "IS a regexp match");
+is($tix->Count, 0, "IS a regexp match")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
-is($tix->Count, 5, "matched LIKE subject");
+is($tix->Count, 5, "matched LIKE subject")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
-is($tix->Count, 2, "IS null CF");
+is($tix->Count, 2, "IS null CF")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'");
-is($tix->Count, 1, "LIKE requestor");
+is($tix->Count, 1, "LIKE requestor")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors = 'search1\@example.com'");
-is($tix->Count, 1, "IS requestor");
+is($tix->Count, 1, "IS requestor")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'");
-is($tix->Count, 6, "LIKE requestor");
+is($tix->Count, 6, "LIKE requestor")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors IS NULL");
-is($tix->Count, 1, "Search for no requestor");
+is($tix->Count, 1, "Search for no requestor")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'");
-is($tix->Count, 1, "IS subject");
+is($tix->Count, 1, "IS subject")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest1'");
-is($tix->Count, 1, "LIKE subject");
+is($tix->Count, 1, "LIKE subject")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = ''");
-is($tix->Count, 1, "found one ticket");
+is($tix->Count, 1, "found one ticket")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest'");
-is($tix->Count, 6, "found two ticket");
+is($tix->Count, 6, "found two ticket")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
$tix = RT::Tickets->new($RT::SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'qwerty'");
-is($tix->Count, 0, "found zero ticket");
+is($tix->Count, 0, "found zero ticket")
+ or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
diff --git a/rt/lib/t/regression/20-sort-by-queue.t b/rt/lib/t/regression/20-sort-by-queue.t
new file mode 100644
index 000000000..16eabe91b
--- /dev/null
+++ b/rt/lib/t/regression/20-sort-by-queue.t
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+
+use Test::More tests => 8;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+#########################################################
+# Test sorting by Queue, we sort by its name
+#########################################################
+
+
+diag "Create queues to test with.";
+my @qids;
+my @queues;
+# create them in reverse order to avoid false positives
+foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) {
+ my $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $name ."-$$",
+ Description => 'queue to test sorting by queue'
+ );
+ ok($ret, "test queue creation. $msg");
+ push @queues, $queue;
+ push @qids, $queue->id;
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+ my ( $id, undef, $msg ) = $t->Create( %args );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+@data = (
+ { Queue => $qids[0], Subject => 'z' },
+ { Queue => $qids[1], Subject => 'a' },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "Queue" },
+);
+run_tests();
+
diff --git a/rt/lib/t/regression/20-sort-by-user.t b/rt/lib/t/regression/20-sort-by-user.t
new file mode 100644
index 000000000..04bf2e75f
--- /dev/null
+++ b/rt/lib/t/regression/20-sort-by-user.t
@@ -0,0 +1,155 @@
+#!/usr/bin/perl
+
+use Test::More tests => 32;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+#########################################################
+# Test sorting by Owner, Creator and LastUpdatedBy
+# we sort by user name
+#########################################################
+
+diag "Create a queue to test with.";
+my $queue_name = "OwnerSortQueue$$";
+my $queue;
+{
+ $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $queue,
+ Description => 'queue for custom field sort testing'
+ );
+ ok($ret, "$queue test queue creation. $msg");
+}
+
+my @uids;
+my @users;
+# create them in reverse order to avoid false positives
+foreach my $u (qw(Z A)) {
+ my $name = $u ."-user-to-test-ordering-$$";
+ my $user = RT::User->new( $RT::SystemUser );
+ my ($uid) = $user->Create(
+ Name => $name,
+ Privileged => 1,
+ );
+ ok $uid, "created user #$uid";
+
+ my ($status, $msg) = $user->PrincipalObj->GrantRight( Right => 'OwnTicket', Object => $queue );
+ ok $status, "granted right";
+ ($status, $msg) = $user->PrincipalObj->GrantRight( Right => 'CreateTicket', Object => $queue );
+ ok $status, "granted right";
+
+ push @users, $user;
+ push @uids, $user->id;
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+
+ my ( $id, undef, $msg ) = $t->Create( %args, Queue => $queue->id );
+ if ( $args{'Owner'} ) {
+ is $t->Owner, $args{'Owner'}, "owner is correct";
+ }
+ if ( $args{'Creator'} ) {
+ is $t->Creator, $args{'Creator'}, "creator is correct";
+ }
+ # hackish, but simpler
+ if ( $args{'LastUpdatedBy'} ) {
+ $t->__Set( Field => 'LastUpdatedBy', Value => $args{'LastUpdatedBy'} );
+ }
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+@data = (
+ { Subject => 'Nobody' },
+ { Subject => 'Z', Owner => $uids[0] },
+ { Subject => 'A', Owner => $uids[1] },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "Owner" },
+);
+run_tests();
+
+@data = (
+ { Subject => 'RT' },
+ { Subject => 'Z', Creator => $uids[0] },
+ { Subject => 'A', Creator => $uids[1] },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "Creator" },
+);
+run_tests();
+
+@data = (
+ { Subject => 'RT' },
+ { Subject => 'Z', LastUpdatedBy => $uids[0] },
+ { Subject => 'A', LastUpdatedBy => $uids[1] },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "LastUpdatedBy" },
+);
+run_tests();
+
diff --git a/rt/lib/t/regression/22search_tix_by_watcher.t b/rt/lib/t/regression/22search_tix_by_watcher.t
index 4dd11af1e..204c41c37 100644
--- a/rt/lib/t/regression/22search_tix_by_watcher.t
+++ b/rt/lib/t/regression/22search_tix_by_watcher.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 79;
+use Test::More tests => 119;
use_ok('RT');
RT::LoadConfig();
RT::Init();
@@ -95,6 +95,56 @@ sub run_tests {
}
run_tests();
+# mixing searches by watchers with other conditions
+# http://rt3.fsck.com/Ticket/Display.html?id=9322
+%test = (
+ 'Subject LIKE "x" AND Requestor = "y@example.com"' =>
+ { xy => 1, x => 0, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" AND Requestor = "y@example.com"' =>
+ { xy => 0, x => 0, y => 1, '-' => 0, z => 0 },
+ 'Subject LIKE "x" AND Requestor != "y@example.com"' =>
+ { xy => 0, x => 1, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" AND Requestor != "y@example.com"' =>
+ { xy => 0, x => 0, y => 0, '-' => 1, z => 1 },
+
+ 'Subject LIKE "x" OR Requestor = "y@example.com"' =>
+ { xy => 1, x => 1, y => 1, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" OR Requestor = "y@example.com"' =>
+ { xy => 1, x => 0, y => 1, '-' => 1, z => 1 },
+ 'Subject LIKE "x" OR Requestor != "y@example.com"' =>
+ { xy => 1, x => 1, y => 0, '-' => 1, z => 1 },
+ 'Subject NOT LIKE "x" OR Requestor != "y@example.com"' =>
+ { xy => 0, x => 1, y => 1, '-' => 1, z => 1 },
+
+# group of cases when user doesn't exist in DB at all
+ 'Subject LIKE "x" AND Requestor = "not-exist@example.com"' =>
+ { xy => 0, x => 0, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" AND Requestor = "not-exist@example.com"' =>
+ { xy => 0, x => 0, y => 0, '-' => 0, z => 0 },
+ 'Subject LIKE "x" AND Requestor != "not-exist@example.com"' =>
+ { xy => 1, x => 1, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" AND Requestor != "not-exist@example.com"' =>
+ { xy => 0, x => 0, y => 1, '-' => 1, z => 1 },
+ 'Subject LIKE "x" OR Requestor = "not-exist@example.com"' =>
+ { xy => 1, x => 1, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "x" OR Requestor = "not-exist@example.com"' =>
+ { xy => 0, x => 0, y => 1, '-' => 1, z => 1 },
+ 'Subject LIKE "x" OR Requestor != "not-exist@example.com"' =>
+ { xy => 1, x => 1, y => 1, '-' => 1, z => 1 },
+ 'Subject NOT LIKE "x" OR Requestor != "not-exist@example.com"' =>
+ { xy => 1, x => 1, y => 1, '-' => 1, z => 1 },
+
+ 'Subject LIKE "z" AND (Requestor = "x@example.com" OR Requestor = "y@example.com")' =>
+ { xy => 0, x => 0, y => 0, '-' => 0, z => 0 },
+ 'Subject NOT LIKE "z" AND (Requestor = "x@example.com" OR Requestor = "y@example.com")' =>
+ { xy => 1, x => 1, y => 1, '-' => 0, z => 0 },
+ 'Subject LIKE "z" OR (Requestor = "x@example.com" OR Requestor = "y@example.com")' =>
+ { xy => 1, x => 1, y => 1, '-' => 0, z => 1 },
+ 'Subject NOT LIKE "z" OR (Requestor = "x@example.com" OR Requestor = "y@example.com")' =>
+ { xy => 1, x => 1, y => 1, '-' => 1, z => 0 },
+);
+run_tests();
+
TODO: {
local $TODO = "we can't generate this query yet";
%test = (
@@ -142,6 +192,7 @@ TODO: {
}
run_tests();
+
# owner is special watcher because reference is duplicated in two places,
# owner was an ENUM field now it's WATCHERFIELD, but should support old
# style ENUM searches for backward compatibility
diff --git a/rt/lib/t/regression/23cfsort-freeform-multiple.t b/rt/lib/t/regression/23cfsort-freeform-multiple.t
new file mode 100644
index 000000000..453e83cf5
--- /dev/null
+++ b/rt/lib/t/regression/23cfsort-freeform-multiple.t
@@ -0,0 +1,137 @@
+#!/usr/bin/perl
+
+use Test::More tests => 24;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+# Test Sorting by custom fields.
+
+diag "Create a queue to test with.";
+my $queue_name = "CFSortQueue-$$";
+my $queue;
+{
+ $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $queue_name,
+ Description => 'queue for custom field sort testing'
+ );
+ ok($ret, "$queue_name - test queue creation. $msg");
+}
+
+diag "create a CF\n";
+my $cf_name = "Order$$";
+my $cf;
+{
+ $cf = RT::CustomField->new( $RT::SystemUser );
+ my ($ret, $msg) = $cf->Create(
+ Name => $cf_name,
+ Queue => $queue->id,
+ Type => 'FreeformMultiple',
+ );
+ ok($ret, "Custom Field Order created");
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+ my @values = ();
+ if ( exists $args{'CF'} && ref $args{'CF'} ) {
+ @values = @{ delete $args{'CF'} };
+ } elsif ( exists $args{'CF'} ) {
+ @values = (delete $args{'CF'});
+ }
+ $args{ 'CustomField-'. $cf->id } = \@values
+ if @values;
+ my $subject = join(",", sort @values) || '-';
+ my ( $id, undef $msg ) = $t->Create(
+ %args,
+ Queue => $queue->id,
+ Subject => $subject,
+ );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+@data = (
+ { },
+ { CF => ['b', 'd'] },
+ { CF => ['a', 'c'] },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "CF.{$cf_name}" },
+ { Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+@data = (
+ { CF => ['m', 'a'] },
+ { CF => ['m'] },
+ { CF => ['m', 'o'] },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "CF.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
+ { Order => "CF.$queue_name.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
+);
+run_tests();
+
diff --git a/rt/lib/t/regression/23cfsort-freeform-single.t b/rt/lib/t/regression/23cfsort-freeform-single.t
new file mode 100644
index 000000000..277befe0a
--- /dev/null
+++ b/rt/lib/t/regression/23cfsort-freeform-single.t
@@ -0,0 +1,191 @@
+#!/usr/bin/perl
+
+use Test::More tests => 57;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+# Test Sorting by FreeformSingle custom field.
+
+diag "Create a queue to test with.";
+my $queue_name = "CFSortQueue$$";
+my $queue;
+{
+ $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $queue,
+ Description => 'queue for custom field sort testing'
+ );
+ ok($ret, "$queue test queue creation. $msg");
+}
+
+# CFs for testing, later we create another one
+my %CF;
+my $cf_name;
+
+diag "create a CF\n";
+{
+ $cf_name = $CF{'CF'}{'name'} = "Order$$";
+ $CF{'CF'}{'obj'} = RT::CustomField->new( $RT::SystemUser );
+ my ($ret, $msg) = $CF{'CF'}{'obj'}->Create(
+ Name => $CF{'CF'}{'name'},
+ Queue => $queue->id,
+ Type => 'FreeformSingle',
+ );
+ ok($ret, "Custom Field $CF{'CF'}{'name'} created");
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+
+ my $subject = '-';
+ foreach my $e ( grep exists $CF{$_} && defined $CF{$_}, keys %args ) {
+ my @values = ();
+ if ( ref $args{ $e } ) {
+ @values = @{ delete $args{ $e } };
+ } else {
+ @values = (delete $args{ $e });
+ }
+ $args{ 'CustomField-'. $CF{ $e }{'obj'}->id } = \@values
+ if @values;
+ $subject = join(",", sort @values) || '-'
+ if $e eq 'CF';
+ }
+
+ my ( $id, undef $msg ) = $t->Create(
+ %args,
+ Queue => $queue->id,
+ Subject => $subject,
+ );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+@data = (
+ { },
+ { CF => 'a' },
+ { CF => 'b' },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "CF.{$cf_name}" },
+ { Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+@data = (
+ { },
+ { CF => 'aa' },
+ { CF => 'ab' },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.{$cf_name}" },
+ { Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+@data = (
+ { Subject => '-', },
+ { Subject => 'a', CF => 'a' },
+ { Subject => 'b', CF => 'b' },
+ { Subject => 'c', CF => 'c' },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" },
+ { Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+
+
+diag "create another CF\n";
+{
+ $CF{'AnotherCF'}{'name'} = "OrderAnother$$";
+ $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( $RT::SystemUser );
+ my ($ret, $msg) = $CF{'AnotherCF'}{'obj'}->Create(
+ Name => $CF{'AnotherCF'}{'name'},
+ Queue => $queue->id,
+ Type => 'FreeformSingle',
+ );
+ ok($ret, "Custom Field $CF{'AnotherCF'}{'name'} created");
+}
+
+# test that order is not affect by other fields (had such problem)
+@data = (
+ { Subject => '-', },
+ { Subject => 'a', CF => 'a', AnotherCF => 'za' },
+ { Subject => 'b', CF => 'b', AnotherCF => 'ya' },
+ { Subject => 'c', CF => 'c', AnotherCF => 'xa' },
+);
+@tickets = add_tix_from_data();
+@test = (
+ { Order => "CF.{$cf_name}" },
+ { Order => "CF.$queue_name.{$cf_name}" },
+ { Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" },
+ { Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+
+
diff --git a/rt/lib/t/regression/23cfsort.t b/rt/lib/t/regression/23cfsort.t
index 85decc707..ba404f2ba 100644
--- a/rt/lib/t/regression/23cfsort.t
+++ b/rt/lib/t/regression/23cfsort.t
@@ -16,6 +16,8 @@ my($ret,$msg);
# Test Sorting by custom fields.
+# TODO: it's hard to read this file, conver to new style,
+# for example look at 23cfsort-freeform-single.t
# ---- Create a queue to test with.
my $queue = "CFSortQueue-$$";
@@ -116,20 +118,14 @@ $tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DESC' );
diag $tx->BuildSelectQuery;
is($tx->Count,2);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 2);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'ASC' );
diag $tx->BuildSelectQuery;
is($tx->Count,2);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 2, 1);
-}
# Add a new ticket, to test sorting on multiple columns.
my $t3 = RT::Ticket->new($RT::SystemUser);
@@ -148,10 +144,7 @@ $tx->OrderByCols(
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 3, 2, 1);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
@@ -160,10 +153,7 @@ $tx->OrderByCols(
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 2, 3);
-}
# Reverse the order of the secondary column, which changes the order
# of the first two tickets.
@@ -174,10 +164,7 @@ $tx->OrderByCols(
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 2, 3, 1);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
@@ -186,7 +173,5 @@ $tx->OrderByCols(
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 3, 2);
-}
+
diff --git a/rt/lib/t/regression/24-watchers.t b/rt/lib/t/regression/24-watchers.t
new file mode 100644
index 000000000..69bc8acc6
--- /dev/null
+++ b/rt/lib/t/regression/24-watchers.t
@@ -0,0 +1,157 @@
+#!/usr/bin/perl -w
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+# <jesse.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+use Test::More tests => 28;
+use RT;
+RT::LoadConfig();
+RT::Init();
+use strict;
+no warnings 'once';
+
+use RT::Queue;
+use RT::User;
+use RT::Group;
+use RT::Ticket;
+use RT::CurrentUser;
+
+
+# clear all global right
+my $acl = RT::ACL->new($RT::SystemUser);
+$acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' );
+$acl->LimitToObject( $RT::System );
+while( my $ace = $acl->Next ) {
+ $ace->Delete;
+}
+
+# create new queue to be sure we do not mess with rights
+my $queue = RT::Queue->new($RT::SystemUser);
+my ($queue_id) = $queue->Create( Name => 'watcher tests '.$$);
+ok( $queue_id, 'queue created for watcher tests' );
+
+# new privileged user to check rights
+my $user = RT::User->new( $RT::SystemUser );
+my ($user_id) = $user->Create( Name => 'watcher'.$$,
+ EmailAddress => "watcher$$".'@localhost',
+ Privileged => 1,
+ Password => 'qwe123',
+ );
+my $cu= RT::CurrentUser->new($user);
+
+# make sure user can see tickets in the queue
+my $principal = $user->PrincipalObj;
+ok( $principal, "principal loaded" );
+$principal->GrantRight( Right => 'ShowTicket', Object => $queue );
+$principal->GrantRight( Right => 'SeeQueue' , Object => $queue );
+
+ok( $user->HasRight( Right => 'SeeQueue', Object => $queue ), "user can see queue" );
+ok( $user->HasRight( Right => 'ShowTicket', Object => $queue ), "user can show queue tickets" );
+ok( !$user->HasRight( Right => 'ModifyTicket', Object => $queue ), "user can't modify queue tickets" );
+ok( !$user->HasRight( Right => 'Watch', Object => $queue ), "user can't watch queue tickets" );
+
+my $ticket = RT::Ticket->new( $RT::SystemUser );
+my ($rv, $msg) = $ticket->Create( Subject => 'watcher tests', Queue => $queue->Name );
+ok( $ticket->id, "ticket created" );
+
+my $ticket2 = RT::Ticket->new( $cu );
+$ticket2->Load( $ticket->id );
+ok( $ticket2->Subject, "ticket load by user" );
+
+# user can add self to ticket only after getting Watch right
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( !$rv, "user can't add self as Cc" );
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Requestor', PrincipalId => $user->PrincipalId );
+ok( !$rv, "user can't add self as Requestor" );
+$principal->GrantRight( Right => 'Watch' , Object => $queue );
+ok( $user->HasRight( Right => 'Watch', Object => $queue ), "user can watch queue tickets" );
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( $rv, "user can add self as Cc by PrincipalId" );
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Requestor', PrincipalId => $user->PrincipalId );
+ok( $rv, "user can add self as Requestor by PrincipalId" );
+
+# remove user and try adding with Email address
+($rv, $msg) = $ticket->DeleteWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( $rv, "watcher removed by PrincipalId" );
+($rv, $msg) = $ticket->DeleteWatcher( Type => 'Requestor', Email => $user->EmailAddress );
+ok( $rv, "watcher removed by Email" );
+
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Cc', Email => $user->EmailAddress );
+ok( $rv, "user can add self as Cc by Email" );
+($rv, $msg) = $ticket2->AddWatcher( Type => 'Requestor', Email => $user->EmailAddress );
+ok( $rv, "user can add self as Requestor by Email" );
+
+# Queue watcher tests
+$principal->RevokeRight( Right => 'Watch' , Object => $queue );
+ok( !$user->HasRight( Right => 'Watch', Object => $queue ), "user queue watch right revoked" );
+
+my $queue2 = RT::Queue->new( $cu );
+($rv, $msg) = $queue2->Load( $queue->id );
+ok( $rv, "user loaded queue" );
+
+# user can add self to queue only after getting Watch right
+($rv, $msg) = $queue2->AddWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( !$rv, "user can't add self as Cc" );
+($rv, $msg) = $queue2->AddWatcher( Type => 'Requestor', PrincipalId => $user->PrincipalId );
+ok( !$rv, "user can't add self as Requestor" );
+$principal->GrantRight( Right => 'Watch' , Object => $queue );
+ok( $user->HasRight( Right => 'Watch', Object => $queue ), "user can watch queue queues" );
+($rv, $msg) = $queue2->AddWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( $rv, "user can add self as Cc by PrincipalId" );
+($rv, $msg) = $queue2->AddWatcher( Type => 'Requestor', PrincipalId => $user->PrincipalId );
+ok( $rv, "user can add self as Requestor by PrincipalId" );
+
+# remove user and try adding with Email address
+($rv, $msg) = $queue->DeleteWatcher( Type => 'Cc', PrincipalId => $user->PrincipalId );
+ok( $rv, "watcher removed by PrincipalId" );
+($rv, $msg) = $queue->DeleteWatcher( Type => 'Requestor', Email => $user->EmailAddress );
+ok( $rv, "watcher removed by Email" );
+
+($rv, $msg) = $queue2->AddWatcher( Type => 'Cc', Email => $user->EmailAddress );
+ok( $rv, "user can add self as Cc by Email" );
+($rv, $msg) = $queue2->AddWatcher( Type => 'Requestor', Email => $user->EmailAddress );
+ok( $rv, "user can add self as Requestor by Email" );
+
+
diff --git a/rt/lib/t/regression/26command_line.t b/rt/lib/t/regression/26command_line.t
index 457c63aa5..702138303 100644
--- a/rt/lib/t/regression/26command_line.t
+++ b/rt/lib/t/regression/26command_line.t
@@ -3,7 +3,7 @@
use strict;
use Test::Expect;
#use Test::More qw/no_plan/;
-use Test::More tests => 218;
+use Test::More tests => 222;
use RT;
RT::LoadConfig();
@@ -155,6 +155,11 @@ expect_send("edit ticket/$ticket_id set 'CF-myCF$$=VALUE' ", 'Changing CF...');
expect_like(qr/Ticket $ticket_id updated/, 'Changed cf');
expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value');
expect_like(qr/CF-myCF$$: VALUE/i, 'Verified change');
+# Test setting 0 as value of the custom field
+expect_send("edit ticket/$ticket_id set 'CF-myCF$$=0' ", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed cf');
+expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value');
+expect_like(qr/CF-myCF$$: 0/i, 'Verified change');
# Test reading and setting custom fields with spaces
expect_send("show ticket/$ticket_id -f 'CF-my CF$$'", 'Checking initial value');
expect_like(qr/my CF$$:/i, 'Verified change');