[Rt-commit] r15367 - in rt/branches/3.999-DANGEROUS: . t/api t/mail t/maildigest t/web

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri Aug 22 09:33:15 EDT 2008


Author: sunnavy
Date: Fri Aug 22 09:33:14 2008
New Revision: 15367

Added:
   rt/branches/3.999-DANGEROUS/t/api/reminders.t
   rt/branches/3.999-DANGEROUS/t/mail/charsets-outgoing.t
   rt/branches/3.999-DANGEROUS/t/maildigest/
   rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t
   rt/branches/3.999-DANGEROUS/t/ticket/action_linear_escalate.t
   rt/branches/3.999-DANGEROUS/t/ticket/add-watchers.t
   rt/branches/3.999-DANGEROUS/t/ticket/badlinks.t
   rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-multiple.t
   rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-single.t
   rt/branches/3.999-DANGEROUS/t/ticket/deferred_owner.t
   rt/branches/3.999-DANGEROUS/t/ticket/search_by_links.t
   rt/branches/3.999-DANGEROUS/t/ticket/search_long_cf_values.t
   rt/branches/3.999-DANGEROUS/t/ticket/sort-by-queue.t
   rt/branches/3.999-DANGEROUS/t/ticket/sort-by-user.t
   rt/branches/3.999-DANGEROUS/t/web/cf_onqueue.t
   rt/branches/3.999-DANGEROUS/t/web/dashboards-groups.t
   rt/branches/3.999-DANGEROUS/t/web/dashboards.t
   rt/branches/3.999-DANGEROUS/t/web/quicksearch.t
   rt/branches/3.999-DANGEROUS/t/web/rest.t
   rt/branches/3.999-DANGEROUS/t/web/unlimited_search.t
Modified:
   rt/branches/3.999-DANGEROUS/   (props changed)

Log:
 r15970 at sunnavys-mb:  sunnavy | 2008-08-22 21:31:55 +0800
 added missing tests in 3.8 but not in 3.7


Added: rt/branches/3.999-DANGEROUS/t/api/reminders.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/api/reminders.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,90 @@
+
+use strict;
+use warnings;
+use Test::More; 
+plan tests => 20;
+use RT;
+use RT::Test;
+
+
+{
+
+# Create test queues
+use_ok ('RT::Queue');
+
+ok(my $testqueue = RT::Queue->new($RT::SystemUser), 'Instantiate RT::Queue');
+ok($testqueue->Create( Name => 'reminders tests'), 'Create new queue: reminders tests');
+isnt($testqueue->Id , 0, 'Success creating queue');
+
+ok($testqueue->Create( Name => 'reminders tests 2'), 'Create new queue: reminders tests 2');
+isnt($testqueue->Id , 0, 'Success creating queue');
+
+# Create test ticket
+use_ok('RT::Ticket');
+
+my $u = RT::User->new($RT::SystemUser);
+$u->Load("root");
+ok ($u->Id, "Found the root user");
+ok(my $t = RT::Ticket->new($RT::SystemUser), 'Instantiate RT::Ticket');
+ok(my ($id, $msg) = $t->Create( Queue => $testqueue->Id,
+               Subject => 'Testing',
+               Owner => $u->Id
+              ), 'Create sample ticket');
+isnt($id , 0, 'Success creating ticket');
+
+# Add reminder
+my $due_obj = RT::Date->new( $RT::SystemUser );
+$due_obj->SetToNow;
+ok(my ( $add_id, $add_msg, $txnid ) = $t->Reminders->Add(
+    Subject => 'TestReminder',
+    Owner   => 'root',
+    Due     => $due_obj->ISO
+    ), 'Add reminder');
+
+# Check that the new Reminder is here
+my $reminders = $t->Reminders->Collection;
+ok($reminders, 'Loading reminders for this ticket');
+my $found = 0;
+while ( my $reminder = $reminders->Next ) {
+    next unless $found == 0;
+    $found = 1 if ( $reminder->Subject =~ m/TestReminder/ );
+}
+
+is($found, 1, 'Reminder successfully added');
+
+# Change queue
+ok (my ($move_val, $move_msg) = $t->SetQueue('reminders tests 2'), 'Moving ticket from queue "reminders tests" to "reminders tests 2"');
+
+is ($t->QueueObj->Name, 'reminders tests 2', 'Ticket successfully moved');
+
+# Check that the new reminder is still there and moved to the new queue
+$reminders = $t->Reminders->Collection;
+ok($reminders, 'Loading reminders for this ticket');
+$found = 0;
+my $ok_queue = 0;
+while ( my $reminder = $reminders->Next ) {
+    next unless $found == 0;
+    if ( $reminder->Subject =~ m/TestReminder/ ) {
+        $found = 1;
+        $ok_queue = 1 if ( $reminder->QueueObj->Name eq 'reminders tests 2' );
+    }
+}
+is($found, 1, 'Reminder successfully added');
+
+is($ok_queue, 1, 'Reminder automatically moved to new queue');
+
+# Resolve reminder
+my $r_resolved = 0;
+while ( my $reminder = $reminders->Next ) {
+    if ( $reminder->Subject =~ m/TestReminder/ ) {
+        if ( $reminder->Status ne 'resolved' ) {
+            $t->Reminders->Resolve($reminder);
+            $r_resolved = 1 if ( $reminder->Status eq 'resolved' );
+        }
+    }
+}
+
+is($r_resolved, 1, 'Reminder resolved');
+
+}
+1;

Added: rt/branches/3.999-DANGEROUS/t/mail/charsets-outgoing.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/mail/charsets-outgoing.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,308 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use utf8;
+
+use Test::More;
+use RT::Test;
+
+plan tests => 30;
+
+RT::Test->set_mail_catcher;
+
+my $queue = RT::Test->load_or_create_queue(
+    Name              => 'Regression',
+    CorrespondAddress => 'rt-recipient at example.com',
+    CommentAddress    => 'rt-recipient at example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+diag "make sure queue has no subject tag" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( undef );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+diag "set intial simple autoreply template" if $ENV{'TEST_VERBOSE'};
+{
+    my $template = RT::Template->new( $RT::SystemUser );
+    $template->Load('Autoreply');
+    ok $template->id, "loaded autoreply tempalte";
+
+    my ($status, $msg) = $template->SetContent(
+        "Subject: Autreply { \$Ticket->Subject }\n"
+        ."\n"
+        ."hi there it's an autoreply.\n"
+        ."\n"
+    );
+    ok $status, "changed content of the template"
+        or diag "error: $msg";
+}
+
+diag "basic test of autoreply" if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => 'test',
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+}
+
+my $str_ru_test = "\x{442}\x{435}\x{441}\x{442}";
+my $str_ru_autoreply = "\x{410}\x{432}\x{442}\x{43e}\x{43e}\x{442}\x{432}\x{435}\x{442}";
+my $str_ru_support = "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}";
+
+diag "non-ascii Subject with ascii prefix set in the template"
+    if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_test/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "set non-ascii subject tag for the queue" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( $str_ru_support );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+diag "ascii subject with non-ascii subject tag" if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => 'test',
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_support/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "non-ascii subject with non-ascii subject tag" if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_support/
+            or do { $status = 0; diag "wrong subject: $subject" };
+        $subject =~ /$str_ru_test/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "return back the empty subject tag" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( undef );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+diag "add non-ascii subject prefix in the autoreply template" if $ENV{'TEST_VERBOSE'};
+{
+    my $template = RT::Template->new( $RT::SystemUser );
+    $template->Load('Autoreply');
+    ok $template->id, "loaded autoreply tempalte";
+
+    my ($status, $msg) = $template->SetContent(
+        "Subject: $str_ru_autoreply { \$Ticket->Subject }\n"
+        ."\n"
+        ."hi there it's an autoreply.\n"
+        ."\n"
+    );
+    ok $status, "changed content of the template" or diag "error: $msg";
+}
+
+diag "ascii subject with non-ascii subject prefix in template" if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => 'test',
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "non-ascii subject with non-ascii subject prefix in template"
+    if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "set non-ascii subject tag for the queue" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( $str_ru_support );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+diag "non-ascii subject, non-ascii prefix in template and non-ascii tag"
+    if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+        $subject =~ /$str_ru_autoreply/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "flush subject tag of the queue" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( undef );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+
+diag "don't change subject via template" if $ENV{'TEST_VERBOSE'};
+{
+    my $template = RT::Template->new( $RT::SystemUser );
+    $template->Load('Autoreply');
+    ok $template->id, "loaded autoreply tempalte";
+
+    my ($status, $msg) = $template->SetContent(
+        "\n"
+        ."\n"
+        ."hi there it's an autoreply.\n"
+        ."\n"
+    );
+    ok $status, "changed content of the template" or diag "error: $msg";
+}
+
+diag "non-ascii Subject without changes in template" if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_test/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+diag "set non-ascii subject tag for the queue" if $ENV{'TEST_VERBOSE'};
+{
+    my ($status, $msg) = $queue->SetSubjectTag( $str_ru_support );
+    ok $status, "set subject tag for the queue" or diag "error: $msg";
+}
+
+diag "non-ascii Subject without changes in template and with non-ascii subject tag"
+    if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Create(
+        Queue => $queue->id,
+        Subject => $str_ru_test,
+        Requestor => 'root at localhost',
+    );
+    my @mails = RT::Test->fetch_caught_mails;
+    ok @mails, "got some outgoing emails";
+
+    my $status = 1;
+    foreach my $mail ( @mails ) {
+        my $entity = parse_mail( $mail );
+        my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
+        $subject =~ /$str_ru_test/
+            or do { $status = 0; diag "wrong subject: $subject" };
+        $subject =~ /$str_ru_support/
+            or do { $status = 0; diag "wrong subject: $subject" };
+    }
+    ok $status, "all mails have correct data";
+}
+
+sub parse_mail {
+    my $mail = shift;
+    require RT::EmailParser;
+    my $parser = new RT::EmailParser;
+    $parser->ParseMIMEEntityFromScalar( $mail );
+    return $parser->Entity;
+}
+

Added: rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,178 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+use Test::More tests => 31;
+use RT;
+use RT::Test;
+my @users = qw/ emailnormal at example.com emaildaily at example.com emailweekly at example.com emailsusp at example.com /;
+
+my( $ret, $msg );
+my $user_n = RT::User->new( $RT::SystemUser );
+( $ret, $msg ) = $user_n->LoadOrCreateByEmail( $users[0] );
+ok( $ret, "user with default email prefs created: $msg" );
+$user_n->SetPrivileged( 1 );
+
+my $user_d = RT::User->new( $RT::SystemUser );
+( $ret, $msg ) = $user_d->LoadOrCreateByEmail( $users[1] );
+ok( $ret, "user with daily digest email prefs created: $msg" );
+# Set a username & password for testing the interface.
+$user_d->SetPrivileged( 1 );
+$user_d->SetPreferences($RT::System => { %{ $user_d->Preferences( $RT::System ) || {}}, EmailFrequency => 'Daily digest'});
+
+
+
+my $user_w = RT::User->new( $RT::SystemUser );
+( $ret, $msg ) = $user_w->LoadOrCreateByEmail( $users[2] );
+ok( $ret, "user with weekly digest email prefs created: $msg" );
+$user_w->SetPrivileged( 1 );
+$user_w->SetPreferences($RT::System => { %{ $user_w->Preferences( $RT::System ) || {}}, EmailFrequency => 'Weekly digest'});
+
+my $user_s = RT::User->new( $RT::SystemUser );
+( $ret, $msg ) = $user_s->LoadOrCreateByEmail( $users[3] );
+ok( $ret, "user with suspended email prefs created: $msg" );
+$user_s->SetPreferences($RT::System => { %{ $user_s->Preferences( $RT::System ) || {}}, EmailFrequency => 'Suspended'});
+$user_s->SetPrivileged( 1 );
+
+
+is(RT::Config->Get('EmailFrequency' => $user_s), 'Suspended');
+
+# Make a testing queue for ourselves.
+my $testq = RT::Queue->new( $RT::SystemUser );
+if( $testq->ValidateName( 'EmailDigest-testqueue' ) ) {
+    ( $ret, $msg ) = $testq->Create( Name => 'EmailDigest-testqueue' );
+    ok( $ret, "Our test queue is created: $msg" );
+} else {
+    $testq->Load( 'EmailDigest-testqueue' );
+    ok( $testq->id, "Our test queue is loaded" );
+}
+
+# Allow anyone to open a ticket on the test queue.
+my $everyone = RT::Group->new( $RT::SystemUser );
+( $ret, $msg ) = $everyone->LoadSystemInternalGroup( 'Everyone' );
+ok( $ret, "Loaded 'everyone' group: $msg" );
+
+( $ret, $msg ) = $everyone->PrincipalObj->GrantRight( Right => 'CreateTicket',
+						      Object => $testq );
+ok( $ret || $msg =~ /already has/, "Granted everyone CreateTicket on testq: $msg" );
+
+# Make user_d an admincc for the queue.
+( $ret, $msg ) = $user_d->PrincipalObj->GrantRight( Right => 'AdminQueue',
+						    Object => $testq );
+ok( $ret || $msg =~ /already has/, "Granted dduser AdminQueue on testq: $msg" );
+( $ret, $msg ) = $testq->AddWatcher( Type => 'AdminCc',
+			     PrincipalId => $user_d->PrincipalObj->id );
+ok( $ret || $msg =~ /already/, "dduser added as a queue watcher: $msg" );
+
+# Give the others queue rights.
+( $ret, $msg ) = $user_n->PrincipalObj->GrantRight( Right => 'AdminQueue',
+						    Object => $testq );
+ok( $ret || $msg =~ /already has/, "Granted emailnormal right on testq: $msg" );
+( $ret, $msg ) = $user_w->PrincipalObj->GrantRight( Right => 'AdminQueue',
+						    Object => $testq );
+ok( $ret || $msg =~ /already has/, "Granted emailweekly right on testq: $msg" );
+( $ret, $msg ) = $user_s->PrincipalObj->GrantRight( Right => 'AdminQueue',
+						    Object => $testq );
+ok( $ret || $msg =~ /already has/, "Granted emailsusp right on testq: $msg" );
+
+# Create a ticket with To: Cc: Bcc: fields using our four users.
+my $id;
+my $ticket = RT::Ticket->new( $RT::SystemUser );
+( $id, $ret, $msg ) = $ticket->Create( Queue => $testq->Name,
+				       Requestor => [ $user_w->Name ],
+				       Subject => 'Test ticket for RT::Extension::EmailDigest',
+				       );
+ok( $ret, "Ticket $id created: $msg" );
+
+# Make the other users ticket watchers.
+( $ret, $msg ) = $ticket->AddWatcher( Type => 'Cc',
+		      PrincipalId => $user_n->PrincipalObj->id );
+ok( $ret, "Added user_w as a ticket watcher: $msg" );
+( $ret, $msg ) = $ticket->AddWatcher( Type => 'Cc',
+		      PrincipalId => $user_s->PrincipalObj->id );
+ok( $ret, "Added user_s as a ticket watcher: $msg" );
+
+my $obj;
+($id, $msg, $obj ) = $ticket->Correspond(
+	Content => "This is a ticket response for CC action" );
+ok( $ret, "Transaction created: $msg" );
+
+# Get the deferred notifications that should result.  Should be two for
+# email daily, and one apiece for emailweekly and emailsusp.
+my @notifications;
+
+my $txns = RT::Transactions->new( $RT::SystemUser );
+$txns->LimitToTicket( $ticket->id );
+my( $c_daily, $c_weekly, $c_susp ) = ( 0, 0, 0 );
+while( my $txn = $txns->Next ) {
+    my @daily_rcpt = $txn->DeferredRecipients( 'daily' );
+    my @weekly_rcpt = $txn->DeferredRecipients('weekly' );
+    my @susp_rcpt = $txn->DeferredRecipients(  'susp' );
+
+    $c_daily++ if @daily_rcpt;
+    $c_weekly++ if @weekly_rcpt;
+    $c_susp++ if @susp_rcpt;
+
+    # If the transaction has content...
+    if( $txn->ContentObj ) {
+	# ...none of the deferred folk should be in the header.
+	my $headerstr = $txn->ContentObj->Headers;
+	foreach my $rcpt( @daily_rcpt, @weekly_rcpt, @susp_rcpt ) {
+	    ok( $headerstr !~ /$rcpt/, "Deferred recipient $rcpt not found in header" );
+	}
+    }
+}
+
+# Finally, check to see that we got the correct number of each sort of
+# deferred recipient.
+is( $c_daily, 2, "correct number of daily-sent messages" );
+is( $c_weekly, 2, "correct number of weekly-sent messages" );
+is( $c_susp, 1, "correct number of suspended messages" );
+
+
+
+
+
+# Now let's actually run the daily and weekly digest tool to make sure we generate those
+
+# the first time get the content
+{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily --print");
+my @results = <$digester>;
+my $content = join ('', @results);
+like($content, qr/in the last day/);
+} {
+# The second time run it for real so we make sure that we get RT to mark the txn as sent
+open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily");
+my @results = <$digester>;
+my $content = join ('', @results);
+like($content, qr/maildaily\@/);
+close($digester);
+}
+# now we should have nothing to do, so no content.
+{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily --print");
+my @results = <$digester>;
+my $content = join ('', @results);
+is ($content, '');
+} 
+
+# the first time get the content
+{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly --print");
+my @results = <$digester>;
+my $content = join ('', @results);
+like($content, qr/in the last seven days/);
+} {
+# The second time run it for real so we make sure that we get RT to mark the txn as sent
+open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly");
+my @results = <$digester>;
+my $content = join ('', @results);
+like($content, qr/mailweekly\@/);
+close($digester);
+}
+# now we should have nothing to do, so no content.
+{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly --print");
+my @results = <$digester>;
+my $content = join ('', @results);
+is ($content, '');
+} 
+
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/action_linear_escalate.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/action_linear_escalate.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,101 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More tests => 17;
+use RT;
+use RT::Test;
+
+my ($id, $msg);
+my $RecordTransaction;
+my $UpdateLastUpdated;
+
+
+use_ok('RT::Action::LinearEscalate');
+
+my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
+ok $q && $q->id, 'loaded or created queue';
+
+# rt-cron-tool uses Gecos name to get rt user, so we'd better create one
+my $gecos = RT::Test->load_or_create_user(
+    Name => 'gecos',
+    Password => 'password',
+    Gecos => ($^O eq 'MSWin32') ? Win32::LoginName() : (getpwuid($<))[0],
+);
+ok $gecos && $gecos->id, 'loaded or created gecos user';
+
+# get rid of all right permissions
+$gecos->PrincipalObj->GrantRight( Right => 'SuperUser' );
+
+
+my $user = RT::Test->load_or_create_user(
+    Name => 'user', Password => 'password',
+);
+ok $user && $user->id, 'loaded or created user';
+
+$user->PrincipalObj->GrantRight( Right => 'SuperUser' );
+my $current_user = RT::CurrentUser->new($RT::SystemUser);
+($id, $msg) = $current_user->Load($user->id);
+ok( $id, "Got current user? $msg" );
+
+#defaults
+$RecordTransaction = 0;
+$UpdateLastUpdated = 1;
+my $ticket2 = create_ticket_as_ok($current_user);
+escalate_ticket_ok($ticket2);
+ok( $ticket2->LastUpdatedBy != $user->id, "Set LastUpdated" );
+ok( $ticket2->Transactions->Last->Type =~ /Create/i, "Did not record a transaction" );
+
+$RecordTransaction = 1;
+$UpdateLastUpdated = 1;
+my $ticket1 = create_ticket_as_ok($current_user);
+escalate_ticket_ok($ticket1);
+ok( $ticket1->LastUpdatedBy != $user->id, "Set LastUpdated" );
+ok( $ticket1->Transactions->Last->Type !~ /Create/i, "Recorded a transaction" );
+
+$RecordTransaction = 0;
+$UpdateLastUpdated = 0;
+my $ticket3 = create_ticket_as_ok($current_user);
+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);
+    $created->Unix(time() - ( 7 * 24 * 60**2 ));
+    my $due = RT::Date->new($RT::SystemUser);
+    $due->Unix(time() + ( 7 * 24 * 60**2 ));
+
+    my $ticket = RT::Ticket->new($user);
+    ($id, $msg) = $ticket->Create( Queue => $q->id,
+                                   Subject => "Escalation test",
+                                   Priority => 0,
+                                   InitialPriority => 0,
+                                   FinalPriority => 50,
+                                 );
+    ok($id, "Created ticket? ".$id);
+    $ticket->__Set( Field => 'Created',
+                    Value => $created->ISO,
+                  );
+    $ticket->__Set( Field => 'Due',
+                    Value => $due->ISO,
+                  );
+
+    return $ticket;
+}
+
+sub escalate_ticket_ok {
+    my $ticket = shift;
+    my $id = $ticket->id;
+    print "$RT::BinPath/rt-crontool --search RT::Search::FromSQL --search-arg \"id = @{[$id]}\" --action RT::Action::LinearEscalate --action-arg \"RecordTransaction:$RecordTransaction; UpdateLastUpdated:$UpdateLastUpdated\"\n";
+    print STDERR `$RT::BinPath/rt-crontool --search RT::Search::FromSQL --search-arg "id = @{[$id]}" --action RT::Action::LinearEscalate --action-arg "RecordTransaction:$RecordTransaction; UpdateLastUpdated:$UpdateLastUpdated"`;
+
+    $ticket->Load($id);     # reload, because otherwise we get the cached value
+    ok( $ticket->Priority != 0, "Escalated ticket" );
+}

Added: rt/branches/3.999-DANGEROUS/t/ticket/add-watchers.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/add-watchers.t	Fri Aug 22 09:33:14 2008
@@ -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::Test;
+
+use strict;
+use warnings;
+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" );
+
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/badlinks.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/badlinks.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 12;
+use RT::Test;
+
+my ($baseurl, $m) = RT::Test->started_ok;
+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 ($tid, $txn, $msg) = $ticket->Create(
+        Queue => $queue->id,
+        Subject => 'test links',
+        );
+ok $tid, 'created a ticket #'. $tid or diag "error: $msg";
+
+$m->goto_ticket($tid);
+
+$m->follow_link_ok( { text => 'Links' }, "Followed link to Links" );
+
+ok $m->form_with_fields("$tid-DependsOn"), "found the form";
+my $not_a_ticket_url = "http://example.com/path/to/nowhere";
+$m->field("$tid-DependsOn", $not_a_ticket_url);
+$m->field("DependsOn-$tid", $not_a_ticket_url);
+$m->field("$tid-MemberOf", $not_a_ticket_url);
+$m->field("MemberOf-$tid", $not_a_ticket_url);
+$m->field("$tid-RefersTo", $not_a_ticket_url);
+$m->field("RefersTo-$tid", $not_a_ticket_url);
+$m->submit;
+
+foreach my $type ("depends on", "member of", "refers to") {
+    $m->content_like(qr/$type.+$not_a_ticket_url/,"base for $type");
+    $m->content_like(qr/$not_a_ticket_url.+$type/,"target for $type");
+}
+
+$m->goto_ticket($tid);

Added: rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-multiple.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-multiple.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,138 @@
+#!/usr/bin/perl
+
+use Test::More tests => 24;
+use RT::Test;
+
+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." if $ENV{TEST_VERBOSE};
+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" if $ENV{TEST_VERBOSE};
+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');
+            my $last_id = $tix->Last->id;
+            while ( my $t = $tix->Next ) {
+                my $tmp;
+                next if $t->id == $last_id and $t->Subject eq "-"; # Nulls are allowed to come last, in Pg
+
+                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;
+                }
+            }
+        }
+    }
+}
+
+ at data = (
+    { },
+    { CF => ['b', 'd'] },
+    { CF => ['a', 'c'] },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "CF.{$cf_name}" },
+    { Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+ at data = (
+    { CF => ['m', 'a'] },
+    { CF => ['m'] },
+    { CF => ['m', 'o'] },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "CF.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
+    { Order => "CF.$queue_name.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
+);
+run_tests();
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-single.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/cfsort-freeform-single.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,192 @@
+#!/usr/bin/perl
+
+use Test::More tests => 57;
+use RT::Test;
+
+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." if $ENV{TEST_VERBOSE};
+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 test queue creation. $msg");
+}
+
+# CFs for testing, later we create another one
+my %CF;
+my $cf_name;
+
+diag "create a CF\n" if $ENV{TEST_VERBOSE};
+{
+    $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');
+            my $last_id = $tix->Last->id;
+            while ( my $t = $tix->Next ) {
+                my $tmp;
+                next if $t->id == $last_id and $t->Subject eq "-"; # Nulls are allowed to come last, in Pg
+
+                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;
+                }
+            }
+        }
+    }
+}
+
+ at data = (
+    { },
+    { CF => 'a' },
+    { CF => 'b' },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "CF.{$cf_name}" },
+    { Order => "CF.$queue_name.{$cf_name}" },
+);
+run_tests();
+
+ at data = (
+    { },
+    { CF => 'aa' },
+    { CF => 'ab' },
+);
+ at tickets = add_tix_from_data();
+ at 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();
+
+ at data = (
+    { Subject => '-', },
+    { Subject => 'a', CF => 'a' },
+    { Subject => 'b', CF => 'b' },
+    { Subject => 'c', CF => 'c' },
+);
+ at tickets = add_tix_from_data();
+ at 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" if $ENV{TEST_VERBOSE};
+{
+    $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)
+ at data = (
+    { Subject => '-', },
+    { Subject => 'a', CF => 'a', AnotherCF => 'za' },
+    { Subject => 'b', CF => 'b', AnotherCF => 'ya' },
+    { Subject => 'c', CF => 'c', AnotherCF => 'xa' },
+);
+ at tickets = add_tix_from_data();
+ at 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();
+
+
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/deferred_owner.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/deferred_owner.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,115 @@
+use Test::More  tests => '17';
+
+use strict;
+use warnings;
+
+use_ok('RT');
+use_ok('RT::Ticket');
+use RT::Test;
+
+
+my $tester = RT::Test->load_or_create_user(
+    EmailAddress => 'tester at localhost',
+);
+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 );
+$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'};
+{
+    RT::Test->set_rights(
+        { Principal => $tester->PrincipalObj,
+          Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
+        },
+        { Principal => $owner_role_group->PrincipalObj,
+          Object => $queue,
+          Right => [qw(ModifyTicket)],
+        },
+    );
+    my $ticket = RT::Ticket->new( $tester );
+    # tester is owner, owner has right to modify owned tickets,
+    # this right is required to set somebody as AdminCc
+    my ($tid, $txn_id, $msg) = $ticket->Create(
+        Queue   => $queue->id,
+        Owner   => $tester->id,
+        AdminCc => 'root at localhost',
+    );
+    diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+    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'};
+{
+    RT::Test->set_rights(
+        { Principal => $tester->PrincipalObj,
+          Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
+        },
+    );
+    my $ticket = RT::Ticket->new( $tester );
+    # tester is owner, owner has right to modify owned tickets,
+    # this right is required to set somebody as AdminCc
+    my ($tid, $txn_id, $msg) = $ticket->Create(
+        Queue   => $queue->id,
+        Owner   => $tester->id,
+        AdminCc => 'root at localhost',
+    );
+    diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+    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'};
+{
+    RT::Test->set_rights(
+        { Principal => $tester->PrincipalObj,
+          Right => [qw(SeeQueue ShowTicket CreateTicket)],
+        },
+        { Principal => $queue->Cc->PrincipalObj,
+          Object => $queue,
+          Right => [qw(OwnTicket TakeTicket)],
+        },
+    );
+    my $ticket = RT::Ticket->new( $tester );
+    # set tester as Cc, Cc role group has right to own and take tickets
+    my ($tid, $txn_id, $msg) = $ticket->Create(
+        Queue => $queue->id,
+        Owner => $tester->id,
+        Cc    => 'tester at localhost',
+    );
+    diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+    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'};
+{
+    RT::Test->set_rights(
+        { Principal => $tester->PrincipalObj,
+          Right => [qw(SeeQueue ShowTicket CreateTicket)],
+        },
+    );
+    my $ticket = RT::Ticket->new( $tester );
+    # set tester as Cc, Cc role group has right to own and take tickets
+    my ($tid, $txn_id, $msg) = $ticket->Create(
+        Queue => $queue->id,
+        Owner => $tester->id,
+        Cc    => 'tester at localhost',
+    );
+    diag $msg if $msg && $ENV{'TEST_VERBOSE'};
+    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';
+}
+
+
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/search_by_links.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/search_by_links.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,133 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More tests => 80;
+use RT::Test;
+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;
+}
+
+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 = 1;
+        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;
+    }
+}
+
+# simple set with "no links", "parent and child"
+ at data = (
+    { Subject => '-', },
+    { Subject => 'p', },
+    { Subject => 'c', MemberOf => -1 },
+);
+ at tickets = add_tix_from_data();
+%test = (
+    'Linked     IS NOT NULL'  => { '-' => 0, c => 1, p => 1 },
+    'Linked     IS     NULL'  => { '-' => 1, c => 0, p => 0 },
+    'LinkedTo   IS NOT NULL'  => { '-' => 0, c => 1, p => 0 },
+    'LinkedTo   IS     NULL'  => { '-' => 1, c => 0, p => 1 },
+    'LinkedFrom IS NOT NULL'  => { '-' => 0, c => 0, p => 1 },
+    'LinkedFrom IS     NULL'  => { '-' => 1, c => 1, p => 0 },
+
+    'HasMember  IS NOT NULL'  => { '-' => 0, c => 0, p => 1 },
+    'HasMember  IS     NULL'  => { '-' => 1, c => 1, p => 0 },
+    'MemberOf   IS NOT NULL'  => { '-' => 0, c => 1, p => 0 },
+    'MemberOf   IS     NULL'  => { '-' => 1, c => 0, p => 1 },
+
+    'RefersTo   IS NOT NULL'  => { '-' => 0, c => 0, p => 0 },
+    'RefersTo   IS     NULL'  => { '-' => 1, c => 1, p => 1 },
+
+    'Linked      = '. $tickets[0]->id  => { '-' => 0, c => 0, p => 0 },
+    'Linked     != '. $tickets[0]->id  => { '-' => 1, c => 1, p => 1 },
+
+    'MemberOf    = '. $tickets[1]->id  => { '-' => 0, c => 1, p => 0 },
+    'MemberOf   != '. $tickets[1]->id  => { '-' => 1, c => 0, p => 1 },
+);
+{
+    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
+ at data = (
+    { Subject => '-', },
+    { Subject => 'p', },
+    { Subject => 'rp',  RefersTo => -1 },
+    { Subject => 'c',   MemberOf => -2 },
+    { Subject => 'rc1', RefersTo => -1 },
+    { Subject => 'rc2', RefersTo => -2 },
+);
+ at tickets = add_tix_from_data();
+my $pid = $tickets[1]->id;
+%test = (
+    'RefersTo IS NOT NULL'  => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
+    'RefersTo IS     NULL'  => { '-' => 1, c => 1, p => 1, rp => 0, rc1 => 0, rc2 => 0 },
+
+    'RefersTo IS NOT NULL AND MemberOf IS NOT NULL'  => { '-' => 0, c => 0, p => 0, rp => 0, rc1 => 0, rc2 => 0 },
+    'RefersTo IS NOT NULL AND MemberOf IS     NULL'  => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
+    'RefersTo IS     NULL AND MemberOf IS NOT NULL'  => { '-' => 0, c => 1, p => 0, rp => 0, rc1 => 0, rc2 => 0 },
+    'RefersTo IS     NULL AND MemberOf IS     NULL'  => { '-' => 1, c => 0, p => 1, rp => 0, rc1 => 0, rc2 => 0 },
+
+    'RefersTo IS NOT NULL OR  MemberOf IS NOT NULL'  => { '-' => 0, c => 1, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
+    'RefersTo IS NOT NULL OR  MemberOf IS     NULL'  => { '-' => 1, c => 0, p => 1, rp => 1, rc1 => 1, rc2 => 1 },
+    'RefersTo IS     NULL OR  MemberOf IS NOT NULL'  => { '-' => 1, c => 1, p => 1, rp => 0, rc1 => 0, rc2 => 0 },
+    'RefersTo IS     NULL OR  MemberOf IS     NULL'  => { '-' => 1, c => 1, p => 1, rp => 1, rc1 => 1, rc2 => 1 },
+
+    "RefersTo  = $pid AND MemberOf  = $pid" => { '-' => 0, c => 0, p => 0, rp => 0, rc1 => 0, rc2 => 0 },
+    "RefersTo  = $pid AND MemberOf != $pid" => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 0, rc2 => 0 },
+    "RefersTo != $pid AND MemberOf  = $pid" => { '-' => 0, c => 1, p => 0, rp => 0, rc1 => 0, rc2 => 0 },
+    "RefersTo != $pid AND MemberOf != $pid" => { '-' => 1, c => 0, p => 1, rp => 0, rc1 => 1, rc2 => 1 },
+
+    "RefersTo  = $pid OR  MemberOf  = $pid" => { '-' => 0, c => 1, p => 0, rp => 1, rc1 => 0, rc2 => 0 },
+    "RefersTo  = $pid OR  MemberOf != $pid" => { '-' => 1, c => 0, p => 1, rp => 1, rc1 => 1, rc2 => 1 },
+    "RefersTo != $pid OR  MemberOf  = $pid" => { '-' => 1, c => 1, p => 1, rp => 0, rc1 => 1, rc2 => 1 },
+    "RefersTo != $pid OR  MemberOf != $pid" => { '-' => 1, c => 1, p => 1, rp => 1, rc1 => 1, rc2 => 1 },
+);
+{
+    my $tix = RT::Tickets->new($RT::SystemUser);
+    $tix->FromSQL("Queue = '". $q->id ."'");
+    is($tix->Count, $total, "found $total tickets");
+}
+run_tests();
+

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

Added: rt/branches/3.999-DANGEROUS/t/ticket/sort-by-queue.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/sort-by-queue.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+use Test::More tests => 8;
+use RT::Test;
+
+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." if $ENV{TEST_VERBOSE};
+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;
+                }
+            }
+        }
+    }
+}
+
+ at data = (
+    { Queue => $qids[0], Subject => 'z' },
+    { Queue => $qids[1], Subject => 'a' },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "Queue" },
+);
+run_tests();
+

Added: rt/branches/3.999-DANGEROUS/t/ticket/sort-by-user.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/ticket/sort-by-user.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,153 @@
+#!/usr/bin/perl
+
+use Test::More tests => 32;
+use RT::Test;
+
+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." if $ENV{TEST_VERBOSE};
+my $queue_name = "OwnerSortQueue$$";
+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 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;
+                }
+            }
+        }
+    }
+}
+
+ at data = (
+    { Subject => 'Nobody' },
+    { Subject => 'Z', Owner => $uids[0] },
+    { Subject => 'A', Owner => $uids[1] },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "Owner" },
+);
+run_tests();
+
+ at data = (
+    { Subject => 'RT' },
+    { Subject => 'Z', Creator => $uids[0] },
+    { Subject => 'A', Creator => $uids[1] },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "Creator" },
+);
+run_tests();
+
+ at data = (
+    { Subject => 'RT' },
+    { Subject => 'Z', LastUpdatedBy => $uids[0] },
+    { Subject => 'A', LastUpdatedBy => $uids[1] },
+);
+ at tickets = add_tix_from_data();
+ at test = (
+    { Order => "LastUpdatedBy" },
+);
+run_tests();
+

Added: rt/branches/3.999-DANGEROUS/t/web/cf_onqueue.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/cf_onqueue.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,67 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More tests => 14;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
+
+ok $m->login, 'logged in';
+
+diag "Create a queue CF" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( text => 'Configuration' );
+    $m->title_is(q/RT Administration/, 'admin screen');
+    $m->follow_link( text => 'Custom Fields' );
+    $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
+    $m->follow_link( text => 'Create' );
+    $m->submit_form(
+        form_name => "ModifyCustomField",
+        fields => {
+            TypeComposite => 'Freeform-1',
+            LookupType => 'RT::Queue',
+            Name => 'QueueCFTest',
+            Description => 'QueueCFTest',
+        },
+    );
+    $m->content_like( qr/Object created/, 'CF QueueCFTest created' );
+}
+
+diag "Apply the new CF globally" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( text => 'Global' );
+    $m->title_is(q!Admin/Global configuration!, 'global configuration screen');
+    $m->follow_link( url_regex => qr!Admin/Global/CustomFields/index! );
+    $m->title_is(q/Global custom field configuration/, 'global custom field configuration screen');
+    $m->follow_link( url => 'Queues.html' );
+    $m->title_is(q/Edit Custom Fields for all queues/, 'global custom field for all queues configuration screen');
+    $m->content_like( qr/QueueCFTest/, 'CF QueueCFTest displayed on page' );
+    $m->submit_form(
+        form_name => "EditCustomFields",
+        fields => {
+            'Object--CF-1' => '1',
+        },
+    );
+    $m->content_like( qr/Object created/, 'CF QueueCFTest enabled globally' );
+}
+
+diag "Edit the CF value for default queue" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( url => '/Admin/Queues/' );
+    $m->title_is(q/Admin queues/, 'queues configuration screen');
+    $m->follow_link( text => "1" );
+    $m->title_is(q/Editing Configuration for queue General/, 'default queue configuration screen');
+    $m->content_like( qr/QueueCFTest/, 'CF QueueCFTest displayed on default queue' );
+    $m->submit_form(
+        form_number => 3,
+        # The following doesn't want to works :(
+        #with_fields => { 'Object-RT::Queue-1-CustomField-1-Value' },
+        fields => {
+            'Object-RT::Queue-1-CustomField-1-Value' => 'QueueCFTest content',
+        },
+    );
+    $m->content_like( qr/QueueCFTest QueueCFTest content added/, 'Content filed in CF QueueCFTest for default queue' );
+
+}
+
+
+__END__

Added: rt/branches/3.999-DANGEROUS/t/web/dashboards-groups.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/dashboards-groups.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,99 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More tests => 36;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
+
+my $url = $m->rt_base_url;
+
+# create user and queue {{{
+my $user_obj = RT::User->new($RT::SystemUser);
+my ($ok, $msg) = $user_obj->LoadOrCreateByEmail('customer at example.com');
+ok($ok, 'ACL test user creation');
+$user_obj->SetName('customer');
+$user_obj->SetPrivileged(1);
+($ok, $msg) = $user_obj->SetPassword('customer');
+$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
+my $currentuser = RT::CurrentUser->new($user_obj);
+
+my $queue = RT::Queue->new($RT::SystemUser);
+$queue->Create(Name => 'SearchQueue'.$$);
+
+$user_obj->PrincipalObj->GrantRight(Right => $_, Object => $queue)
+    for qw/SeeQueue ShowTicket OwnTicket/;
+
+# grant the user all these rights so we can make sure that the group rights
+# are checked and not these as well
+$user_obj->PrincipalObj->GrantRight(Right => $_, Object => $RT::System)
+    for qw/SubscribeDashboard CreateOwnDashboard SeeOwnDashboard ModifyOwnDashboard DeleteOwnDashboard/;
+# }}}
+# create and test groups (outer < inner < user) {{{
+my $inner_group = RT::Group->new($RT::SystemUser);
+($ok, $msg) = $inner_group->CreateUserDefinedGroup(Name => "inner", Description => "inner group");
+ok($ok, "created inner group: $msg");
+
+my $outer_group = RT::Group->new($RT::SystemUser);
+($ok, $msg) = $outer_group->CreateUserDefinedGroup(Name => "outer", Description => "outer group");
+ok($ok, "created outer group: $msg");
+
+($ok, $msg) = $outer_group->AddMember($inner_group->PrincipalId);
+ok($ok, "added inner as a member of outer: $msg");
+
+($ok, $msg) = $inner_group->AddMember($user_obj->PrincipalId);
+ok($ok, "added user as a member of member: $msg");
+
+ok($outer_group->HasMember($inner_group->PrincipalId), "outer has inner");
+ok(!$outer_group->HasMember($user_obj->PrincipalId), "outer doesn't have user directly");
+ok($outer_group->HasMemberRecursively($inner_group->PrincipalId), "outer has inner recursively");
+ok($outer_group->HasMemberRecursively($user_obj->PrincipalId), "outer has user recursively");
+
+ok(!$inner_group->HasMember($outer_group->PrincipalId), "inner doesn't have outer");
+ok($inner_group->HasMember($user_obj->PrincipalId), "inner has user");
+ok(!$inner_group->HasMemberRecursively($outer_group->PrincipalId), "inner doesn't have outer, even recursively");
+ok($inner_group->HasMemberRecursively($user_obj->PrincipalId), "inner has user recursively");
+# }}}
+
+ok $m->login(customer => 'customer'), "logged in";
+
+$m->get_ok("$url/Dashboards");
+
+$m->follow_link_ok({text => "New dashboard"});
+$m->form_name('ModifyDashboard');
+is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id], "the only selectable privacy is user");
+$m->content_lacks('Delete', "Delete button hidden because we are creating");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'CreateGroupDashboard', Object => $inner_group);
+
+$m->follow_link_ok({text => "New dashboard"});
+$m->form_name('ModifyDashboard');
+is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id, "RT::Group-" . $inner_group->Id], "the only selectable privacies are user and inner group (not outer group)");
+$m->field("Name" => 'inner dashboard');
+$m->field("Privacy" => "RT::Group-" . $inner_group->Id);
+$m->content_lacks('Delete', "Delete button hidden because we are creating");
+
+$m->click_button(value => 'Save Changes');
+$m->content_lacks("No permission to create dashboards");
+$m->content_contains("Saved dashboard inner dashboard");
+$m->content_lacks('Delete', "Delete button hidden because we lack DeleteDashboard");
+
+my $dashboard = RT::Dashboard->new($currentuser);
+my ($id) = $m->content =~ /name="id" value="(\d+)"/;
+ok($id, "got an ID, $id");
+$dashboard->LoadById($id);
+is($dashboard->Name, "inner dashboard");
+
+is($dashboard->Privacy, 'RT::Group-' . $inner_group->Id, "correct privacy");
+is($dashboard->PossibleHiddenSearches, 0, "all searches are visible");
+
+$m->get_ok("/Dashboards/Modify.html?id=$id");
+$m->content_lacks("inner dashboard", "no SeeGroupDashboard right");
+$m->content_contains("Permission denied");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'SeeGroupDashboard', Object => $inner_group);
+$m->get_ok("/Dashboards/Modify.html?id=$id");
+$m->content_contains("inner dashboard", "we now have SeeGroupDashboard right");
+$m->content_lacks("Permission denied");
+
+$m->content_contains('Subscription', "Subscription link not hidden because we have SubscribeDashboard");
+

Added: rt/branches/3.999-DANGEROUS/t/web/dashboards.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/dashboards.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,178 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More tests => 78;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
+
+my $url = $m->rt_base_url;
+
+my $user_obj = RT::User->new($RT::SystemUser);
+my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer at example.com');
+ok($ret, 'ACL test user creation');
+$user_obj->SetName('customer');
+$user_obj->SetPrivileged(1);
+($ret, $msg) = $user_obj->SetPassword('customer');
+$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
+my $currentuser = RT::CurrentUser->new($user_obj);
+
+my $queue = RT::Queue->new($RT::SystemUser);
+$queue->Create(Name => 'SearchQueue'.$$);
+$user_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',   Object => $queue);
+$user_obj->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $queue);
+$user_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',  Object => $queue);
+
+ok $m->login(customer => 'customer'), "logged in";
+
+$m->get_ok($url."Dashboards/index.html");
+$m->content_lacks("New dashboard", "No 'new dashboard' link because we have no CreateOwnDashboard");
+
+$m->get_ok($url."Dashboards/Modify.html?Create=1");
+$m->content_contains("Permission denied");
+$m->content_lacks("Save Changes");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'ModifyOwnDashboard', Object => $RT::System);
+
+# Modify itself is no longer good enough, you need Create
+$m->get_ok($url."Dashboards/Modify.html?Create=1");
+$m->content_contains("Permission denied");
+$m->content_lacks("Save Changes");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'CreateOwnDashboard', Object => $RT::System);
+
+$m->get_ok($url."Dashboards/Modify.html?Create=1");
+$m->content_lacks("Permission denied");
+$m->content_contains("Save Changes");
+
+$m->get_ok($url."Dashboards/index.html");
+$m->content_contains("New dashboard", "'New dashboard' link because we now have ModifyOwnDashboard");
+
+$m->follow_link_ok({text => "New dashboard"});
+$m->form_name('ModifyDashboard');
+$m->field("Name" => 'different dashboard');
+$m->content_lacks('Delete', "Delete button hidden because we are creating");
+$m->click_button(value => 'Save Changes');
+$m->content_lacks("No permission to create dashboards");
+$m->content_contains("Saved dashboard different dashboard");
+$m->content_lacks('Delete', "Delete button hidden because we lack DeleteOwnDashboard");
+
+$m->get_ok($url."Dashboards/index.html");
+$m->content_lacks("different dashboard", "we lack SeeOwnDashboard");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard', Object => $RT::System);
+
+$m->get_ok($url."Dashboards/index.html");
+$m->content_contains("different dashboard", "we now have SeeOwnDashboard");
+$m->content_lacks("Permission denied");
+
+$m->follow_link_ok({text => "different dashboard"});
+$m->content_contains("Basics");
+$m->content_contains("Queries");
+$m->content_lacks("Subscription", "we don't have the SubscribeDashboard right");
+$m->content_contains("Show");
+
+$m->follow_link_ok({text => "Basics"});
+$m->content_contains("Modify the dashboard different dashboard");
+
+$m->follow_link_ok({text => "Queries"});
+$m->content_contains("Modify the queries of dashboard different dashboard");
+$m->form_name('DashboardQueries');
+$m->field('Searches-Available' => ["2-RT::System-1"]);
+$m->click_button(name => 'add');
+$m->content_contains("Dashboard updated");
+
+my $dashboard = RT::Dashboard->new($currentuser);
+my ($id) = $m->content =~ /name="id" value="(\d+)"/;
+ok($id, "got an ID, $id");
+$dashboard->LoadById($id);
+is($dashboard->Name, "different dashboard");
+
+is($dashboard->Privacy, 'RT::User-' . $user_obj->Id, "correct privacy");
+is($dashboard->PossibleHiddenSearches, 0, "all searches are visible");
+
+my @searches = $dashboard->Searches;
+is(@searches, 1, "one saved search in the dashboard");
+like($searches[0]->Name, qr/newest unowned tickets/, "correct search name");
+
+$m->form_name('DashboardQueries');
+$m->field('Searches-Available' => ["1-RT::System-1"]);
+$m->click_button(name => 'add');
+$m->content_contains("Dashboard updated");
+
+RT::Record->FlushCache if RT::Record->can('FlushCache');
+$dashboard = RT::Dashboard->new($currentuser);
+$dashboard->LoadById($id);
+
+ at searches = $dashboard->Searches;
+is(@searches, 2, "two saved searches in the dashboard");
+like($searches[0]->Name, qr/newest unowned tickets/, "correct existing search name");
+like($searches[1]->Name, qr/highest priority tickets I own/, "correct new search name");
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+$ticket->Create(
+    Queue     => $queue->Id,
+	Requestor => [ $user_obj->Name ],
+	Owner     => $user_obj,
+	Subject   => 'dashboard test',
+);
+
+$m->follow_link_ok({text => "Show"});
+$m->content_contains("20 highest priority tickets I own");
+$m->content_contains("20 newest unowned tickets");
+$m->content_lacks("Bookmarked Tickets");
+$m->content_contains("dashboard test", "ticket subject");
+
+$m->get_ok("/Dashboards/$id/This fragment left intentionally blank");
+$m->content_contains("20 highest priority tickets I own");
+$m->content_contains("20 newest unowned tickets");
+$m->content_lacks("Bookmarked Tickets");
+$m->content_contains("dashboard test", "ticket subject");
+
+$m->get_ok("/Dashboards/Subscription.html?DashboardId=$id");
+$m->form_name('SubscribeDashboard');
+$m->click_button(name => 'Save');
+$m->content_contains("Permission denied");
+
+RT::Record->FlushCache if RT::Record->can('FlushCache');
+is($user_obj->Attributes->Named('Subscription'), 0, "no subscriptions");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'SubscribeDashboard', Object => $RT::System);
+
+$m->get_ok("/Dashboards/Modify.html?id=$id");
+$m->follow_link_ok({text => "Subscription"});
+$m->content_contains("Subscribe to dashboard different dashboard");
+$m->content_contains("Unowned Tickets");
+$m->content_contains("My Tickets");
+$m->content_lacks("Bookmarked Tickets", "only dashboard queries show up");
+
+$m->form_name('SubscribeDashboard');
+$m->click_button(name => 'Save');
+$m->content_lacks("Permission denied");
+$m->content_contains("Subscribed to dashboard different dashboard");
+
+RT::Record->FlushCache if RT::Record->can('FlushCache');
+TODO: {
+    local $TODO = "some kind of caching is still happening (it works if I remove the check above)";
+    is($user_obj->Attributes->Named('Subscription'), 1, "we have a subscription");
+};
+
+$m->get_ok("/Dashboards/Modify.html?id=$id");
+$m->follow_link_ok({text => "Subscription"});
+$m->content_contains("Modify the subscription to dashboard different dashboard");
+
+$m->get_ok("/Dashboards/Modify.html?id=$id&Delete=1");
+$m->content_contains("Permission denied", "unable to delete dashboard because we lack DeleteOwnDashboard");
+
+$user_obj->PrincipalObj->GrantRight(Right => 'DeleteOwnDashboard', Object => $RT::System);
+
+$m->get_ok("/Dashboards/Modify.html?id=$id");
+$m->content_contains('Delete', "Delete button shows because we have DeleteOwnDashboard");
+
+$m->form_name('ModifyDashboard');
+$m->click_button(name => 'Delete');
+$m->content_contains("Deleted dashboard $id");
+
+$m->get("/Dashboards/Modify.html?id=$id");
+$m->content_lacks("different dashboard", "dashboard was deleted");
+$m->content_contains("Failed to load dashboard $id");
+

Added: rt/branches/3.999-DANGEROUS/t/web/quicksearch.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/quicksearch.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,52 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
+my $url = $m->rt_base_url;
+
+# merged tickets still show up in search
+my $t1 = RT::Ticket->new($RT::SystemUser);
+$t1->Create(
+    Subject   => 'base ticket'.$$,
+    Queue     => 'general',
+    Owner     => 'root',
+    Requestor => 'customsearch at localhost',
+    MIMEObj   => MIME::Entity->build(
+        From    => 'customsearch at localhost',
+        To      => 'rt at localhost',
+        Subject => 'base ticket'.$$,
+        Data    => "DON'T SEARCH FOR ME",
+    ),
+);
+ok(my $id1 = $t1->id, 'created ticket for custom search');
+
+my $t2 = RT::Ticket->new($RT::SystemUser);
+$t2->Create(
+    Subject   => 'merged away'.$$,
+    Queue     => 'general',
+    Owner     => 'root',
+    Requestor => 'customsearch at localhost',
+    MIMEObj   => MIME::Entity->build(
+        From    => 'customsearch at localhost',
+        To      => 'rt at localhost',
+        Subject => 'merged away'.$$,
+        Data    => "MERGEDAWAY",
+    ),
+);
+ok(my $id2 = $t2->id, 'created ticket for custom search');
+
+my ($ok, $msg) = $t2->MergeInto($id1);
+ok($ok, "merge: $msg");
+
+ok($m->login, 'logged in');
+
+$m->form_with_fields('q');
+$m->field(q => 'fulltext:MERGEDAWAY');
+TODO:  {
+    local $TODO = "We don't yet handle merged ticket content searches right";
+$m->content_contains('Found 1 ticket');
+}
+$m->content_contains('base ticket', "base ticket is found, not the merged-away ticket");

Added: rt/branches/3.999-DANGEROUS/t/web/rest.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/rest.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 16;
+use RT::Test;
+
+my ($baseurl, $m) = RT::Test->started_ok;
+
+for my $name ("severity", "fu()n:k/") {
+    my $cf = RT::Test->load_or_create_custom_field(
+        Name  => $name,
+        Type  => 'Freeform',
+        Queue => 'General',
+    );
+    ok($cf->Id, "created a CustomField");
+    is($cf->Name, $name, "correct CF name");
+}
+
+my $queue = RT::Test->load_or_create_queue(Name => 'General');
+ok($queue->Id, "loaded the General queue");
+
+$m->post("$baseurl/REST/1.0/ticket/new", [
+    user    => 'root',
+    pass    => 'password',
+    format  => 'l',
+]);
+
+my $text = $m->content;
+my @lines = $text =~ m{.*}g;
+shift @lines; # header
+
+# CFs aren't in the default ticket form
+push @lines, "CF-fu()n:k/: maximum"; # old style
+push @lines, "CF.{severity}: explosive"; # new style
+
+$text = join "\n", @lines;
+
+ok($text =~ s/Subject:\s*$/Subject: REST interface/m, "successfully replaced subject");
+
+$m->post("$baseurl/REST/1.0/ticket/edit", [
+    user    => 'root',
+    pass    => 'password',
+
+    content => $text,
+], Content_Type => 'form-data');
+
+my ($id) = $m->content =~ /Ticket (\d+) created/;
+ok($id, "got ticket #$id");
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+$ticket->Load($id);
+is($ticket->Id, $id, "loaded the REST-created ticket");
+is($ticket->Subject, "REST interface", "subject successfully set");
+is($ticket->FirstCustomFieldValue("fu()n:k/"), "maximum", "CF successfully set");
+
+$m->post("$baseurl/REST/1.0/search/ticket", [
+    user    => 'root',
+    pass    => 'password',
+    query   => "id=$id",
+    fields  => "Subject,CF-fu()n:k/,CF.{severity},Status",
+]);
+
+# the fields are interpreted server-side a hash (why?), so we can't depend
+# on order
+for ("id: ticket/1",
+     "Subject: REST interface",
+     "CF.{fu()n:k/}: maximum",
+     "CF.{severity}: explosive",
+     "Status: new") {
+        $m->content_contains($_);
+}
+

Added: rt/branches/3.999-DANGEROUS/t/web/unlimited_search.t
==============================================================================
--- (empty file)
+++ rt/branches/3.999-DANGEROUS/t/web/unlimited_search.t	Fri Aug 22 09:33:14 2008
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More tests => 8;
+
+use RT::Test;
+RT::Test->started_ok;
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+for ( 1 .. 75 ) {
+    $ticket->Create(
+        Subject   => 'Ticket ' . $_,
+        Queue     => 'General',
+        Owner     => 'root',
+        Requestor => 'unlimitedsearch at localhost',
+    );
+}
+
+my $agent = RT::Test::Web->new;
+ok $agent->login('root', 'password'), 'logged in as root';
+
+$agent->get_ok('/Search/Build.html');
+$agent->form_name('BuildQuery');
+$agent->field('idOp', '>');
+$agent->field('ValueOfid', '0');
+$agent->submit('AddClause');
+$agent->form_name('BuildQuery');
+$agent->field('RowsPerPage', '0');
+$agent->submit('DoSearch');
+$agent->follow_link_ok({text=>'Show Results'});
+$agent->content_like(qr/Ticket 75/);
+
+$agent->follow_link_ok({text=>'New Search'});
+$agent->form_name('BuildQuery');
+$agent->field('idOp', '>');
+$agent->field('ValueOfid', '0');
+$agent->submit('AddClause');
+$agent->form_name('BuildQuery');
+$agent->field('RowsPerPage', '50');
+$agent->submit('DoSearch');
+$agent->follow_link_ok({text=>'Bulk Update'});
+$agent->content_unlike(qr/Ticket 51/);


More information about the Rt-commit mailing list