[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.4-189-g2a320a6
? sunnavy
sunnavy at bestpractical.com
Thu Oct 21 05:47:40 EDT 2010
The branch, 3.9-trunk has been updated
via 2a320a6f68bf1c778737853d2b887c2d73fcd4d3 (commit)
via 95c6fdfe5a50fbfda11df10f58c03b46e25ca719 (commit)
via 7d9a6b5a02c8b6f29c1d6ea7902f17cb6c14f764 (commit)
via 22403d5fc8a96640db2c8383e38ccce3d469dc36 (commit)
from 2bf9cb4b1172c194d5cdbb3b20d4654be1f35106 (commit)
Summary of changes:
lib/RT/Test.pm | 85 ++++++++++++++++++++++++++++-
t/customfields/combo_cascade.t | 14 +----
t/customfields/pattern.t | 15 +----
t/mail/charsets-outgoing.t | 8 ---
t/mail/extractsubjecttag.t | 7 ---
t/ticket/cfsort-freeform-multiple.t | 47 ++++-------------
t/ticket/cfsort-freeform-single.t | 56 ++++---------------
t/ticket/search_by_cf_freeform_multiple.t | 46 ++++------------
t/ticket/search_by_cf_freeform_single.t | 30 ++--------
t/ticket/search_by_links.t | 28 +++-------
t/ticket/search_by_watcher.t | 29 ++--------
t/ticket/sort-by-queue.t | 18 +------
t/ticket/sort-by-user.t | 37 +++----------
13 files changed, 151 insertions(+), 269 deletions(-)
- Log -----------------------------------------------------------------
commit 22403d5fc8a96640db2c8383e38ccce3d469dc36
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 21 15:03:14 2010 +0800
move parse_mail to Test.pm
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index a098dfb..6a92544 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -75,7 +75,7 @@ wrap 'HTTP::Request::Common::form_data',
};
-our @EXPORT = qw(is_empty diag);
+our @EXPORT = qw(is_empty diag parse_mail);
our ($port, $dbname);
our @SERVERS;
@@ -1369,6 +1369,15 @@ sub diag {
goto \&Test::More::diag;
}
+sub parse_mail {
+ my $mail = shift;
+ require RT::EmailParser;
+ my $parser = RT::EmailParser->new;
+ $parser->ParseMIMEEntityFromScalar( $mail );
+ return $parser->Entity;
+}
+
+
END {
my $Test = RT::Test->builder;
return if $Test->{Original_Pid} != $$;
diff --git a/t/mail/charsets-outgoing.t b/t/mail/charsets-outgoing.t
index 3fcbfc1..59af27e 100644
--- a/t/mail/charsets-outgoing.t
+++ b/t/mail/charsets-outgoing.t
@@ -317,11 +317,3 @@ foreach my $set ( 'ru', 'latin1' ) {
} # subject tag set
-sub parse_mail {
- my $mail = shift;
- require RT::EmailParser;
- my $parser = RT::EmailParser->new;
- $parser->ParseMIMEEntityFromScalar( $mail );
- return $parser->Entity;
-}
-
diff --git a/t/mail/extractsubjecttag.t b/t/mail/extractsubjecttag.t
index 24fc8c2..cf1c667 100644
--- a/t/mail/extractsubjecttag.t
+++ b/t/mail/extractsubjecttag.t
@@ -88,10 +88,3 @@ EOF
}
-sub parse_mail {
- my $mail = shift;
- require RT::EmailParser;
- my $parser = RT::EmailParser->new;
- $parser->ParseMIMEEntityFromScalar( $mail );
- return $parser->Entity;
-}
commit 7d9a6b5a02c8b6f29c1d6ea7902f17cb6c14f764
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 21 15:16:59 2010 +0800
move works and fails to Test.pm
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 6a92544..44ecb92 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -75,7 +75,7 @@ wrap 'HTTP::Request::Common::form_data',
};
-our @EXPORT = qw(is_empty diag parse_mail);
+our @EXPORT = qw(is_empty diag parse_mail works fails);
our ($port, $dbname);
our @SERVERS;
@@ -1377,6 +1377,13 @@ sub parse_mail {
return $parser->Entity;
}
+sub works {
+ Test::More::ok($_[0], $_[1] || 'This works');
+}
+
+sub fails {
+ Test::More::ok(!$_[0], $_[1] || 'This should fail');
+}
END {
my $Test = RT::Test->builder;
diff --git a/t/customfields/combo_cascade.t b/t/customfields/combo_cascade.t
index b1bcdf5..c24fcd3 100644
--- a/t/customfields/combo_cascade.t
+++ b/t/customfields/combo_cascade.t
@@ -4,9 +4,6 @@ use strict;
use RT::Test nodata => 1, tests => 11;
-sub fails { ok(!$_[0], "This should fail: $_[1]") }
-sub works { ok($_[0], $_[1] || 'This works') }
-
sub new (*) {
my $class = shift;
return $class->new(RT->SystemUser);
diff --git a/t/customfields/pattern.t b/t/customfields/pattern.t
index 3e5f444..ce0e04b 100644
--- a/t/customfields/pattern.t
+++ b/t/customfields/pattern.t
@@ -5,10 +5,6 @@ use strict;
use RT;
use RT::Test nodata => 1, tests => 17;
-
-sub fails { ok(!$_[0], "This should fail: $_[1]") }
-sub works { ok($_[0], $_[1] || 'This works') }
-
sub new (*) {
my $class = shift;
return $class->new(RT->SystemUser);
commit 95c6fdfe5a50fbfda11df10f58c03b46e25ca719
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 21 15:19:38 2010 +0800
remove new() sub: kinda useless
diff --git a/t/customfields/combo_cascade.t b/t/customfields/combo_cascade.t
index c24fcd3..28eee45 100644
--- a/t/customfields/combo_cascade.t
+++ b/t/customfields/combo_cascade.t
@@ -4,22 +4,17 @@ use strict;
use RT::Test nodata => 1, tests => 11;
-sub new (*) {
- my $class = shift;
- return $class->new(RT->SystemUser);
-}
-
-my $q = new(RT::Queue);
+my $q = RT::Queue->new($RT::SystemUser);
works($q->Create(Name => "CF-Pattern-".$$));
-my $cf = new(RT::CustomField);
+my $cf = RT::CustomField->new($RT::SystemUser);
my @cf_args = (Name => $q->Name, Type => 'Combobox', Queue => $q->id);
works($cf->Create(@cf_args));
# Set some CFVs with Category markers
-my $t = new(RT::Ticket);
+my $t = RT::Ticket->new($RT::SystemUser);
my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test');
works($id,$msg);
diff --git a/t/customfields/pattern.t b/t/customfields/pattern.t
index ce0e04b..7d1090f 100644
--- a/t/customfields/pattern.t
+++ b/t/customfields/pattern.t
@@ -5,21 +5,16 @@ use strict;
use RT;
use RT::Test nodata => 1, tests => 17;
-sub new (*) {
- my $class = shift;
- return $class->new(RT->SystemUser);
-}
-
-my $q = new(RT::Queue);
+my $q = RT::Queue->new($RT::SystemUser);
works($q->Create(Name => "CF-Pattern-".$$));
-my $cf = new(RT::CustomField);
+my $cf = RT::CustomField->new($RT::SystemUser);
my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id, MaxValues => 1);
fails($cf->Create(@cf_args, Pattern => ')))bad!regex((('));
works($cf->Create(@cf_args, Pattern => 'good regex'));
-my $t = new(RT::Ticket);
+my $t = RT::Ticket->new($RT::SystemUser);
my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test');
works($id,$msg);
commit 2a320a6f68bf1c778737853d2b887c2d73fcd4d3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 21 17:46:35 2010 +0800
abstract create_tickets and move it to Test.pm
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 44ecb92..87badb6 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -75,7 +75,7 @@ wrap 'HTTP::Request::Common::form_data',
};
-our @EXPORT = qw(is_empty diag parse_mail works fails);
+our @EXPORT = qw(is_empty diag parse_mail works fails create_tickets);
our ($port, $dbname);
our @SERVERS;
@@ -1385,6 +1385,73 @@ sub fails {
Test::More::ok(!$_[0], $_[1] || 'This should fail');
}
+sub create_tickets {
+ my $default_queue;
+ if ( $_[0] && ( !ref $_[0] || ref $_[0] eq 'RT::Queue' ) ) {
+ $default_queue = shift;
+ }
+ else {
+ $default_queue = 'General';
+ }
+
+ my @res;
+
+ while (my $data = shift @_) {
+ my $ticket = RT::Ticket->new(RT->SystemUser);
+ my %args = %$data;
+ my %links;
+
+ # link tickets
+ for my $type ( keys %RT::Ticket::LINKTYPEMAP ) {
+ my $index = delete $args{$type};
+ next unless defined $index;
+ $links{$type} = $res[ $index ]->id;
+ }
+
+ my ( $id, undef, $msg ) = $ticket->Create(
+ Queue => $default_queue,
+ %args,
+ %links,
+ );
+
+ # hackish, but simpler
+ if ( $args{'LastUpdatedBy'} ) {
+ $ticket->__Set( Field => 'LastUpdatedBy', Value => $args{'LastUpdatedBy'} );
+ }
+
+ Test::More::ok( $id, "ticket created" ) or diag("error: $msg");
+
+ for my $field ( keys %args ) {
+ #TODO check links and watchers
+
+ if ( $field =~ /CustomField-(\d+)/ ) {
+ my $cf = $1;
+ my $got = join ',', do {
+ my $vals = $ticket->CustomFieldValues($cf);
+ $vals->OrderBy( Field => 'id', ORDER => 'ASC' );
+ my @tmp;
+ while ( my $v = $vals->Next ) { push @tmp, $v->Content }
+ @tmp;
+ };
+
+ Test::More::is(
+ $got,
+ ref $args{$field}
+ ? join( ',', @{ $args{$field} } )
+ : $args{$field},
+ 'correct CF values'
+ );
+ }
+ else {
+ next unless !ref $args{$field} && $ticket->can($field);
+ Test::More::is( $ticket->$field, $args{$field}, "$field is correct" );
+ }
+ }
+ push @res, $ticket;
+ }
+ return @res;
+}
+
END {
my $Test = RT::Test->builder;
return if $Test->{Original_Pid} != $$;
diff --git a/t/ticket/cfsort-freeform-multiple.t b/t/ticket/cfsort-freeform-multiple.t
index 539ce91..4319670 100644
--- a/t/ticket/cfsort-freeform-multiple.t
+++ b/t/ticket/cfsort-freeform-multiple.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test nodata => 1, tests => 24;
+use RT::Test nodata => 1, tests => 29;
use strict;
use warnings;
@@ -36,34 +36,7 @@ my $cf;
ok($ret, "Custom Field Order created");
}
-my ($total, @data, @tickets, @test) = (0, ());
-
-sub add_tix_from_data {
- my @res = ();
- @data = sort { rand(100) <=> rand(100) } @data;
- while (@data) {
- my $t = RT::Ticket->new(RT->SystemUser);
- my %args = %{ shift(@data) };
- my @values = ();
- if ( exists $args{'CF'} && ref $args{'CF'} ) {
- @values = @{ delete $args{'CF'} };
- } elsif ( exists $args{'CF'} ) {
- @values = (delete $args{'CF'});
- }
- $args{ 'CustomField-'. $cf->id } = \@values
- if @values;
- my $subject = join(",", sort @values) || '-';
- my ( $id, undef $msg ) = $t->Create(
- %args,
- Queue => $queue->id,
- Subject => $subject,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- push @res, $t;
- $total++;
- }
- return @res;
-}
+my (@data, @tickets, @test) = (0, ());
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -112,11 +85,11 @@ sub run_tests {
}
@data = (
- { },
- { CF => ['b', 'd'] },
- { CF => ['a', 'c'] },
+ { Subject => '-' },
+ { Subject => 'b-d', 'CustomField-' . $cf->id => ['b', 'd'] },
+ { Subject => 'a-c', 'CustomField-' . $cf->id => ['a', 'c'] },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
@@ -124,11 +97,11 @@ sub run_tests {
run_tests();
@data = (
- { CF => ['m', 'a'] },
- { CF => ['m'] },
- { CF => ['m', 'o'] },
+ { Subject => 'm-a', 'CustomField-' . $cf->id => ['m', 'a'] },
+ { Subject => 'm', 'CustomField-' . $cf->id => ['m'] },
+ { Subject => 'm-o', 'CustomField-' . $cf->id => ['m', 'o'] },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Order => "CF.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
{ Order => "CF.$queue_name.{$cf_name}", Query => "CF.{$cf_name} = 'm'" },
diff --git a/t/ticket/cfsort-freeform-single.t b/t/ticket/cfsort-freeform-single.t
index e29d64e..6c2c03c 100644
--- a/t/ticket/cfsort-freeform-single.t
+++ b/t/ticket/cfsort-freeform-single.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test nodata => 1, tests => 57;
+use RT::Test nodata => 1, tests => 61;
use strict;
use warnings;
@@ -41,39 +41,6 @@ diag "create a CF";
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 ) {
@@ -121,11 +88,12 @@ sub run_tests {
}
@data = (
- { },
- { CF => 'a' },
- { CF => 'b' },
+ { Subject => '-' },
+ { Subject => 'a', 'CustomField-' . $CF{CF}{obj}->id => 'a' },
+ { Subject => 'b', 'CustomField-' . $CF{CF}{obj}->id => 'b' },
);
- at tickets = add_tix_from_data();
+
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
@@ -133,11 +101,11 @@ sub run_tests {
run_tests();
@data = (
- { },
- { CF => 'aa' },
- { CF => 'ab' },
+ { Subject => '-' },
+ { Subject => 'aa', 'CustomField-' . $CF{CF}{obj}->id => 'aa' },
+ { Subject => 'bb', 'CustomField-' . $CF{CF}{obj}->id => 'bb' },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.{$cf_name}" },
{ Query => "CF.{$cf_name} LIKE 'a'", Order => "CF.$queue_name.{$cf_name}" },
@@ -150,7 +118,7 @@ run_tests();
{ Subject => 'b', CF => 'b' },
{ Subject => 'c', CF => 'c' },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Query => "CF.{$cf_name} != 'c'", Order => "CF.{$cf_name}" },
{ Query => "CF.{$cf_name} != 'c'", Order => "CF.$queue_name.{$cf_name}" },
@@ -178,7 +146,7 @@ diag "create another CF";
{ Subject => 'b', CF => 'b', AnotherCF => 'ya' },
{ Subject => 'c', CF => 'c', AnotherCF => 'xa' },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($queue->id, sort { rand(100) <=> rand(100) } @data);
@test = (
{ Order => "CF.{$cf_name}" },
{ Order => "CF.$queue_name.{$cf_name}" },
diff --git a/t/ticket/search_by_cf_freeform_multiple.t b/t/ticket/search_by_cf_freeform_multiple.t
index fd9eb67..194b493 100644
--- a/t/ticket/search_by_cf_freeform_multiple.t
+++ b/t/ticket/search_by_cf_freeform_multiple.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => 105;
+use RT::Test nodata => 1, tests => 104;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
@@ -25,34 +25,6 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
my ($total, @data, @tickets, %test) = (0, ());
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my %args = %{ shift(@data) };
- my @cf_value = $args{'Subject'} ne '-'? (split /(?=.)/, $args{'Subject'}) : ();
- diag "vals: ". join ', ', @cf_value;
- my $t = RT::Ticket->new(RT->SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %args,
- "CustomField-$cf_id" => \@cf_value,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
-
- my $got = join ',', sort do {
- my $vals = $t->CustomFieldValues( $cf_name );
- my @tmp;
- while (my $v = $vals->Next ) { push @tmp, $v->Content }
- @tmp;
- };
-
- is( $got, join( ',', sort @cf_value), 'correct CF values' );
- push @res, $t;
- $total++;
- }
- return @res;
-}
-
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
foreach my $key ( sort keys %test ) {
@@ -79,12 +51,12 @@ sub run_tests {
@data = (
{ Subject => '-' },
- { Subject => 'x' },
- { Subject => 'y' },
- { Subject => 'z' },
- { Subject => 'xy' },
- { Subject => 'xz' },
- { Subject => 'yz' },
+ { Subject => 'x', "CustomField-$cf_id" => 'x', },
+ { Subject => 'y', "CustomField-$cf_id" => 'y', },
+ { Subject => 'z', "CustomField-$cf_id" => 'z', },
+ { Subject => 'xy', "CustomField-$cf_id" => [ 'x', 'y' ], },
+ { Subject => 'xz', "CustomField-$cf_id" => [ 'x', 'z' ], },
+ { Subject => 'yz', "CustomField-$cf_id" => [ 'y', 'z' ], },
);
%test = (
"CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0, xy => 0, xz => 0, yz => 0 },
@@ -142,7 +114,9 @@ sub run_tests {
"'CF.$queue.{$cf_id}' = 'x' OR 'CF.$queue.{$cf_id}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 },
"'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1, xy => 1, xz => 1, yz => 1 },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($q->id, @data);
+$total = scalar @tickets;
+
{
my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
diff --git a/t/ticket/search_by_cf_freeform_single.t b/t/ticket/search_by_cf_freeform_single.t
index d0ff9af..e8c5e42 100644
--- a/t/ticket/search_by_cf_freeform_single.t
+++ b/t/ticket/search_by_cf_freeform_single.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => 99;
+use RT::Test nodata => 1, tests => 98;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
@@ -25,25 +25,6 @@ my ($cf_name, $cf_id, $cf) = ("Test", 0, undef);
my ($total, @data, @tickets, %test) = (0, ());
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my %args = %{ shift(@data) };
- my $cf_value = $args{'Subject'} ne '-'? $args{'Subject'} : undef;
- my $t = RT::Ticket->new(RT->SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %args,
- "CustomField-$cf_id" => $cf_value,
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- is( $t->FirstCustomFieldValue( $cf_name ), $cf_value, 'correct value' );
- push @res, $t;
- $total++;
- }
- return @res;
-}
-
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
foreach my $key ( sort keys %test ) {
@@ -70,9 +51,9 @@ sub run_tests {
@data = (
{ Subject => '-' },
- { Subject => 'x' },
- { Subject => 'y' },
- { Subject => 'z' },
+ { Subject => 'x', "CustomField-$cf_id" => 'x', },
+ { Subject => 'y', "CustomField-$cf_id" => 'y', },
+ { Subject => 'z', "CustomField-$cf_id" => 'z', },
);
%test = (
"CF.{$cf_id} IS NULL" => { '-' => 1, x => 0, y => 0, z => 0 },
@@ -131,7 +112,8 @@ sub run_tests {
"'CF.$queue.{$cf_name}' = 'x' OR 'CF.$queue.{$cf_name}' IS NOT NULL" => { '-' => 0, x => 1, y => 1, z => 1 },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets($q->id, @data);
+$total = scalar @tickets;
{
my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
diff --git a/t/ticket/search_by_links.t b/t/ticket/search_by_links.t
index fc311d0..dd41ce1 100644
--- a/t/ticket/search_by_links.t
+++ b/t/ticket/search_by_links.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => 80;
+use RT::Test nodata => 1, tests => 86;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
@@ -11,23 +11,6 @@ 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 ) {
@@ -58,7 +41,10 @@ sub run_tests {
{ Subject => 'p', },
{ Subject => 'c', MemberOf => -1 },
);
- at tickets = add_tix_from_data();
+
+ at tickets = create_tickets( $q->id, @data );
+$total = scalar @tickets;
+
%test = (
'Linked IS NOT NULL' => { '-' => 0, c => 1, p => 1 },
'Linked IS NULL' => { '-' => 1, c => 0, p => 0 },
@@ -97,7 +83,9 @@ run_tests();
{ Subject => 'rc1', RefersTo => -1 },
{ Subject => 'rc2', RefersTo => -2 },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets( $q->id, @data );
+$total += scalar @tickets;
+
my $pid = $tickets[1]->id;
%test = (
'RefersTo IS NOT NULL' => { '-' => 0, c => 0, p => 0, rp => 1, rc1 => 1, rc2 => 1 },
diff --git a/t/ticket/search_by_watcher.t b/t/ticket/search_by_watcher.t
index 171eb23..691fd8e 100644
--- a/t/ticket/search_by_watcher.t
+++ b/t/ticket/search_by_watcher.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test nodata => 1, tests => 1974;
+use RT::Test nodata => 1, tests => 1975;
use RT::Ticket;
my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
@@ -12,21 +12,6 @@ my $queue = $q->Name;
my ($total, @data, @tickets, @test, @conditions) = (0, ());
-sub add_tix_from_data {
- my @res = ();
- while (@data) {
- my $t = RT::Ticket->new(RT->SystemUser);
- my ( $id, undef $msg ) = $t->Create(
- Queue => $q->id,
- %{ shift(@data) },
- );
- ok( $id, "ticket created" ) or diag("error: $msg");
- push @res, $t;
- $total++;
- }
- return @res;
-}
-
sub generate_tix {
my @list = (
[],
@@ -49,7 +34,7 @@ sub generate_tix {
};
}
}
- return add_tix_from_data();
+ return create_tickets($q->id, @data);
}
sub run_tests {
@@ -193,6 +178,7 @@ sub run_auto_tests {
);
@tickets = generate_tix();
+$total += scalar @tickets;
{
my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue'");
@@ -236,13 +222,12 @@ my $nobody = RT::Nobody();
# bug #6898 at rt3.fsck.com
# and http://marc.theaimsgroup.com/?l=rt-devel&m=112662934627236&w=2
@data = ( { Subject => 'not a ticket' } );
- my($t) = add_tix_from_data();
+ my($t) = create_tickets( $q->id,, @data );
$t->_Set( Field => 'Type',
Value => 'not a ticket',
CheckACL => 0,
RecordTransaction => 0,
);
- $total--;
my $tix = RT::Tickets->new(RT->SystemUser);
$tix->FromSQL("Queue = '$queue' AND Owner = 'Nobody'");
@@ -262,16 +247,14 @@ my $nobody = RT::Nobody();
$u->LoadOrCreateByEmail('alpha at e.com');
ok($u->id, "loaded user");
@data = ( { Subject => '4', Owner => $u->id } );
- my($t) = add_tix_from_data();
- is( $t->Owner, $u->id, "created ticket with custom owner" );
+ my($t) = create_tickets($q->id, @data);
my $u_alpha_id = $u->id;
$u = RT::User->new( RT->SystemUser );
$u->LoadOrCreateByEmail('bravo at e.com');
ok($u->id, "loaded user");
@data = ( { Subject => '5', Owner => $u->id } );
- ($t) = add_tix_from_data();
- is( $t->Owner, $u->id, "created ticket with custom owner" );
+ ($t) = create_tickets($q->id, @data);
my $u_bravo_id = $u->id;
my $tix = RT::Tickets->new(RT->SystemUser);
diff --git a/t/ticket/sort-by-queue.t b/t/ticket/sort-by-queue.t
index 84a57a1..15206d5 100644
--- a/t/ticket/sort-by-queue.t
+++ b/t/ticket/sort-by-queue.t
@@ -29,21 +29,7 @@ foreach my $name ( qw(sort-by-queue-Z sort-by-queue-A) ) {
push @qids, $queue->id;
}
-my ($total, @data, @tickets, @test) = (0, ());
-
-sub add_tix_from_data {
- my @res = ();
- @data = sort { rand(100) <=> rand(100) } @data;
- while (@data) {
- my $t = RT::Ticket->new(RT->SystemUser);
- my %args = %{ shift(@data) };
- my ( $id, undef, $msg ) = $t->Create( %args );
- ok( $id, "ticket created" ) or diag("error: $msg");
- push @res, $t;
- $total++;
- }
- return @res;
-}
+my (@data, @tickets, @test) = (0, ());
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -92,7 +78,7 @@ sub run_tests {
{ Queue => $qids[0], Subject => 'z' },
{ Queue => $qids[1], Subject => 'a' },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets( sort { rand(100) <=> rand(100) } @data );
@test = (
{ Order => "Queue" },
);
diff --git a/t/ticket/sort-by-user.t b/t/ticket/sort-by-user.t
index 17df0ba..ca0e085 100644
--- a/t/ticket/sort-by-user.t
+++ b/t/ticket/sort-by-user.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-use RT::Test nodata => 1, tests => 32;
+use RT::Test nodata => 1, tests => 34;
use strict;
use warnings;
@@ -47,32 +47,7 @@ foreach my $u (qw(Z A)) {
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;
-}
+my (@data, @tickets, @test) = (0, ());
sub run_tests {
my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
@@ -122,7 +97,9 @@ sub run_tests {
{ Subject => 'Z', Owner => $uids[0] },
{ Subject => 'A', Owner => $uids[1] },
);
- at tickets = add_tix_from_data();
+
+ at tickets = create_tickets( $queue->id, @data );
+
@test = (
{ Order => "Owner" },
);
@@ -133,7 +110,7 @@ run_tests();
{ Subject => 'Z', Creator => $uids[0] },
{ Subject => 'A', Creator => $uids[1] },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets( $queue->id, @data );
@test = (
{ Order => "Creator" },
);
@@ -144,7 +121,7 @@ run_tests();
{ Subject => 'Z', LastUpdatedBy => $uids[0] },
{ Subject => 'A', LastUpdatedBy => $uids[1] },
);
- at tickets = add_tix_from_data();
+ at tickets = create_tickets( $queue->id, @data );
@test = (
{ Order => "LastUpdatedBy" },
);
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list