summaryrefslogtreecommitdiff
path: root/rt/t/ticket
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
committerIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
commit43a06151e47d2c59b833cbd8c26d97865ee850b6 (patch)
tree42c51d94e7fa265461b508d061562be204ccc2c1 /rt/t/ticket
parent6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff)
starting to work...
Diffstat (limited to 'rt/t/ticket')
-rw-r--r--rt/t/ticket/action_linear_escalate.t9
-rw-r--r--rt/t/ticket/add-watchers.t13
-rw-r--r--rt/t/ticket/badlinks.t4
-rw-r--r--rt/t/ticket/batch-upload-csv.t7
-rw-r--r--rt/t/ticket/cfsort-freeform-multiple.t61
-rw-r--r--rt/t/ticket/cfsort-freeform-single.t72
-rw-r--r--rt/t/ticket/deferred_owner.t21
-rw-r--r--rt/t/ticket/link_search.t14
-rw-r--r--rt/t/ticket/linking.t78
-rw-r--r--rt/t/ticket/merge.t12
-rw-r--r--rt/t/ticket/quicksearch.t41
-rw-r--r--rt/t/ticket/requestor-order.t26
-rw-r--r--rt/t/ticket/scrips_batch.t24
-rw-r--r--rt/t/ticket/search.t88
-rw-r--r--rt/t/ticket/search_by_cf_freeform_multiple.t55
-rw-r--r--rt/t/ticket/search_by_cf_freeform_single.t41
-rw-r--r--rt/t/ticket/search_by_links.t39
-rw-r--r--rt/t/ticket/search_by_txn.t4
-rw-r--r--rt/t/ticket/search_by_watcher.t362
-rw-r--r--rt/t/ticket/search_long_cf_values.t22
-rw-r--r--rt/t/ticket/sort-by-custom-ownership.t20
-rw-r--r--rt/t/ticket/sort-by-queue.t29
-rw-r--r--rt/t/ticket/sort-by-user.t45
-rw-r--r--rt/t/ticket/sort_by_cf.t34
24 files changed, 461 insertions, 660 deletions
diff --git a/rt/t/ticket/action_linear_escalate.t b/rt/t/ticket/action_linear_escalate.t
index 38cd47ded..2a1be611d 100644
--- a/rt/t/ticket/action_linear_escalate.t
+++ b/rt/t/ticket/action_linear_escalate.t
@@ -34,7 +34,7 @@ my $user = RT::Test->load_or_create_user(
ok $user && $user->id, 'loaded or created user';
$user->PrincipalObj->GrantRight( Right => 'SuperUser' );
-my $current_user = RT::CurrentUser->new($RT::SystemUser);
+my $current_user = RT::CurrentUser->new(RT->SystemUser);
($id, $msg) = $current_user->Load($user->id);
ok( $id, "Got current user? $msg" );
@@ -60,15 +60,12 @@ escalate_ticket_ok($ticket3);
ok( $ticket3->LastUpdatedBy == $user->id, "Did not set LastUpdated" );
ok( $ticket3->Transactions->Last->Type =~ /Create/i, "Did not record a transaction" );
-1;
-
-
sub create_ticket_as_ok {
my $user = shift;
- my $created = RT::Date->new($RT::SystemUser);
+ my $created = RT::Date->new(RT->SystemUser);
$created->Unix(time() - ( 7 * 24 * 60**2 ));
- my $due = RT::Date->new($RT::SystemUser);
+ my $due = RT::Date->new(RT->SystemUser);
$due->Unix(time() + ( 7 * 24 * 60**2 ));
my $ticket = RT::Ticket->new($user);
diff --git a/rt/t/ticket/add-watchers.t b/rt/t/ticket/add-watchers.t
index ae993a936..e49c694ed 100644
--- a/rt/t/ticket/add-watchers.t
+++ b/rt/t/ticket/add-watchers.t
@@ -45,11 +45,10 @@
#
# END BPS TAGGED BLOCK }}}
-use RT::Test tests => 32;
+use RT::Test nodata => 1, tests => 32;
use strict;
use warnings;
-no warnings 'once';
use RT::Queue;
use RT::User;
@@ -59,20 +58,20 @@ use RT::CurrentUser;
# clear all global right
-my $acl = RT::ACL->new($RT::SystemUser);
+my $acl = RT::ACL->new(RT->SystemUser);
$acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' );
-$acl->LimitToObject( $RT::System );
+$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 = 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 = RT::User->new( RT->SystemUser );
my ($user_id) = $user->Create( Name => 'watcher'.$$,
EmailAddress => "watcher$$".'@localhost',
Privileged => 1,
@@ -91,7 +90,7 @@ ok( $user->HasRight( Right => 'ShowTicket', Object => $queue ), "user can sho
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 $ticket = RT::Ticket->new( RT->SystemUser );
my ($rv, $msg) = $ticket->Create( Subject => 'watcher tests', Queue => $queue->Name );
ok( $ticket->id, "ticket created" );
diff --git a/rt/t/ticket/badlinks.t b/rt/t/ticket/badlinks.t
index 408e6b67c..71ab73928 100644
--- a/rt/t/ticket/badlinks.t
+++ b/rt/t/ticket/badlinks.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use RT::Test tests => 12;
+use RT::Test tests => 14;
my ($baseurl, $m) = RT::Test->started_ok;
ok($m->login, "Logged in");
@@ -9,7 +9,7 @@ ok($m->login, "Logged in");
my $queue = RT::Test->load_or_create_queue(Name => 'General');
ok($queue->Id, "loaded the General queue");
-my $ticket = RT::Ticket->new($RT::SystemUser);
+my $ticket = RT::Ticket->new(RT->SystemUser);
my ($tid, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test links',
diff --git a/rt/t/ticket/batch-upload-csv.t b/rt/t/ticket/batch-upload-csv.t
index 41dc78696..cedc0143a 100644
--- a/rt/t/ticket/batch-upload-csv.t
+++ b/rt/t/ticket/batch-upload-csv.t
@@ -8,10 +8,10 @@ use_ok('RT::Action::CreateTickets');
my $QUEUE = 'uploadtest-'.$$;
-my $queue_obj = RT::Queue->new($RT::SystemUser);
+my $queue_obj = RT::Queue->new(RT->SystemUser);
$queue_obj->Create(Name => $QUEUE);
-my $cf = RT::CustomField->new($RT::SystemUser);
+my $cf = RT::CustomField->new(RT->SystemUser);
my ($val,$msg) = $cf->Create(Name => 'Work Package-'.$$, Type => 'Freeform', LookupType => RT::Ticket->CustomFieldLookupType, MaxValues => 1);
ok($cf->id);
ok($val,$msg);
@@ -32,7 +32,7 @@ ok ($action->CurrentUser->id , "WE have a current user");
$action->Parse(Content => $data);
my @results = $action->CreateByTemplate();
-my $tix = RT::Tickets->new($RT::SystemUser);
+my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL ("Queue = '". $QUEUE."'");
$tix->OrderBy( FIELD => 'id', ORDER => 'ASC' );
is($tix->Count, 2, '2 tickets');
@@ -45,4 +45,3 @@ is($first->FirstCustomFieldValue($cf->id), '2.0');
my $second = $tix->Next;
is($second->Subject(), 'hello');
is($second->FirstCustomFieldValue($cf->id), '3.0');
-1;
diff --git a/rt/t/ticket/cfsort-freeform-multiple.t b/rt/t/ticket/cfsort-freeform-multiple.t
index f8f5950ef..e285d0e6f 100644
--- a/rt/t/ticket/cfsort-freeform-multiple.t
+++ b/rt/t/ticket/cfsort-freeform-multiple.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test tests => 24;
+use RT::Test nodata => 1, tests => 41;
use strict;
use warnings;
@@ -11,11 +11,11 @@ use RT::CustomField;
# Test Sorting by custom fields.
-diag "Create a queue to test with." if $ENV{TEST_VERBOSE};
+diag "Create a queue to test with.";
my $queue_name = "CFSortQueue-$$";
my $queue;
{
- $queue = RT::Queue->new( $RT::SystemUser );
+ $queue = RT::Queue->new( RT->SystemUser );
my ($ret, $msg) = $queue->Create(
Name => $queue_name,
Description => 'queue for custom field sort testing'
@@ -23,11 +23,11 @@ my $queue;
ok($ret, "$queue_name - test queue creation. $msg");
}
-diag "create a CF\n" if $ENV{TEST_VERBOSE};
+diag "create a CF";
my $cf_name = "Order$$";
my $cf;
{
- $cf = RT::CustomField->new( $RT::SystemUser );
+ $cf = RT::CustomField->new( RT->SystemUser );
my ($ret, $msg) = $cf->Create(
Name => $cf_name,
Queue => $queue->id,
@@ -36,34 +36,9 @@ my $cf;
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;
-}
+my (@data, @tickets, @test) = (0, ());
+
+
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -73,7 +48,7 @@ sub run_tests {
foreach my $order (qw(ASC DESC)) {
my $error = 0;
- my $tix = RT::Tickets->new( $RT::SystemUser );
+ my $tix = RT::Tickets->new( RT->SystemUser );
$tix->FromSQL( $query );
$tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
@@ -112,11 +87,11 @@ sub run_tests {
}
@data = (
- { },
- { CF => ['b', 'd'] },
- { CF => ['a', 'c'] },
+ { Subject => '-' },
+ { Subject => 'b-d', 'CustomField-' . $cf->id => ['b', 'd'] },
+ { Subject => 'a-c', 'CustomField-' . $cf->id => ['a', 'c'] },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( {Queue => $queue->id, RandomOrder => 1 }, @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
@@ -124,14 +99,16 @@ sub run_tests {
run_tests();
@data = (
- { CF => ['m', 'a'] },
- { CF => ['m'] },
- { CF => ['m', 'o'] },
+ { Subject => 'm-a', 'CustomField-' . $cf->id => ['m', 'a'] },
+ { Subject => 'm', 'CustomField-' . $cf->id => ['m'] },
+ { Subject => 'm-o', 'CustomField-' . $cf->id => ['m', 'o'] },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( {Queue => $queue->id, RandomORder => 1 }, @data);
@test = (
{ Order => "CF.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
{ Order => "CF.$queue_name.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
);
run_tests();
+@tickets = ();
+
diff --git a/rt/t/ticket/cfsort-freeform-single.t b/rt/t/ticket/cfsort-freeform-single.t
index f1f506bea..35a53fb54 100644
--- a/rt/t/ticket/cfsort-freeform-single.t
+++ b/rt/t/ticket/cfsort-freeform-single.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test tests => 57;
+use RT::Test nodata => 1, tests => 89;
use strict;
use warnings;
@@ -11,11 +11,11 @@ use RT::CustomField;
# Test Sorting by FreeformSingle custom field.
-diag "Create a queue to test with." if $ENV{TEST_VERBOSE};
+diag "Create a queue to test with.";
my $queue_name = "CFSortQueue-$$";
my $queue;
{
- $queue = RT::Queue->new( $RT::SystemUser );
+ $queue = RT::Queue->new( RT->SystemUser );
my ($ret, $msg) = $queue->Create(
Name => $queue_name,
Description => 'queue for custom field sort testing'
@@ -27,10 +27,10 @@ my $queue;
my %CF;
my $cf_name;
-diag "create a CF\n" if $ENV{TEST_VERBOSE};
+diag "create a CF";
{
$cf_name = $CF{'CF'}{'name'} = "Order$$";
- $CF{'CF'}{'obj'} = RT::CustomField->new( $RT::SystemUser );
+ $CF{'CF'}{'obj'} = RT::CustomField->new( RT->SystemUser );
my ($ret, $msg) = $CF{'CF'}{'obj'}->Create(
Name => $CF{'CF'}{'name'},
Queue => $queue->id,
@@ -41,39 +41,6 @@ diag "create a CF\n" if $ENV{TEST_VERBOSE};
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 ) {
@@ -82,7 +49,7 @@ sub run_tests {
foreach my $order (qw(ASC DESC)) {
my $error = 0;
- my $tix = RT::Tickets->new( $RT::SystemUser );
+ my $tix = RT::Tickets->new( RT->SystemUser );
$tix->FromSQL( $query );
$tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
@@ -121,11 +88,12 @@ sub run_tests {
}
@data = (
- { },
- { CF => 'a' },
- { CF => 'b' },
+ { Subject => '-' },
+ { Subject => 'a', 'CustomField-' . $CF{CF}{obj}->id => 'a' },
+ { Subject => 'b', 'CustomField-' . $CF{CF}{obj}->id => 'b' },
);
-@tickets = add_tix_from_data();
+
+@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
@@ -133,11 +101,11 @@ sub run_tests {
run_tests();
@data = (
- { },
- { CF => 'aa' },
- { CF => 'ab' },
+ { Subject => '-' },
+ { Subject => 'aa', 'CustomField-' . $CF{CF}{obj}->id => 'aa' },
+ { Subject => 'bb', 'CustomField-' . $CF{CF}{obj}->id => 'bb' },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data);
@test = (
{ Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.{$cf_name}" },
{ Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.$queue_name.{$cf_name}" },
@@ -150,7 +118,7 @@ run_tests();
{ Subject => 'b', CF => 'b' },
{ Subject => 'c', CF => 'c' },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data);
@test = (
{ Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" },
{ Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" },
@@ -159,10 +127,10 @@ run_tests();
-diag "create another CF\n" if $ENV{TEST_VERBOSE};
+diag "create another CF";
{
$CF{'AnotherCF'}{'name'} = "OrderAnother$$";
- $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( $RT::SystemUser );
+ $CF{'AnotherCF'}{'obj'} = RT::CustomField->new( RT->SystemUser );
my ($ret, $msg) = $CF{'AnotherCF'}{'obj'}->Create(
Name => $CF{'AnotherCF'}{'name'},
Queue => $queue->id,
@@ -178,7 +146,7 @@ diag "create another CF\n" if $ENV{TEST_VERBOSE};
{ Subject => 'b', CF => 'b', AnotherCF => 'ya' },
{ Subject => 'c', CF => 'c', AnotherCF => 'xa' },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $queue->id, RandomOrder => 1 }, @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
@@ -187,5 +155,5 @@ diag "create another CF\n" if $ENV{TEST_VERBOSE};
);
run_tests();
-
+@tickets = ();
diff --git a/rt/t/ticket/deferred_owner.t b/rt/t/ticket/deferred_owner.t
index 40172caf9..fe90d539d 100644
--- a/rt/t/ticket/deferred_owner.t
+++ b/rt/t/ticket/deferred_owner.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use RT::Test tests => 18;
+use RT::Test nodata => 1, tests => 18;
use_ok('RT');
use_ok('RT::Ticket');
use Test::Warn;
@@ -16,11 +16,11 @@ ok $tester && $tester->id, 'loaded or created user';
my $queue = RT::Test->load_or_create_queue( Name => 'General' );
ok $queue && $queue->id, 'loaded or created queue';
-my $owner_role_group = RT::Group->new( $RT::SystemUser );
+my $owner_role_group = RT::Group->new( RT->SystemUser );
$owner_role_group->LoadQueueRoleGroup( Type => 'Owner', Queue => $queue->id );
ok $owner_role_group->id, 'loaded owners role group of the queue';
-diag "check that deffering owner doesn't regress" if $ENV{'TEST_VERBOSE'};
+diag "check that deffering owner doesn't regress";
{
RT::Test->set_rights(
{ Principal => $tester->PrincipalObj,
@@ -39,14 +39,13 @@ diag "check that deffering owner doesn't regress" if $ENV{'TEST_VERBOSE'};
Owner => $tester->id,
AdminCc => 'root@localhost',
);
- diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+ diag $msg if $msg;
ok $tid, "created a ticket";
is $ticket->Owner, $tester->id, 'correct owner';
like $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there';
}
-diag "check that previous trick doesn't work without sufficient rights"
- if $ENV{'TEST_VERBOSE'};
+diag "check that previous trick doesn't work without sufficient rights";
{
RT::Test->set_rights(
{ Principal => $tester->PrincipalObj,
@@ -61,13 +60,13 @@ diag "check that previous trick doesn't work without sufficient rights"
Owner => $tester->id,
AdminCc => 'root@localhost',
);
- diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+ diag $msg if $msg;
ok $tid, "created a ticket";
is $ticket->Owner, $tester->id, 'correct owner';
unlike $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there';
}
-diag "check that deffering owner really works" if $ENV{'TEST_VERBOSE'};
+diag "check that deffering owner really works";
{
RT::Test->set_rights(
{ Principal => $tester->PrincipalObj,
@@ -85,13 +84,13 @@ diag "check that deffering owner really works" if $ENV{'TEST_VERBOSE'};
Owner => $tester->id,
Cc => 'tester@localhost',
);
- diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+ diag $msg if $msg;
ok $tid, "created a ticket";
like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
is $ticket->Owner, $tester->id, 'tester is also owner';
}
-diag "check that deffering doesn't work without correct rights" if $ENV{'TEST_VERBOSE'};
+diag "check that deffering doesn't work without correct rights";
{
RT::Test->set_rights(
{ Principal => $tester->PrincipalObj,
@@ -110,7 +109,7 @@ diag "check that deffering doesn't work without correct rights" if $ENV{'TEST_VE
);
} qr/User .* was proposed as a ticket owner but has no rights to own tickets in General/;
- diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+ diag $msg if $msg;
ok $tid, "created a ticket";
like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
isnt $ticket->Owner, $tester->id, 'tester is also owner';
diff --git a/rt/t/ticket/link_search.t b/rt/t/ticket/link_search.t
index 1bf7dc6dc..dbcf4b477 100644
--- a/rt/t/ticket/link_search.t
+++ b/rt/t/ticket/link_search.t
@@ -10,19 +10,19 @@ use RT::Test tests => 63;
#Get the current user all loaded
-my $CurrentUser = $RT::SystemUser;
+my $CurrentUser = RT->SystemUser;
-my $queue = new RT::Queue($CurrentUser);
+my $queue = RT::Queue->new($CurrentUser);
$queue->Load('General') || Abort(loc("Queue could not be loaded."));
-my $child_ticket = new RT::Ticket( $CurrentUser );
+my $child_ticket = RT::Ticket->new( $CurrentUser );
my ($childid) = $child_ticket->Create(
Subject => 'test child',
Queue => $queue->Id,
);
ok($childid, "We created a child ticket");
-my $parent_ticket = new RT::Ticket( $CurrentUser );
+my $parent_ticket = RT::Ticket->new( $CurrentUser );
my ($parentid) = $parent_ticket->Create(
Subject => 'test parent',
Children => [ $childid ],
@@ -155,7 +155,7 @@ while (my $t = $Collection->Next) {
ok( $has{$parentid}, "The collection has our parent - $parentid");
ok( !$has{$childid}, "The collection doesn't have our child - $childid");
-my $grand_child_ticket = new RT::Ticket( $CurrentUser );
+my $grand_child_ticket = RT::Ticket->new( $CurrentUser );
my ($grand_childid) = $child_ticket->Create(
Subject => 'test child',
Queue => $queue->Id,
@@ -163,7 +163,7 @@ my ($grand_childid) = $child_ticket->Create(
);
ok($childid, "We created a grand child ticket");
-my $unlinked_ticket = new RT::Ticket( $CurrentUser );
+my $unlinked_ticket = RT::Ticket->new( $CurrentUser );
my ($unlinked_id) = $child_ticket->Create(
Subject => 'test unlinked',
Queue => $queue->Id,
@@ -242,5 +242,3 @@ ok( $has{$parentid}, "The collection has our parent");
ok( $has{$grand_childid}, "The collection have our child");
ok( !$has{$unlinked_id}, "unlinked is not in collection");
-
-1;
diff --git a/rt/t/ticket/linking.t b/rt/t/ticket/linking.t
index fc4761d47..1bd83d633 100644
--- a/rt/t/ticket/linking.t
+++ b/rt/t/ticket/linking.t
@@ -2,7 +2,8 @@
use strict;
use warnings;
-use RT::Test tests => '101';
+use RT::Test tests => 102;
+use Test::Warn;
use_ok('RT');
use_ok('RT::Ticket');
use_ok('RT::ScripConditions');
@@ -12,35 +13,36 @@ use_ok('RT::Scrips');
use_ok('RT::Scrip');
-use File::Temp qw/tempfile/;
-my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
+my $filename = File::Spec->catfile( RT::Test->temp_directory, 'link_count' );
+open my $fh, '>', $filename or die $!;
+close $fh;
+
my $link_scrips_orig = RT->Config->Get( 'LinkTransactionsRun1Scrip' );
RT->Config->Set( 'LinkTransactionsRun1Scrip', 1 );
my $link_acl_checks_orig = RT->Config->Get( 'StrictLinkACL' );
RT->Config->Set( 'StrictLinkACL', 1);
-my $condition = RT::ScripCondition->new( $RT::SystemUser );
+my $condition = RT::ScripCondition->new( RT->SystemUser );
$condition->Load('User Defined');
ok($condition->id);
-my $action = RT::ScripAction->new( $RT::SystemUser );
+my $action = RT::ScripAction->new( RT->SystemUser );
$action->Load('User Defined');
ok($action->id);
-my $template = RT::Template->new( $RT::SystemUser );
+my $template = RT::Template->new( RT->SystemUser );
$template->Load('Blank');
ok($template->id);
-my $q1 = RT::Queue->new($RT::SystemUser);
+my $q1 = RT::Queue->new(RT->SystemUser);
my ($id,$msg) = $q1->Create(Name => "LinkTest1.$$");
ok ($id,$msg);
-my $q2 = RT::Queue->new($RT::SystemUser);
+my $q2 = RT::Queue->new(RT->SystemUser);
($id,$msg) = $q2->Create(Name => "LinkTest2.$$");
ok ($id,$msg);
my $commit_code = <<END;
open( my \$file, '<', "$filename" ) or die "couldn't open $filename";
my \$data = <\$file>;
-chomp \$data;
\$data += 0;
close \$file;
\$RT::Logger->debug("Data is \$data");
@@ -62,14 +64,14 @@ close \$file;
1;
END
-my $Scrips = RT::Scrips->new( $RT::SystemUser );
+my $Scrips = RT::Scrips->new( RT->SystemUser );
$Scrips->UnLimit;
while ( my $Scrip = $Scrips->Next ) {
$Scrip->Delete if $Scrip->Description and $Scrip->Description =~ /Add or Delete Link \d+/;
}
-my $scrip = RT::Scrip->new($RT::SystemUser);
+my $scrip = RT::Scrip->new(RT->SystemUser);
($id,$msg) = $scrip->Create( Description => "Add or Delete Link $$",
ScripCondition => $condition->id,
ScripAction => $action->id,
@@ -82,7 +84,7 @@ my $scrip = RT::Scrip->new($RT::SystemUser);
);
ok($id, "Scrip created");
-my $u1 = RT::User->new($RT::SystemUser);
+my $u1 = RT::User->new(RT->SystemUser);
($id,$msg) = $u1->Create(Name => "LinkTestUser.$$");
ok ($id,$msg);
@@ -96,31 +98,31 @@ ok ($id,$msg);
my $creator = RT::CurrentUser->new($u1->id);
-diag('Create tickets without rights to link') if $ENV{'TEST_VERBOSE'};
+diag('Create tickets without rights to link');
{
# on q2 we have no rights, yet
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
-diag('Create tickets with rights checks on one end of a link') if $ENV{'TEST_VERBOSE'};
+diag('Create tickets with rights checks on one end of a link');
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
# no scrip run on second ticket accroding to config option
@@ -131,10 +133,10 @@ diag('Create tickets with rights checks on one end of a link') if $ENV{'TEST_VER
($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket');
ok ($id,$msg);
-diag('try to add link without rights') if $ENV{'TEST_VERBOSE'};
+diag('try to add link without rights');
{
# on q2 we have no rights, yet
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
@@ -143,16 +145,16 @@ diag('try to add link without rights') if $ENV{'TEST_VERBOSE'};
($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id);
ok(!$id, $msg);
is(link_count($filename), undef, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
-diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'};
+diag('add link with rights only on base');
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
@@ -161,7 +163,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'};
($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id);
ok($id, $msg);
is(link_count($filename), 1, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
$child->CurrentUser( $creator );
@@ -171,7 +173,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'};
($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id);
ok(!$id, $msg);
is(link_count($filename), 1, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 1, 'link was not deleted');
$child->CurrentUser( $creator );
@@ -181,7 +183,7 @@ diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'};
($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id);
ok($id, $msg);
is(link_count($filename), 0, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ $child->CurrentUser( RT->SystemUser );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 0, 'link was deleted');
RT->Config->Set( StrictLinkACL => 1 );
@@ -193,14 +195,16 @@ ok($ticket->isa('RT::Ticket'));
($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id);
ok ($id,$msg);
-diag('try link to itself') if $ENV{'TEST_VERBOSE'};
+diag('try link to itself');
{
- my ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+ warning_like {
+ ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+ } qr/Can't link a ticket to itself/;
ok(!$id, $msg);
is(link_count($filename), 0, "scrips ok");
}
-my $ticket2 = RT::Ticket->new($RT::SystemUser);
+my $ticket2 = RT::Ticket->new(RT->SystemUser);
($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id);
ok ($id, $msg);
($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
@@ -214,8 +218,14 @@ ok ($id,$msg);
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
is(link_count($filename), 1, "scrips ok");
-($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1);
-ok(!$id,$msg);
+
+warnings_like {
+ ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1);
+} [
+ qr/Could not determine a URI scheme for -1/,
+ qr/Couldn't resolve '-1' into a URI/,
+];
+
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
is(link_count($filename), 1, "scrips ok");
@@ -301,13 +311,13 @@ RT->Config->Set( LinkTransactionsRun1Scrip => $link_scrips_orig );
RT->Config->Set( StrictLinkACL => $link_acl_checks_orig );
{
- my $Scrips = RT::Scrips->new( $RT::SystemUser );
+ my $Scrips = RT::Scrips->new( RT->SystemUser );
$Scrips->Limit( FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Add or Delete Link ');
while ( my $s = $Scrips->Next ) { $s->Delete };
}
-my $link = RT::Link->new( $RT::SystemUser );
+my $link = RT::Link->new( RT->SystemUser );
($id,$msg) = $link->Create( Base => $ticket->URI, Target => $ticket2->URI, Type => 'MyLinkType' );
ok($id, $msg);
ok($link->LocalBase == $ticket->id, "LocalBase set correctly");
@@ -375,7 +385,7 @@ ok($link->LocalBase == 0, "LocalBase set correctly");
sub link_count {
my $file = shift;
- open ( my $fh, '<', $file ) or die "couldn't open $file";
+ open( my $fh, '<', $file ) or die "couldn't open $file";
my $data = <$fh>;
close $fh;
diff --git a/rt/t/ticket/merge.t b/rt/t/ticket/merge.t
index 7c72fe08f..d06d54174 100644
--- a/rt/t/ticket/merge.t
+++ b/rt/t/ticket/merge.t
@@ -11,11 +11,11 @@ use RT::Test tests => '29';
# validate that when merging two tickets, the comments from both tickets
# are integrated into the new ticket
{
- my $queue = RT::Queue->new($RT::SystemUser);
+ my $queue = RT::Queue->new(RT->SystemUser);
my ($id,$msg) = $queue->Create(Name => 'MergeTest-'.rand(25));
ok ($id,$msg);
- my $t1 = RT::Ticket->new($RT::SystemUser);
+ my $t1 = RT::Ticket->new(RT->SystemUser);
my ($tid,$transid, $t1msg) =$t1->Create(
Queue => $queue->Name,
Subject => 'Merge test. orig',
@@ -31,7 +31,7 @@ use RT::Test tests => '29';
}
is($Comments,1, "our first ticket has only one Comment");
- my $t2 = RT::Ticket->new($RT::SystemUser);
+ my $t2 = RT::Ticket->new(RT->SystemUser);
my ($t2id,$t2transid, $t2msg) =$t2->Create ( Queue => $queue->Name, Subject => 'Merge test. duplicate');
ok ($t2id, $t2msg);
@@ -71,15 +71,15 @@ use RT::Test tests => '29';
# when you try to merge duplicate links on postgres, eveyrything goes to hell due to referential integrity constraints.
{
- my $t = RT::Ticket->new($RT::SystemUser);
+ my $t = RT::Ticket->new(RT->SystemUser);
$t->Create(Subject => 'Main', Queue => 'general');
ok ($t->id);
- my $t2 = RT::Ticket->new($RT::SystemUser);
+ my $t2 = RT::Ticket->new(RT->SystemUser);
$t2->Create(Subject => 'Second', Queue => 'general');
ok ($t2->id);
- my $t3 = RT::Ticket->new($RT::SystemUser);
+ my $t3 = RT::Ticket->new(RT->SystemUser);
$t3->Create(Subject => 'Third', Queue => 'general');
ok ($t3->id);
diff --git a/rt/t/ticket/quicksearch.t b/rt/t/ticket/quicksearch.t
deleted file mode 100644
index 9ab9f21e4..000000000
--- a/rt/t/ticket/quicksearch.t
+++ /dev/null
@@ -1,41 +0,0 @@
-
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;
-
-use RT::Test tests => 10;
-use_ok('RT');
-
-
-my $q = RT::Queue->new($RT::SystemUser);
-my $queue = 'SearchTests-'.$$;
-$q->Create(Name => $queue);
-ok ($q->id, "Created the queue");
-
-my $t1 = RT::Ticket->new($RT::SystemUser);
-my ( $id, undef, $msg ) = $t1->Create(
- Queue => $q->id,
- Subject => 'SearchTest1',
- Requestor => ['search2@example.com'],
-);
-ok( $id, $msg );
-
-use_ok("RT::Search::Googleish");
-
-my $active_statuses = join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray());
-
-my $tickets = RT::Tickets->new($RT::SystemUser);
-my $quick = RT::Search::Googleish->new(Argument => "",
- TicketsObj => $tickets);
-my @tests = (
- "General new open root" => "( Owner = 'root' ) AND ( Queue = 'General' ) AND ( Status = 'new' OR Status = 'open' )",
- "fulltext:jesse" => "( Content LIKE 'jesse' ) AND ( $active_statuses )",
- $queue => "( Queue = '$queue' ) AND ( $active_statuses )",
- "root $queue" => "( Owner = 'root' ) AND ( Queue = '$queue' ) AND ( $active_statuses )",
- "notauser $queue" => "( Queue = '$queue' ) AND ( $active_statuses ) AND ( Subject LIKE 'notauser' )",
- "notauser $queue root" => "( Owner = 'root' ) AND ( Queue = '$queue' ) AND ( $active_statuses ) AND ( Subject LIKE 'notauser' )");
-
-while (my ($from, $to) = splice @tests, 0, 2) {
- is($quick->QueryToSQL($from), $to, "<$from> -> <$to>");
-}
diff --git a/rt/t/ticket/requestor-order.t b/rt/t/ticket/requestor-order.t
index 4539fbdc6..bdacc460e 100644
--- a/rt/t/ticket/requestor-order.t
+++ b/rt/t/ticket/requestor-order.t
@@ -6,7 +6,7 @@ use_ok('RT');
use RT::Ticket;
-my $q = RT::Queue->new($RT::SystemUser);
+my $q = RT::Queue->new(RT->SystemUser);
my $queue = 'SearchTests-'.rand(200);
$q->Create(Name => $queue);
@@ -15,7 +15,7 @@ my @requestors = ( ('bravo@example.com') x 6, ('alpha@example.com') x 6,
(undef) x 6);
my @subjects = ("first test", "second test", "third test", "fourth test", "fifth test") x 6;
while (@requestors) {
- my $t = RT::Ticket->new($RT::SystemUser);
+ my $t = RT::Ticket->new(RT->SystemUser);
my ( $id, undef $msg ) = $t->Create(
Queue => $q->id,
Subject => shift @subjects,
@@ -25,13 +25,13 @@ while (@requestors) {
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
is($tix->Count, 30, "found thirty tickets");
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND requestor = 'alpha\@example.com'");
$tix->OrderByCols({ FIELD => "Subject" });
my @subjects;
@@ -60,7 +60,7 @@ sub check_emails_order
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND subject = 'first test' AND Requestor.EmailAddress LIKE 'example.com'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
check_emails_order($tix, 5, 'ASC');
@@ -69,7 +69,7 @@ sub check_emails_order
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = 'first test'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
check_emails_order($tix, 6, 'ASC');
@@ -79,7 +79,7 @@ sub check_emails_order
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = 'first test'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
check_emails_order($tix, 6, 'ASC');
@@ -89,7 +89,7 @@ sub check_emails_order
{
# create ticket with group as member of the requestors group
- my $t = RT::Ticket->new($RT::SystemUser);
+ my $t = RT::Ticket->new(RT->SystemUser);
my ( $id, $msg ) = $t->Create(
Queue => $q->id,
Subject => "first test",
@@ -97,7 +97,7 @@ sub check_emails_order
);
ok( $id, "ticket created" ) or diag( "error: $msg" );
- my $g = RT::Group->new($RT::SystemUser);
+ my $g = RT::Group->new(RT->SystemUser);
my ($gid);
($gid, $msg) = $g->CreateUserDefinedGroup(Name => '20-sort-by-requestor.t-'.rand(200));
@@ -107,7 +107,7 @@ sub check_emails_order
ok($id, "added group to requestors group") or diag("error: $msg");
}
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = 'first test'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
@@ -117,7 +117,7 @@ sub check_emails_order
check_emails_order($tix, 7, 'DESC');
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
$tix->RowsPerPage(30);
@@ -128,7 +128,7 @@ sub check_emails_order
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
$tix->OrderByCols({ FIELD => "Requestor.EmailAddress" });
$tix->RowsPerPage(30);
@@ -138,5 +138,3 @@ sub check_emails_order
is_deeply( [grep {$_} @mails], [ sort grep {$_} @mails ], "Paging works (exclude nulls, which are db-dependant)");
}
RT::Test->mailsent_ok(25);
-
-# vim:ft=perl:
diff --git a/rt/t/ticket/scrips_batch.t b/rt/t/ticket/scrips_batch.t
index f13881b65..44d7f8e34 100644
--- a/rt/t/ticket/scrips_batch.t
+++ b/rt/t/ticket/scrips_batch.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use RT::Test tests => '19';
+use RT::Test tests => 19;
use_ok('RT');
use_ok('RT::Ticket');
@@ -16,12 +16,10 @@ ok $m->login, 'logged in as root';
my $sid;
{
- $m->follow_link_ok( { text => 'Configuration' } );
- $m->follow_link_ok( { text => 'Queues' } );
+ $m->follow_link_ok( { id => 'tools-config-queues' } );
$m->follow_link_ok( { text => $queue->Name } );
- $m->follow_link_ok( { text => 'Scrips' } );
- $m->follow_link_ok( { text => 'New scrip' } );
- $m->form_number(3);
+ $m->follow_link_ok( { id => 'page-scrips-create'});
+ $m->form_name('ModifyScrip');
$m->field('Scrip-new-Description' => 'test');
$m->select('Scrip-new-ScripCondition' => 'On Transaction');
$m->select('Scrip-new-ScripAction' => 'User Defined');
@@ -30,19 +28,19 @@ my $sid;
$m->field('Scrip-new-CustomPrepareCode' => 'return 1;');
$m->field('Scrip-new-CustomCommitCode' => 'return 1;');
$m->submit;
- $m->content_like( qr/Scrip Created/ );
+ $m->content_contains("Scrip Created");
- ($sid) = ($m->content =~ /Scrip\s*#(\d+)/);
- my $form = $m->form_number(3);
+ my $form = $m->form_name('ModifyScrip');
+ $sid = $form->value('id');
is $m->value("Scrip-$sid-Description"), 'test', 'correct description';
is value_name($form, "Scrip-$sid-ScripCondition"), 'On Transaction', 'correct condition';
is value_name($form, "Scrip-$sid-ScripAction"), 'User Defined', 'correct action';
is value_name($form, "Scrip-$sid-Template"), 'Global template: Blank', 'correct template';
is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage';
- use File::Temp qw(tempfile);
- my ($tmp_fh, $tmp_fn) = tempfile();
+ my $tmp_fn = File::Spec->catfile( RT::Test->temp_directory, 'transactions' );
+ open my $tmp_fh, '+>', $tmp_fn or die $!;
my $code = <<END;
open( my \$fh, '>', '$tmp_fn' ) or die "Couldn't open '$tmp_fn':\$!";
@@ -62,13 +60,13 @@ END
$m->submit;
$m->goto_create_ticket( $queue );
- $m->form_number(3);
+ $m->form_name('TicketCreate');
$m->submit;
is_deeply parse_handle($tmp_fh), ['Create'], 'Create';
$m->follow_link_ok( { text => 'Resolve' } );
- $m->form_number(3);
+ $m->form_name('TicketUpdate');
$m->field( "UpdateContent" => 'resolve it' );
$m->click('SubmitTicket');
diff --git a/rt/t/ticket/search.t b/rt/t/ticket/search.t
index 9cec4f753..fd0a7e08f 100644
--- a/rt/t/ticket/search.t
+++ b/rt/t/ticket/search.t
@@ -6,11 +6,11 @@
use strict;
use warnings;
-use RT::Test tests => 43;
+use RT::Test nodata => 1, tests => 43;
# setup the queue
-my $q = RT::Queue->new($RT::SystemUser);
+my $q = RT::Queue->new(RT->SystemUser);
my $queue = 'SearchTests-'.$$;
$q->Create(Name => $queue);
ok ($q->id, "Created the queue");
@@ -19,17 +19,17 @@ ok ($q->id, "Created the queue");
# and setup the CFs
# we believe the Type shouldn't matter.
-my $cf = RT::CustomField->new($RT::SystemUser);
+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;
-my $cf2 = RT::CustomField->new($RT::SystemUser);
+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);
+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;
@@ -39,16 +39,16 @@ my $cflabel3 = "CustomField-".$cf3->id;
# caused spurious results on negative searches if another custom field
# with the same name existed on a different queue. Hence, we make
# duplicate CFs on a different queue here
-my $dup = RT::Queue->new($RT::SystemUser);
+my $dup = RT::Queue->new(RT->SystemUser);
$dup->Create(Name => $queue . "-Copy");
ok ($dup->id, "Created the duplicate queue");
-my $dupcf = RT::CustomField->new($RT::SystemUser);
+my $dupcf = RT::CustomField->new(RT->SystemUser);
$dupcf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $dup->id);
ok($dupcf->id, "Created the duplicate SearchTest CF");
-$dupcf = RT::CustomField->new($RT::SystemUser);
+$dupcf = RT::CustomField->new(RT->SystemUser);
$dupcf->Create(Name => 'SearchTest2', Type => 'Freeform', MaxValues => 0, Queue => $dup->id);
ok($dupcf->id, "Created the SearchTest2 CF");
-$dupcf = RT::CustomField->new($RT::SystemUser);
+$dupcf = RT::CustomField->new(RT->SystemUser);
$dupcf->Create(Name => 'SearchTest3', Type => 'Freeform', MaxValues => 0, Queue => $dup->id);
ok($dupcf->id, "Created the SearchTest3 CF");
@@ -58,7 +58,7 @@ ok($dupcf->id, "Created the SearchTest3 CF");
# there's probably a way to think harder and do this with fewer
-my $t1 = RT::Ticket->new($RT::SystemUser);
+my $t1 = RT::Ticket->new(RT->SystemUser);
my ( $id, undef $msg ) = $t1->Create(
Queue => $q->id,
Subject => 'SearchTest1',
@@ -70,7 +70,7 @@ my ( $id, undef $msg ) = $t1->Create(
ok( $id, $msg );
-my $t2 = RT::Ticket->new($RT::SystemUser);
+my $t2 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t2->Create(
Queue => $q->id,
Subject => 'SearchTest2',
@@ -81,7 +81,7 @@ my $t2 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t3 = RT::Ticket->new($RT::SystemUser);
+my $t3 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t3->Create(
Queue => $q->id,
Subject => 'SearchTest3',
@@ -92,7 +92,7 @@ my $t3 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t4 = RT::Ticket->new($RT::SystemUser);
+my $t4 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t4->Create(
Queue => $q->id,
Subject => 'SearchTest4',
@@ -103,7 +103,7 @@ my $t4 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t5 = RT::Ticket->new($RT::SystemUser);
+my $t5 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t5->Create(
Queue => $q->id,
# Subject => 'SearchTest5',
@@ -114,7 +114,7 @@ my $t5 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t6 = RT::Ticket->new($RT::SystemUser);
+my $t6 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t6->Create(
Queue => $q->id,
Subject => 'SearchTest6',
@@ -125,7 +125,7 @@ my $t6 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t7 = RT::Ticket->new($RT::SystemUser);
+my $t7 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t7->Create(
Queue => $q->id,
Subject => 'SearchTest7',
@@ -137,7 +137,7 @@ my $t7 = RT::Ticket->new($RT::SystemUser);
ok( $id, $msg );
# we have tickets. start searching
-my $tix = RT::Tickets->new($RT::SystemUser);
+my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
is($tix->Count, 7, "found all the tickets")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
@@ -145,73 +145,73 @@ is($tix->Count, 7, "found all the tickets")
# very simple searches. both CF and normal
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo1'");
is($tix->Count, 1, "matched identical subject")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo1'");
is($tix->Count, 1, "matched LIKE subject")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo'");
is($tix->Count, 0, "IS a regexp match")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
is($tix->Count, 5, "matched LIKE subject")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
is($tix->Count, 2, "IS null CF")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'");
is($tix->Count, 1, "LIKE requestor")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors = 'search1\@example.com'");
is($tix->Count, 1, "IS requestor")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'");
is($tix->Count, 6, "LIKE requestor")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Requestors IS NULL");
is($tix->Count, 1, "Search for no requestor")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'");
is($tix->Count, 1, "IS subject")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest1'");
is($tix->Count, 1, "LIKE subject")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject = ''");
is($tix->Count, 1, "found one ticket")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'SearchTest'");
is($tix->Count, 6, "found two ticket")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Subject LIKE 'qwerty'");
is($tix->Count, 0, "found zero ticket")
or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
@@ -221,58 +221,58 @@ is($tix->Count, 0, "found zero ticket")
# various combinations
-$tix = RT::Tickets->new($RT::SystemUser);
+$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 = 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 = 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 = 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 = 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 = 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 = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar2'");
is($tix->Count, 1, "null cf and is cf");
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL");
is($tix->Count, 1, "null cf and null cf");
# tests with the same CF listed twice
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("CF.{SearchTest} = 'foo1'");
is($tix->Count, 1, "is cf.{name} format");
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3'");
is($tix->Count, 2, "is cf1 or is cf1");
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest IS NULL");
is($tix->Count, 3, "is cf1 or null cf1");
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("(CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3') AND (CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2')");
is($tix->Count, 1, "(is cf1 or is cf1) and (is cf2 or is cf2)");
-$tix = RT::Tickets->new($RT::SystemUser);
+$tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3' OR CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2'");
is($tix->Count, 3, "is cf1 or is cf1 or is cf2 or is cf2");
diff --git a/rt/t/ticket/search_by_cf_freeform_multiple.t b/rt/t/ticket/search_by_cf_freeform_multiple.t
index be5130651..4e7cddc06 100644
--- a/rt/t/ticket/search_by_cf_freeform_multiple.t
+++ b/rt/t/ticket/search_by_cf_freeform_multiple.t
@@ -3,17 +3,17 @@
use strict;
use warnings;
-use RT::Test tests => 105;
+use RT::Test nodata => 1, tests => 118;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $q && $q->id, 'loaded or created queue';
my $queue = $q->Name;
-diag "create a CF\n" if $ENV{TEST_VERBOSE};
+diag "create a CF";
my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
{
- $cf = RT::CustomField->new( $RT::SystemUser );
+ $cf = RT::CustomField->new( RT->SystemUser );
my ($ret, $msg) = $cf->Create(
Name => $cf_name,
Queue => $q->id,
@@ -25,38 +25,10 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
my ($total, @data, @tickets, %test) = (0, ());
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my %args = %{ shift(@data) };
- my @cf_value = $args{'Subject'} ne '-'? (split /(?=.)/, $args{'Subject'}) : ();
- diag "vals: ". join ', ', @cf_value;
- my $t = RT::Ticket->new($RT::SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %args,
- "CustomField-$cf_id" => \@cf_value,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
-
- my $got = join ',', sort do {
- my $vals = $t->CustomFieldValues( $cf_name );
- my @tmp;
- while (my $v = $vals->Next ) { push @tmp, $v->Content }
- @tmp;
- };
-
- is( $got, join( ',', sort @cf_value), 'correct CF values' );
- push @res, $t;
- $total++;
- }
- return @res;
-}
-
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
foreach my $key ( sort keys %test ) {
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL( "( $query_prefix ) AND ( $key )" );
my $error = 0;
@@ -79,12 +51,12 @@ sub run_tests {
@data = (
{ Subject => '-' },
- { Subject => 'x' },
- { Subject => 'y' },
- { Subject => 'z' },
- { Subject => 'xy' },
- { Subject => 'xz' },
- { Subject => 'yz' },
+ { Subject => 'x', "CustomField-$cf_id" => 'x', },
+ { Subject => 'y', "CustomField-$cf_id" => 'y', },
+ { Subject => 'z', "CustomField-$cf_id" => 'z', },
+ { Subject => 'xy', "CustomField-$cf_id" => [ 'x', 'y' ], },
+ { Subject => 'xz', "CustomField-$cf_id" => [ 'x', 'z' ], },
+ { Subject => 'yz', "CustomField-$cf_id" => [ 'y', 'z' ], },
);
%test = (
"CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 },
@@ -142,12 +114,13 @@ sub run_tests {
"'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 },
"'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data);
+$total = scalar @tickets;
+
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
is($tix->Count, $total, "found $total tickets");
}
run_tests();
-exit 0;
diff --git a/rt/t/ticket/search_by_cf_freeform_single.t b/rt/t/ticket/search_by_cf_freeform_single.t
index d5ff7ec0d..278a3ce03 100644
--- a/rt/t/ticket/search_by_cf_freeform_single.t
+++ b/rt/t/ticket/search_by_cf_freeform_single.t
@@ -3,17 +3,17 @@
use strict;
use warnings;
-use RT::Test tests => 99;
+use RT::Test nodata => 1, tests => 106;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $q && $q->id, 'loaded or created queue';
my $queue = $q->Name;
-diag "create a CF\n" if $ENV{TEST_VERBOSE};
+diag "create a CF";
my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
{
- $cf = RT::CustomField->new( $RT::SystemUser );
+ $cf = RT::CustomField->new( RT->SystemUser );
my ($ret, $msg) = $cf->Create(
Name => $cf_name,
Queue => $q->id,
@@ -25,29 +25,10 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
my ($total, @data, @tickets, %test) = (0, ());
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my %args = %{ shift(@data) };
- my $cf_value = $args{'Subject'} ne '-'? $args{'Subject'} : undef;
- my $t = RT::Ticket->new($RT::SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %args,
- "CustomField-$cf_id" => $cf_value,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- is( $t->FirstCustomFieldValue( $cf_name ), $cf_value, 'correct value' );
- push @res, $t;
- $total++;
- }
- return @res;
-}
-
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
foreach my $key ( sort keys %test ) {
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL( "( $query_prefix ) AND ( $key )" );
my $error = 0;
@@ -70,9 +51,9 @@ sub run_tests {
@data = (
{ Subject => '-' },
- { Subject => 'x' },
- { Subject => 'y' },
- { Subject => 'z' },
+ { Subject => 'x', "CustomField-$cf_id" => 'x', },
+ { Subject => 'y', "CustomField-$cf_id" => 'y', },
+ { Subject => 'z', "CustomField-$cf_id" => 'z', },
);
%test = (
"CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 },
@@ -131,12 +112,14 @@ sub run_tests {
"'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $q->id }, @data);
+$total = scalar @tickets;
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
is($tix->Count, $total, "found $total tickets");
}
run_tests();
-exit 0;
+@tickets = ();
+
diff --git a/rt/t/ticket/search_by_links.t b/rt/t/ticket/search_by_links.t
index a8e955c8b..61b69b73e 100644
--- a/rt/t/ticket/search_by_links.t
+++ b/rt/t/ticket/search_by_links.t
@@ -3,35 +3,18 @@
use strict;
use warnings;
-use RT::Test tests => 80;
+use RT::Test nodata => 1, tests => 98;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $q && $q->id, 'loaded or created queue';
-my ($total, @data, @tickets, %test) = (0, ());
-
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my $t = RT::Ticket->new($RT::SystemUser);
- my %args = %{ shift(@data) };
- $args{$_} = $res[ $args{$_} ]->id foreach grep $args{$_}, keys %RT::Ticket::LINKTYPEMAP;
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %args,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- push @res, $t;
- $total++;
- }
- return @res;
-}
+my ($total, @tickets, %test) = (0, ());
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
foreach my $key ( sort keys %test ) {
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL( "( $query_prefix ) AND ( $key )" );
my $error = 0;
@@ -53,12 +36,13 @@ sub run_tests {
}
# simple set with "no links", "parent and child"
-@data = (
+@tickets = RT::Test->create_tickets(
+ { Queue => $q->id },
{ Subject => '-', },
{ Subject => 'p', },
{ Subject => 'c', MemberOf => -1 },
);
-@tickets = add_tix_from_data();
+$total += @tickets;
%test = (
'Linked IS NOT NULL' => { '-' => 0, c => 1, p => 1 },
'Linked IS NULL' => { '-' => 1, c => 0, p => 0 },
@@ -82,14 +66,15 @@ sub run_tests {
'MemberOf != '. $tickets[1]->id => { '-' => 1, c => 0, p => 1 },
);
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '". $q->id ."'");
is($tix->Count, $total, "found $total tickets");
}
run_tests();
# another set with tests of combinations searches
-@data = (
+@tickets = RT::Test->create_tickets(
+ { Queue => $q->id },
{ Subject => '-', },
{ Subject => 'p', },
{ Subject => 'rp', RefersTo => -1 },
@@ -97,7 +82,7 @@ run_tests();
{ Subject => 'rc1', RefersTo => -1 },
{ Subject => 'rc2', RefersTo => -2 },
);
-@tickets = add_tix_from_data();
+$total += @tickets;
my $pid = $tickets[1]->id;
%test = (
'RefersTo IS NOT NULL' => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
@@ -124,9 +109,11 @@ my $pid = $tickets[1]->id;
"RefersTo != $pid OR MemberOf != $pid" => { '-' => 1, c => 1, p => 1, rp => 1, rc1 => 1, rc2 => 1 },
);
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '". $q->id ."'");
is($tix->Count, $total, "found $total tickets");
}
run_tests();
+@tickets = ();
+
diff --git a/rt/t/ticket/search_by_txn.t b/rt/t/ticket/search_by_txn.t
index 1be6916ef..0e5f76dcd 100644
--- a/rt/t/ticket/search_by_txn.t
+++ b/rt/t/ticket/search_by_txn.t
@@ -11,13 +11,13 @@ use RT::Test tests => 10;
my $SUBJECT = "Search test - ".$$;
use_ok('RT::Tickets');
-my $tix = RT::Tickets->new($RT::SystemUser);
+my $tix = RT::Tickets->new(RT->SystemUser);
can_ok($tix, 'FromSQL');
$tix->FromSQL('Updated = "2005-08-05" AND Subject = "$SUBJECT"');
ok(! $tix->Count, "Searching for tickets updated on a random date finds nothing" . $tix->Count);
-my $ticket = RT::Ticket->new($RT::SystemUser);
+my $ticket = RT::Ticket->new(RT->SystemUser);
$ticket->Create(Queue => 'General', Subject => $SUBJECT);
ok ($ticket->id, "We created a ticket");
my ($id, $txnid, $txnobj) = $ticket->Comment( Content => 'A comment that happend on 2004-01-01');
diff --git a/rt/t/ticket/search_by_watcher.t b/rt/t/ticket/search_by_watcher.t
index 9d94432d2..809450b56 100644
--- a/rt/t/ticket/search_by_watcher.t
+++ b/rt/t/ticket/search_by_watcher.t
@@ -3,224 +3,216 @@
use strict;
use warnings;
-use RT::Test tests => 119;
+use RT::Test nodata => 1, tests => 2108;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $q && $q->id, 'loaded or created queue';
my $queue = $q->Name;
-my ($total, @data, @tickets, %test) = (0, ());
-
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my $t = RT::Ticket->new($RT::SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %{ shift(@data) },
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- push @res, $t;
- $total++;
+my ($total, @tickets, @test, @conditions) = (0, ());
+
+sub generate_tix {
+ my @list = (
+ [],
+ ['x@foo.com'], ['y@bar.com'], ['z@bar.com'],
+ ['x@foo.com', 'y@bar.com'],
+ ['y@bar.com', 'z@bar.com'],
+ ['x@foo.com', 'z@bar.com'],
+ ['x@foo.com', 'y@bar.com', 'z@bar.com'],
+ );
+ my @data = ();
+ foreach my $r (@list) {
+ foreach my $c (@list) {
+ my $subject = 'r:'. (join( '', map substr($_, 0, 1), @$r ) || '-') .';';
+ $subject .= 'c:'. (join( '', map substr($_, 0, 1), @$c ) || '-') .';';
+
+ push @data, {
+ Subject => $subject,
+ Requestor => $r,
+ Cc => $c,
+ };
+ }
}
- return @res;
+ return RT::Test->create_tickets( { Queue => $q->id }, @data );
}
sub run_tests {
- my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
- foreach my $key ( sort keys %test ) {
- my $tix = RT::Tickets->new($RT::SystemUser);
- $tix->FromSQL( "( $query_prefix ) AND ( $key )" );
-
- my $error = 0;
-
- my $count = 0;
- $count++ foreach grep $_, values %{ $test{$key} };
- is($tix->Count, $count, "found correct number of ticket(s) by '$key'") or $error = 1;
-
- my $good_tickets = ($tix->Count == $count);
- while ( my $ticket = $tix->Next ) {
- next if $test{$key}->{ $ticket->Subject };
- diag $ticket->Subject ." ticket has been found when it's not expected";
- $good_tickets = 0;
- }
- ok( $good_tickets, "all tickets are good with '$key'" ) or $error = 1;
-
- diag "Wrong SQL query for '$key':". $tix->BuildSelectQuery if $error;
+ while ( my ($query, $checks) = splice @test, 0, 2 ) {
+ run_test( $query, %$checks );
}
}
-@data = (
- { Subject => 'xy', Requestor => ['x@example.com', 'y@example.com'] },
- { Subject => 'x', Requestor => 'x@example.com' },
- { Subject => 'y', Requestor => 'y@example.com' },
- { Subject => '-', },
- { Subject => 'z', Requestor => 'z@example.com' },
-);
-%test = (
- 'Requestor = "x@example.com"' => { xy => 1, x => 1, y => 0, '-' => 0, z => 0 },
- 'Requestor != "x@example.com"' => { xy => 0, x => 0, y => 1, '-' => 1, z => 1 },
-
- 'Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 0, z => 0 },
- 'Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 1, z => 1 },
+sub run_test {
+ my ($query, %checks) = @_;
- 'Requestor LIKE "@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 },
- 'Requestor NOT LIKE "@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 },
+ my $tix = RT::Tickets->new(RT->SystemUser);
+ $tix->FromSQL($query);
+ my $error = 0;
- 'Requestor IS NULL' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 },
- 'Requestor IS NOT NULL' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 },
+ my $count = 0;
+ $count++ foreach grep $_, values %checks;
+ is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1;
-# this test is a todo, we run it later
-# 'Requestor = "x@example.com" AND Requestor = "y@example.com"' => { xy => 1, x => 0, y => 0, '-' => 0, z => 0 },
- 'Requestor = "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 0 },
-
- 'Requestor != "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 1 },
- 'Requestor != "x@example.com" OR Requestor != "y@example.com"' => { xy => 0, x => 1, y => 1, '-' => 1, z => 1 },
-
- 'Requestor = "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 0, z => 0 },
- 'Requestor = "x@example.com" OR Requestor != "y@example.com"' => { xy => 1, x => 1, y => 0, '-' => 1, z => 1 },
+ my $good_tickets = ($tix->Count == $count);
+ while ( my $ticket = $tix->Next ) {
+ next if $checks{ $ticket->Subject };
+ diag $ticket->Subject ." ticket has been found when it's not expected";
+ $good_tickets = 0;
+ }
+ ok( $good_tickets, "all tickets are good with '$query'" ) or $error = 1;
- 'Requestor != "x@example.com" AND Requestor = "y@example.com"' => { xy => 0, x => 0, y => 1, '-' => 0, z => 0 },
- 'Requestor != "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 1, z => 1 },
-);
-@tickets = add_tix_from_data();
-{
- my $tix = RT::Tickets->new($RT::SystemUser);
- $tix->FromSQL("Queue = '$queue'");
- is($tix->Count, $total, "found $total tickets");
+ diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
}
-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 = (
- 'Requestor = "x@example.com" AND Requestor = "y@example.com"'
- => { xy => 1, x => 0, y => 0, '-' => 0, z => 0 },
- '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 },
+
+sub run_auto_tests {
+ {
+ my @atmp = @conditions;
+ while ( my ($query, $cb) = splice @atmp, 0, 2 ) {
+ my %checks = ();
+ foreach my $ticket ( @tickets ) {
+ my $s = $ticket->Subject;
+ $checks{ $s } = $cb->($s);
+ }
+ run_test($query, %checks);
+ }
+ }
+ my @queries = (
+ '? AND ?' => sub { $_[0] and $_[1] },
+ '? OR ?' => sub { $_[0] or $_[1] },
);
- run_tests();
+ while ( my ($template, $t_cb) = splice @queries, 0, 2 ) {
+ my @atmp = @conditions;
+ while ( my ($a, $a_cb) = splice @atmp, 0, 2 ) {
+ my @btmp = @conditions;
+ while ( my ($b, $b_cb) = splice @btmp, 0, 2 ) {
+ next if $a eq $b;
+
+ my %checks = ();
+ foreach my $ticket ( @tickets ) {
+ my $s = $ticket->Subject;
+ $checks{ $s } = $t_cb->( scalar $a_cb->($s), scalar $b_cb->($s) );
+ }
+
+ my $query = $template;
+ foreach my $tmp ($a, $b) {
+ $query =~ s/\?/$tmp/;
+ }
+
+ run_test( $query, %checks );
+ } }
+ }
+# XXX: It
+# @queries = (
+# '? AND ? AND ?' => sub { $_[0] and $_[1] and $_[2] },
+# '(? OR ?) AND ?' => sub { return (($_[0] or $_[1]) and $_[2]) },
+# '? OR (? AND ?)' => sub { $_[0] or ($_[1] and $_[2]) },
+# '(? AND ?) OR ?' => sub { ($_[0] and $_[1]) or $_[2] },
+# '? AND (? OR ?)' => sub { $_[0] and ($_[1] or $_[2]) },
+# '? OR ? OR ?' => sub { $_[0] or $_[1] or $_[2] },
+# );
+# while ( my ($template, $t_cb) = splice @queries, 0, 2 ) {
+# my @atmp = @conditions;
+# while ( my ($a, $a_cb) = splice @atmp, 0, 2 ) {
+# my @btmp = @conditions;
+# while ( my ($b, $b_cb) = splice @btmp, 0, 2 ) {
+# next if $a eq $b;
+# my @ctmp = @conditions;
+# while ( my ($c, $c_cb) = splice @ctmp, 0, 2 ) {
+# next if $a eq $c;
+# next if $b eq $c;
+#
+# my %checks = ();
+# foreach my $ticket ( @tickets ) {
+# my $s = $ticket->Subject;
+# $checks{ $s } = $t_cb->( scalar $a_cb->($s), scalar $b_cb->($s), scalar $c_cb->($s) );
+# }
+#
+# my $query = $template;
+# foreach my $tmp ($a, $b, $c) {
+# $query =~ s/\?/$tmp/;
+# }
+#
+# run_test( $query, %checks );
+# } } }
+# }
+
}
-@data = (
- { Subject => 'xy', Cc => ['x@example.com'], Requestor => [ 'y@example.com' ] },
- { Subject => 'x-', Cc => ['x@example.com'], Requestor => [] },
- { Subject => '-y', Cc => [], Requestor => [ 'y@example.com' ] },
- { Subject => '-', },
- { Subject => 'zz', Cc => ['z@example.com'], Requestor => [ 'z@example.com' ] },
- { Subject => 'z-', Cc => ['z@example.com'], Requestor => [] },
- { Subject => '-z', Cc => [], Requestor => [ 'z@example.com' ] },
-);
-%test = (
- 'Cc = "x@example.com" AND Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 },
- 'Cc = "x@example.com" OR Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 },
-
- 'Cc != "x@example.com" AND Requestor = "y@example.com"' =>
- { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 },
- 'Cc != "x@example.com" OR Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 1, 'z-' => 1, '-z' => 1 },
-
- 'Cc IS NULL AND Requestor = "y@example.com"' =>
- { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 },
- 'Cc IS NULL OR Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 0, 'z-' => 0, '-z' => 1 },
-
- 'Cc IS NOT NULL AND Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 },
- 'Cc IS NOT NULL OR Requestor = "y@example.com"' =>
- { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 1, 'z-' => 1, '-z' => 0 },
+@conditions = (
+ 'Cc = "not@exist"' => sub { 0 },
+ 'Cc != "not@exist"' => sub { 1 },
+ 'Cc IS NULL' => sub { $_[0] =~ 'c:-;' },
+ 'Cc IS NOT NULL' => sub { $_[0] !~ 'c:-;' },
+ 'Cc = "x@foo.com"' => sub { $_[0] =~ /c:[^;]*x/ },
+ 'Cc != "x@foo.com"' => sub { $_[0] !~ /c:[^;]*x/ },
+ 'Cc LIKE "@bar.com"' => sub { $_[0] =~ /c:[^;]*(?:y|z)/ },
+# TODO:
+# 'Cc NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ },
+
+ 'Requestor = "not@exist"' => sub { 0 },
+ 'Requestor != "not@exist"' => sub { 1 },
+ 'Requestor IS NULL' => sub { $_[0] =~ 'r:-;' },
+ 'Requestor IS NOT NULL' => sub { $_[0] !~ 'r:-;' },
+ 'Requestor = "x@foo.com"' => sub { $_[0] =~ /r:[^;]*x/ },
+ 'Requestor != "x@foo.com"' => sub { $_[0] !~ /r:[^;]*x/ },
+ 'Requestor LIKE "@bar.com"' => sub { $_[0] =~ /r:[^;]*(?:y|z)/ },
+# TODO:
+# 'Requestor NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ },
+
+ 'Watcher = "not@exist"' => sub { 0 },
+ 'Watcher != "not@exist"' => sub { 1 },
+# TODO:
+# 'Watcher IS NULL' => sub { $_[0] eq 'r:-;c:-;' },
+# 'Watcher IS NOT NULL' => sub { $_[0] ne 'r:-;c:-;' },
+ 'Watcher = "x@foo.com"' => sub { $_[0] =~ /x/ },
+# 'Watcher != "x@foo.com"' => sub { $_[0] !~ /x/ },
+ 'Watcher LIKE "@bar.com"' => sub { $_[0] =~ /(?:y|z)/ },
+# TODO:
+# 'Watcher NOT LIKE "@bar.com"' => sub { $_[0] !~ /y|z/ },
+
+ 'Subject LIKE "ne"' => sub { 0 },
+ 'Subject NOT LIKE "ne"' => sub { 1 },
+ 'Subject = "r:x;c:y;"' => sub { $_[0] eq 'r:x;c:y;' },
+ 'Subject LIKE "x"' => sub { $_[0] =~ 'x' },
);
-@tickets = add_tix_from_data();
+
+@tickets = generate_tix();
+$total += scalar @tickets;
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
is($tix->Count, $total, "found $total tickets");
}
-run_tests();
-
+run_auto_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
my $nobody = RT::Nobody();
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->id ."'");
ok($tix->Count, "found ticket(s)");
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->Name ."'");
ok($tix->Count, "found ticket(s)");
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner != '". $nobody->id ."'");
is($tix->Count, 0, "found ticket(s)");
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner != '". $nobody->Name ."'");
is($tix->Count, 0, "found ticket(s)");
}
{
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner.Name LIKE 'nob'");
ok($tix->Count, "found ticket(s)");
}
@@ -229,22 +221,20 @@ my $nobody = RT::Nobody();
# create ticket and force type to not a 'ticket' value
# bug #6898@rt3.fsck.com
# and http://marc.theaimsgroup.com/?l=rt-devel&m=112662934627236&w=2
- @data = ( { Subject => 'not a ticket' } );
- my($t) = add_tix_from_data();
+ my($t) = RT::Test->create_tickets( { Queue => $q->id }, { Subject => 'not a ticket' } );
$t->_Set( Field => 'Type',
Value => 'not a ticket',
CheckACL => 0,
RecordTransaction => 0,
);
- $total--;
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner = 'Nobody'");
is($tix->Count, $total, "found ticket(s)");
}
{
- my $everyone = RT::Group->new( $RT::SystemUser );
+ my $everyone = RT::Group->new( RT->SystemUser );
$everyone->LoadSystemInternalGroup('Everyone');
ok($everyone->id, "loaded 'everyone' group");
my($id, $msg) = $everyone->PrincipalObj->GrantRight( Right => 'OwnTicket',
@@ -252,23 +242,23 @@ my $nobody = RT::Nobody();
);
ok($id, "granted OwnTicket right to Everyone on '$queue'") or diag("error: $msg");
- my $u = RT::User->new( $RT::SystemUser );
- $u->LoadOrCreateByEmail('alpha@example.com');
+ my $u = RT::User->new( RT->SystemUser );
+ $u->LoadOrCreateByEmail('alpha@e.com');
ok($u->id, "loaded user");
- @data = ( { Subject => '4', Owner => $u->id } );
- my($t) = add_tix_from_data();
- is( $t->Owner, $u->id, "created ticket with custom owner" );
+ my($t) = RT::Test->create_tickets(
+ { Queue => $q->id }, { Subject => '4', Owner => $u->id },
+ );
my $u_alpha_id = $u->id;
- $u = RT::User->new( $RT::SystemUser );
- $u->LoadOrCreateByEmail('bravo@example.com');
+ $u = RT::User->new( RT->SystemUser );
+ $u->LoadOrCreateByEmail('bravo@e.com');
ok($u->id, "loaded user");
- @data = ( { Subject => '5', Owner => $u->id } );
- ($t) = add_tix_from_data();
- is( $t->Owner, $u->id, "created ticket with custom owner" );
+ ($t) = RT::Test->create_tickets(
+ { Queue => $q->id }, { Subject => '5', Owner => $u->id },
+ );
my $u_bravo_id = $u->id;
- my $tix = RT::Tickets->new($RT::SystemUser);
+ my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND
( Owner = '$u_alpha_id' OR
Owner = '$u_bravo_id' )"
@@ -276,5 +266,5 @@ my $nobody = RT::Nobody();
is($tix->Count, 2, "found ticket(s)");
}
+@tickets = ();
-exit(0)
diff --git a/rt/t/ticket/search_long_cf_values.t b/rt/t/ticket/search_long_cf_values.t
index f9cc7b5a2..6ce8505d6 100644
--- a/rt/t/ticket/search_long_cf_values.t
+++ b/rt/t/ticket/search_long_cf_values.t
@@ -6,24 +6,24 @@
use strict;
use warnings;
-use RT::Test tests => 10;
+use RT::Test nodata => 1, tests => 10;
# setup the queue
-my $q = RT::Queue->new($RT::SystemUser);
+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);
+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 $t1 = RT::Ticket->new(RT->SystemUser);
my ( $id, undef $msg ) = $t1->Create(
Queue => $q->id,
Subject => 'SearchTest1',
@@ -33,7 +33,7 @@ my ( $id, undef $msg ) = $t1->Create(
ok( $id, $msg );
-my $t2 = RT::Ticket->new($RT::SystemUser);
+my $t2 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t2->Create(
Queue => $q->id,
Subject => 'SearchTest2',
@@ -42,7 +42,7 @@ my $t2 = RT::Ticket->new($RT::SystemUser);
);
ok( $id, $msg );
-my $t3 = RT::Ticket->new($RT::SystemUser);
+my $t3 = RT::Ticket->new(RT->SystemUser);
( $id, undef, $msg ) = $t3->Create(
Queue => $q->id,
Subject => 'SearchTest3',
@@ -52,27 +52,27 @@ my $t3 = RT::Ticket->new($RT::SystemUser);
ok( $id, $msg );
# we have tickets. start searching
-my $tix = RT::Tickets->new($RT::SystemUser);
+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 = 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 = 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 = 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 = 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;
diff --git a/rt/t/ticket/sort-by-custom-ownership.t b/rt/t/ticket/sort-by-custom-ownership.t
index 9739c5aec..b06e9a00a 100644
--- a/rt/t/ticket/sort-by-custom-ownership.t
+++ b/rt/t/ticket/sort-by-custom-ownership.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use RT;
-use RT::Test tests => 7;
+use RT::Test nodata => 1, tests => 7;
use strict;
@@ -19,7 +19,7 @@ my($ret,$msg);
# ---- Create a queue to test with.
my $queue = "PAWSortQueue-$$";
-my $queue_obj = RT::Queue->new($RT::SystemUser);
+my $queue_obj = RT::Queue->new(RT->SystemUser);
($ret, $msg) = $queue_obj->Create(Name => $queue,
Description => 'queue for custom field sort testing');
ok($ret, "$queue test queue creation. $msg");
@@ -27,18 +27,18 @@ ok($ret, "$queue test queue creation. $msg");
# ---- Create some users
-my $me = RT::User->new($RT::SystemUser);
+my $me = RT::User->new(RT->SystemUser);
($ret, $msg) = $me->Create(Name => "Me$$", EmailAddress => $$.'create-me-1@example.com');
($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket');
($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue');
($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket');
-my $you = RT::User->new($RT::SystemUser);
+my $you = RT::User->new(RT->SystemUser);
($ret, $msg) = $you->Create(Name => "You$$", EmailAddress => $$.'create-you-1@example.com');
($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket');
($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue');
($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket');
-my $nobody = RT::User->new($RT::SystemUser);
+my $nobody = RT::User->new(RT->SystemUser);
$nobody->Load('nobody');
@@ -54,7 +54,7 @@ my @tickets = (
[qw[6 55], $nobody],
);
for (@tickets) {
- my $t = RT::Ticket->new($RT::SystemUser);
+ my $t = RT::Ticket->new(RT->SystemUser);
$t->Create( Queue => $queue_obj->Id,
Subject => $_->[0],
Owner => $_->[2]->Id,
@@ -76,8 +76,8 @@ sub check_order {
# The real tests start here
-my $cme = new RT::CurrentUser( $me );
-my $metx = new RT::Tickets( $cme );
+my $cme = RT::CurrentUser->new( $me );
+my $metx = RT::Tickets->new( $cme );
# Make sure we can sort in both directions on a queue specific field.
$metx->FromSQL(qq[queue="$queue"] );
$metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' );
@@ -90,8 +90,8 @@ check_order( $metx, reverse qw[2 1 6 5 4 3]);
-my $cyou = new RT::CurrentUser( $you );
-my $youtx = new RT::Tickets( $cyou );
+my $cyou = RT::CurrentUser->new( $you );
+my $youtx = RT::Tickets->new( $cyou );
# Make sure we can sort in both directions on a queue specific field.
$youtx->FromSQL(qq[queue="$queue"] );
$youtx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' );
diff --git a/rt/t/ticket/sort-by-queue.t b/rt/t/ticket/sort-by-queue.t
index df6e1ad0f..bf2934bc2 100644
--- a/rt/t/ticket/sort-by-queue.t
+++ b/rt/t/ticket/sort-by-queue.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test tests => 8;
+use RT::Test nodata => 1, tests => 12;
use strict;
use warnings;
@@ -14,12 +14,12 @@ use RT::CustomField;
#########################################################
-diag "Create queues to test with." if $ENV{TEST_VERBOSE};
+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 $queue = RT::Queue->new( RT->SystemUser );
my ($ret, $msg) = $queue->Create(
Name => $name ."-$$",
Description => 'queue to test sorting by queue'
@@ -29,21 +29,7 @@ foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) {
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;
-}
+my ($total, @tickets, @test) = (0, ());
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -53,7 +39,7 @@ sub run_tests {
foreach my $order (qw(ASC DESC)) {
my $error = 0;
- my $tix = RT::Tickets->new( $RT::SystemUser );
+ my $tix = RT::Tickets->new( RT->SystemUser );
$tix->FromSQL( $query );
$tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
@@ -88,13 +74,14 @@ sub run_tests {
}
}
-@data = (
+@tickets = RT::Test->create_tickets(
+ { RandomOrder => 1 },
{ Queue => $qids[0], Subject => 'z' },
{ Queue => $qids[1], Subject => 'a' },
);
-@tickets = add_tix_from_data();
@test = (
{ Order => "Queue" },
);
run_tests();
+@tickets = ();
diff --git a/rt/t/ticket/sort-by-user.t b/rt/t/ticket/sort-by-user.t
index f9b1602f1..10d43de37 100644
--- a/rt/t/ticket/sort-by-user.t
+++ b/rt/t/ticket/sort-by-user.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test tests => 32;
+use RT::Test nodata => 1, tests => 52;
use strict;
use warnings;
@@ -14,11 +14,11 @@ use RT::CustomField;
# we sort by user name
#########################################################
-diag "Create a queue to test with." if $ENV{TEST_VERBOSE};
+diag "Create a queue to test with.";
my $queue_name = "OwnerSortQueue$$";
my $queue;
{
- $queue = RT::Queue->new( $RT::SystemUser );
+ $queue = RT::Queue->new( RT->SystemUser );
my ($ret, $msg) = $queue->Create(
Name => $queue_name,
Description => 'queue for custom field sort testing'
@@ -31,7 +31,7 @@ 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 $user = RT::User->new( RT->SystemUser );
my ($uid) = $user->Create(
Name => $name,
Privileged => 1,
@@ -47,32 +47,8 @@ foreach my $u (qw(Z A)) {
push @uids, $user->id;
}
-my ($total, @data, @tickets, @test) = (0, ());
+my (@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;
@@ -82,7 +58,7 @@ sub run_tests {
foreach my $order (qw(ASC DESC)) {
my $error = 0;
- my $tix = RT::Tickets->new( $RT::SystemUser );
+ my $tix = RT::Tickets->new( RT->SystemUser );
$tix->FromSQL( $query );
$tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
@@ -122,7 +98,9 @@ sub run_tests {
{ Subject => 'Z', Owner => $uids[0] },
{ Subject => 'A', Owner => $uids[1] },
);
-@tickets = add_tix_from_data();
+
+@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data );
+
@test = (
{ Order => "Owner" },
);
@@ -133,7 +111,7 @@ run_tests();
{ Subject => 'Z', Creator => $uids[0] },
{ Subject => 'A', Creator => $uids[1] },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data );
@test = (
{ Order => "Creator" },
);
@@ -144,9 +122,10 @@ run_tests();
{ Subject => 'Z', LastUpdatedBy => $uids[0] },
{ Subject => 'A', LastUpdatedBy => $uids[1] },
);
-@tickets = add_tix_from_data();
+@tickets = RT::Test->create_tickets( { Queue => $queue->id }, @data );
@test = (
{ Order => "LastUpdatedBy" },
);
run_tests();
+@tickets = ();
diff --git a/rt/t/ticket/sort_by_cf.t b/rt/t/ticket/sort_by_cf.t
index 69274add9..65704da62 100644
--- a/rt/t/ticket/sort_by_cf.t
+++ b/rt/t/ticket/sort_by_cf.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test tests => 21;
+use RT::Test nodata => 1, tests => 21;
RT::Init();
use strict;
@@ -19,7 +19,7 @@ my($ret,$msg);
# ---- Create a queue to test with.
my $queue = "CFSortQueue-$$";
-my $queue_obj = RT::Queue->new( $RT::SystemUser );
+my $queue_obj = RT::Queue->new( RT->SystemUser );
($ret, $msg) = $queue_obj->Create(
Name => $queue,
Description => 'queue for custom field sort testing'
@@ -28,10 +28,10 @@ ok($ret, "$queue test queue creation. $msg");
# ---- Create some custom fields. We're not currently using all of
# them to test with, but the more the merrier.
-my $cfO = RT::CustomField->new($RT::SystemUser);
-my $cfA = RT::CustomField->new($RT::SystemUser);
-my $cfB = RT::CustomField->new($RT::SystemUser);
-my $cfC = RT::CustomField->new($RT::SystemUser);
+my $cfO = RT::CustomField->new(RT->SystemUser);
+my $cfA = RT::CustomField->new(RT->SystemUser);
+my $cfB = RT::CustomField->new(RT->SystemUser);
+my $cfC = RT::CustomField->new(RT->SystemUser);
($ret, $msg) = $cfO->Create( Name => 'Order',
Queue => 0,
@@ -61,7 +61,7 @@ ok($ret, "Custom Field Charlie created");
# ----- Create some tickets to test with. Assign them some values to
# make it easy to sort with.
-my $t1 = RT::Ticket->new($RT::SystemUser);
+my $t1 = RT::Ticket->new(RT->SystemUser);
$t1->Create( Queue => $queue_obj->Id,
Subject => 'One',
);
@@ -70,7 +70,7 @@ $t1->AddCustomFieldValue(Field => $cfA->Id, Value => '2');
$t1->AddCustomFieldValue(Field => $cfB->Id, Value => '1');
$t1->AddCustomFieldValue(Field => $cfC->Id, Value => 'BBB');
-my $t2 = RT::Ticket->new($RT::SystemUser);
+my $t2 = RT::Ticket->new(RT->SystemUser);
$t2->Create( Queue => $queue_obj->Id,
Subject => 'Two',
);
@@ -93,7 +93,7 @@ sub check_order {
}
# The real tests start here
-my $tx = new RT::Tickets( $RT::SystemUser );
+my $tx = RT::Tickets->new( RT->SystemUser );
# Make sure we can sort in both directions on a queue specific field.
@@ -102,7 +102,7 @@ $tx->OrderBy( FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' );
is($tx->Count,2 ,"We found 2 tickets when looking for cf charlie");
check_order( $tx, 1, 2);
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' );
is($tx->Count,2, "We found two tickets when sorting by cf charlie without limiting to it" );
@@ -111,20 +111,20 @@ check_order( $tx, 2, 1);
# When ordering by _global_ CustomFields, if more than one queue has a
# CF named Charlie, things will go bad. So, these results are uniqued
# in Tickets_Overlay.
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DESC' );
is($tx->Count,2);
check_order( $tx, 1, 2);
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'ASC' );
is($tx->Count,2);
check_order( $tx, 2, 1);
# Add a new ticket, to test sorting on multiple columns.
-my $t3 = RT::Ticket->new($RT::SystemUser);
+my $t3 = RT::Ticket->new(RT->SystemUser);
$t3->Create( Queue => $queue_obj->Id,
Subject => 'Three',
);
@@ -133,7 +133,7 @@ $t3->AddCustomFieldValue(Field => $cfA->Id, Value => '3');
$t3->AddCustomFieldValue(Field => $cfB->Id, Value => '2');
$t3->AddCustomFieldValue(Field => $cfC->Id, Value => 'AAA');
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderByCols(
{ FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' },
@@ -142,7 +142,7 @@ $tx->OrderByCols(
is($tx->Count,3);
check_order( $tx, 3, 2, 1);
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderByCols(
{ FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' },
@@ -153,7 +153,7 @@ check_order( $tx, 1, 2, 3);
# Reverse the order of the secondary column, which changes the order
# of the first two tickets.
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderByCols(
{ FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' },
@@ -162,7 +162,7 @@ $tx->OrderByCols(
is($tx->Count,3);
check_order( $tx, 2, 3, 1);
-$tx = new RT::Tickets( $RT::SystemUser );
+$tx = RT::Tickets->new( RT->SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderByCols(
{ FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' },