[Rt-commit] r11416 - rt/branches/3.6-RELEASE/lib/t/regression
ruz at bestpractical.com
ruz at bestpractical.com
Wed Apr 2 22:24:44 EDT 2008
Author: ruz
Date: Wed Apr 2 22:24:44 2008
New Revision: 11416
Added:
rt/branches/3.6-RELEASE/lib/t/regression/23cfsort-freeform-multiple.t
rt/branches/3.6-RELEASE/lib/t/regression/23cfsort-freeform-single.t
Modified:
rt/branches/3.6-RELEASE/lib/t/regression/23cfsort.t
Log:
* update 23cfsort tests and add new
Added: rt/branches/3.6-RELEASE/lib/t/regression/23cfsort-freeform-multiple.t
==============================================================================
--- (empty file)
+++ rt/branches/3.6-RELEASE/lib/t/regression/23cfsort-freeform-multiple.t Wed Apr 2 22:24:44 2008
@@ -0,0 +1,137 @@
+#!/usr/bin/perl
+
+use Test::More tests => 24;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+# Test Sorting by custom fields.
+
+diag "Create a queue to test with.";
+my $queue_name = "CFSortQueue-$$";
+my $queue;
+{
+ $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $queue_name,
+ Description => 'queue for custom field sort testing'
+ );
+ ok($ret, "$queue_name - test queue creation. $msg");
+}
+
+diag "create a CF\n";
+my $cf_name = "Order$$";
+my $cf;
+{
+ $cf = RT::CustomField->new( $RT::SystemUser );
+ my ($ret, $msg) = $cf->Create(
+ Name => $cf_name,
+ Queue => $queue->id,
+ Type => 'FreeformMultiple',
+ );
+ ok($ret, "Custom Field Order created");
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+ my @values = ();
+ if ( exists $args{'CF'} && ref $args{'CF'} ) {
+ @values = @{ delete $args{'CF'} };
+ } elsif ( exists $args{'CF'} ) {
+ @values = (delete $args{'CF'});
+ }
+ $args{ 'CustomField-'. $cf->id } = \@values
+ if @values;
+ my $subject = join(",", sort @values) || '-';
+ my ( $id, undef $msg ) = $t->Create(
+ %args,
+ Queue => $queue->id,
+ Subject => $subject,
+ );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+ 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.6-RELEASE/lib/t/regression/23cfsort-freeform-single.t
==============================================================================
--- (empty file)
+++ rt/branches/3.6-RELEASE/lib/t/regression/23cfsort-freeform-single.t Wed Apr 2 22:24:44 2008
@@ -0,0 +1,149 @@
+#!/usr/bin/perl
+
+use Test::More tests => 36;
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+use strict;
+use warnings;
+
+use RT::Tickets;
+use RT::Queue;
+use RT::CustomField;
+
+# Test Sorting by FreeformSingle custom field.
+
+diag "Create a queue to test with.";
+my $queue_name = "CFSortQueue$$";
+my $queue;
+{
+ $queue = RT::Queue->new( $RT::SystemUser );
+ my ($ret, $msg) = $queue->Create(
+ Name => $queue,
+ Description => 'queue for custom field sort testing'
+ );
+ ok($ret, "$queue test queue creation. $msg");
+}
+
+diag "create a CF\n";
+my $cf_name = "Order$$";
+my $cf;
+{
+ $cf = RT::CustomField->new( $RT::SystemUser );
+ my ($ret, $msg) = $cf->Create(
+ Name => $cf_name,
+ Queue => $queue->id,
+ Type => 'FreeformSingle',
+ );
+ ok($ret, "Custom Field Order created");
+}
+
+my ($total, @data, @tickets, @test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ @data = sort { rand(100) <=> rand(100) } @data;
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+ my @values = ();
+ if ( exists $args{'CF'} && ref $args{'CF'} ) {
+ @values = @{ delete $args{'CF'} };
+ } elsif ( exists $args{'CF'} ) {
+ @values = (delete $args{'CF'});
+ }
+ $args{ 'CustomField-'. $cf->id } = \@values
+ if @values;
+ my $subject = join(",", sort @values) || '-';
+ my ( $id, undef $msg ) = $t->Create(
+ %args,
+ Queue => $queue->id,
+ Subject => $subject,
+ );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $test ( @test ) {
+ my $query = join " AND ", map "( $_ )", grep defined && length,
+ $query_prefix, $test->{'Query'};
+
+ foreach my $order (qw(ASC DESC)) {
+ my $error = 0;
+ my $tix = RT::Tickets->new( $RT::SystemUser );
+ $tix->FromSQL( $query );
+ $tix->OrderBy( FIELD => $test->{'Order'}, ORDER => $order );
+
+ ok($tix->Count, "found ticket(s)")
+ or $error = 1;
+
+ my ($order_ok, $last) = (1, $order eq 'ASC'? '-': 'zzzzzz');
+ while ( my $t = $tix->Next ) {
+ my $tmp;
+ if ( $order eq 'ASC' ) {
+ $tmp = ((split( /,/, $last))[0] cmp (split( /,/, $t->Subject))[0]);
+ } else {
+ $tmp = -((split( /,/, $last))[-1] cmp (split( /,/, $t->Subject))[-1]);
+ }
+ if ( $tmp > 0 ) {
+ $order_ok = 0; last;
+ }
+ $last = $t->Subject;
+ }
+
+ ok( $order_ok, "$order order of tickets is good" )
+ or $error = 1;
+
+ if ( $error ) {
+ diag "Wrong SQL query:". $tix->BuildSelectQuery;
+ $tix->GotoFirstItem;
+ while ( my $t = $tix->Next ) {
+ diag sprintf "%02d - %s", $t->id, $t->Subject;
+ }
+ }
+ }
+ }
+}
+
+ 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();
Modified: rt/branches/3.6-RELEASE/lib/t/regression/23cfsort.t
==============================================================================
--- rt/branches/3.6-RELEASE/lib/t/regression/23cfsort.t (original)
+++ rt/branches/3.6-RELEASE/lib/t/regression/23cfsort.t Wed Apr 2 22:24:44 2008
@@ -16,6 +16,8 @@
# Test Sorting by custom fields.
+# TODO: it's hard to read this file, conver to new style,
+# for example look at 23cfsort-freeform-single.t
# ---- Create a queue to test with.
my $queue = "CFSortQueue-$$";
@@ -116,20 +118,14 @@
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DESC' );
diag $tx->BuildSelectQuery;
is($tx->Count,2);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 2);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'ASC' );
diag $tx->BuildSelectQuery;
is($tx->Count,2);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 2, 1);
-}
# Add a new ticket, to test sorting on multiple columns.
my $t3 = RT::Ticket->new($RT::SystemUser);
@@ -148,10 +144,7 @@
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 3, 2, 1);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
@@ -160,10 +153,7 @@
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 2, 3);
-}
# Reverse the order of the secondary column, which changes the order
# of the first two tickets.
@@ -174,10 +164,7 @@
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 2, 3, 1);
-}
$tx = new RT::Tickets( $RT::SystemUser );
$tx->FromSQL(qq[queue="$queue"] );
@@ -186,7 +173,5 @@
{ FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' },
);
is($tx->Count,3);
-TODO: {
- local $TODO = 'order by CF fail';
check_order( $tx, 1, 3, 2);
-}
+
More information about the Rt-commit
mailing list