summaryrefslogtreecommitdiff
path: root/rt/t/shredder
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
committerIvan Kohler <ivan@freeside.biz>2012-06-07 00:56:06 -0700
commit43a06151e47d2c59b833cbd8c26d97865ee850b6 (patch)
tree42c51d94e7fa265461b508d061562be204ccc2c1 /rt/t/shredder
parent6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff)
starting to work...
Diffstat (limited to 'rt/t/shredder')
-rw-r--r--rt/t/shredder/00load.t2
-rw-r--r--rt/t/shredder/01basics.t4
-rw-r--r--rt/t/shredder/01ticket.t12
-rw-r--r--rt/t/shredder/02group_member.t22
-rw-r--r--rt/t/shredder/02queue.t28
-rw-r--r--rt/t/shredder/02template.t14
-rw-r--r--rt/t/shredder/02user.t10
-rw-r--r--rt/t/shredder/03plugin.t6
-rw-r--r--rt/t/shredder/03plugin_summary.t4
-rw-r--r--rt/t/shredder/03plugin_tickets.t31
-rw-r--r--rt/t/shredder/03plugin_users.t4
-rw-r--r--rt/t/shredder/utils.pl117
12 files changed, 105 insertions, 149 deletions
diff --git a/rt/t/shredder/00load.t b/rt/t/shredder/00load.t
index 1e06261bc..21d5ef765 100644
--- a/rt/t/shredder/00load.t
+++ b/rt/t/shredder/00load.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use File::Spec;
use Test::More tests => 11;
-use RT::Test ();
+use RT::Test nodb => 1;
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/rt/t/shredder/01basics.t b/rt/t/shredder/01basics.t
index 450f2df8c..99e66c786 100644
--- a/rt/t/shredder/01basics.t
+++ b/rt/t/shredder/01basics.t
@@ -18,11 +18,11 @@ init_db();
create_savepoint();
use RT::Tickets;
-my $ticket = RT::Ticket->new( $RT::SystemUser );
+my $ticket = RT::Ticket->new( RT->SystemUser );
my ($id) = $ticket->Create( Subject => 'test', Queue => 1 );
ok( $id, "created new ticket" );
-$ticket = RT::Ticket->new( $RT::SystemUser );
+$ticket = RT::Ticket->new( RT->SystemUser );
my ($status, $msg) = $ticket->Load( $id );
ok( $id, "load ticket" ) or diag( "error: $msg" );
diff --git a/rt/t/shredder/01ticket.t b/rt/t/shredder/01ticket.t
index 5625b985d..7dff16df3 100644
--- a/rt/t/shredder/01ticket.t
+++ b/rt/t/shredder/01ticket.t
@@ -22,13 +22,13 @@ use RT::Ticket;
use RT::Tickets;
{
- my $ticket = RT::Ticket->new( $RT::SystemUser );
+ my $ticket = RT::Ticket->new( RT->SystemUser );
my ($id) = $ticket->Create( Subject => 'test', Queue => 1 );
ok( $id, "created new ticket" );
$ticket->Delete;
is( $ticket->Status, 'deleted', "successfuly changed status" );
- my $tickets = RT::Tickets->new( $RT::SystemUser );
+ my $tickets = RT::Tickets->new( RT->SystemUser );
$tickets->{'allow_deleted_search'} = 1;
$tickets->LimitStatus( VALUE => 'deleted' );
is( $tickets->Count, 1, "found one deleted ticket" );
@@ -40,12 +40,12 @@ use RT::Tickets;
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
{
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($pid) = $parent->Create( Subject => 'test', Queue => 1 );
ok( $pid, "created new ticket" );
create_savepoint('parent_ticket');
- my $child = RT::Ticket->new( $RT::SystemUser );
+ my $child = RT::Ticket->new( RT->SystemUser );
my ($cid) = $child->Create( Subject => 'test', Queue => 1 );
ok( $cid, "created new ticket" );
@@ -62,14 +62,14 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
{
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($pid) = $parent->Create( Subject => 'test', Queue => 1 );
ok( $pid, "created new ticket" );
my ($status, $msg) = $parent->Delete;
ok( $status, 'deleted parent ticket');
create_savepoint('parent_ticket');
- my $child = RT::Ticket->new( $RT::SystemUser );
+ my $child = RT::Ticket->new( RT->SystemUser );
my ($cid) = $child->Create( Subject => 'test', Queue => 1 );
ok( $cid, "created new ticket" );
diff --git a/rt/t/shredder/02group_member.t b/rt/t/shredder/02group_member.t
index b68557a8b..9f8a6c6e3 100644
--- a/rt/t/shredder/02group_member.t
+++ b/rt/t/shredder/02group_member.t
@@ -18,12 +18,12 @@ init_db();
### nested membership check
{
create_savepoint('clean');
- my $pgroup = RT::Group->new( $RT::SystemUser );
+ my $pgroup = RT::Group->new( RT->SystemUser );
my ($pgid) = $pgroup->CreateUserDefinedGroup( Name => 'Parent group' );
ok( $pgid, "created parent group" );
is( $pgroup->id, $pgid, "id is correct" );
- my $cgroup = RT::Group->new( $RT::SystemUser );
+ my $cgroup = RT::Group->new( RT->SystemUser );
my ($cgid) = $cgroup->CreateUserDefinedGroup( Name => 'Child group' );
ok( $cgid, "created child group" );
is( $cgroup->id, $cgid, "id is correct" );
@@ -32,7 +32,7 @@ init_db();
ok( $status, "added child group to parent") or diag "error: $msg";
create_savepoint('bucreate'); # before user create
- my $user = RT::User->new( $RT::SystemUser );
+ my $user = RT::User->new( RT->SystemUser );
my $uid;
($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 );
ok( $uid, "created new user" ) or diag "error: $msg";
@@ -42,7 +42,7 @@ init_db();
($status, $msg) = $cgroup->AddMember( $user->id );
ok( $status, "added user to child group") or diag "error: $msg";
- my $members = RT::GroupMembers->new( $RT::SystemUser );
+ my $members = RT::GroupMembers->new( RT->SystemUser );
$members->Limit( FIELD => 'MemberId', VALUE => $uid );
$members->Limit( FIELD => 'GroupId', VALUE => $cgid );
is( $members->Count, 1, "find membership record" );
@@ -65,23 +65,23 @@ init_db();
{
restore_savepoint('clean');
- my $user = RT::User->new( $RT::SystemUser );
+ my $user = RT::User->new( RT->SystemUser );
my ($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 );
ok( $uid, "created new user" ) or diag "error: $msg";
is( $user->id, $uid, "id is correct" );
use RT::Queue;
- my $queue = new RT::Queue( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
$queue->Load('general');
ok( $queue->id, "queue loaded succesfully" );
$user->PrincipalObj->GrantRight( Right => 'OwnTicket', Object => $queue );
use RT::Tickets;
- my $ticket = RT::Ticket->new( $RT::SystemUser );
+ my $ticket = RT::Ticket->new( RT->SystemUser );
my ($id) = $ticket->Create( Subject => 'test', Queue => $queue->id );
ok( $id, "created new ticket" );
- $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket = RT::Ticket->new( RT->SystemUser );
my $status;
($status, $msg) = $ticket->Load( $id );
ok( $id, "load ticket" ) or diag( "error: $msg" );
@@ -95,9 +95,9 @@ init_db();
$shredder->PutObjects( Objects => $member );
$shredder->WipeoutAll();
- $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket = RT::Ticket->new( RT->SystemUser );
($status, $msg) = $ticket->Load( $id );
ok( $id, "load ticket" ) or diag( "error: $msg" );
- is( $ticket->Owner, $RT::Nobody->id, "owner switched back to nobody" );
- is( $ticket->OwnerGroup->MembersObj->First->MemberId, $RT::Nobody->id, "and owner role group member is nobody");
+ is( $ticket->Owner, RT->Nobody->id, "owner switched back to nobody" );
+ is( $ticket->OwnerGroup->MembersObj->First->MemberId, RT->Nobody->id, "and owner role group member is nobody");
}
diff --git a/rt/t/shredder/02queue.t b/rt/t/shredder/02queue.t
index 197cf63c8..fb5e36d6e 100644
--- a/rt/t/shredder/02queue.t
+++ b/rt/t/shredder/02queue.t
@@ -15,10 +15,10 @@ BEGIN {
init_db();
-diag 'simple queue' if $ENV{'TEST_VERBOSE'};
+diag 'simple queue' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $queue = RT::Queue->new( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
my ($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
@@ -28,14 +28,14 @@ diag 'simple queue' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'queue with scrip' if $ENV{'TEST_VERBOSE'};
+diag 'queue with scrip' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $queue = RT::Queue->new( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
my ($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
- my $scrip = RT::Scrip->new( $RT::SystemUser );
+ my $scrip = RT::Scrip->new( RT->SystemUser );
($id, $msg) = $scrip->Create(
Description => 'my scrip',
Queue => $queue->id,
@@ -51,14 +51,14 @@ diag 'queue with scrip' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'queue with template' if $ENV{'TEST_VERBOSE'};
+diag 'queue with template' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $queue = RT::Queue->new( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
my ($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
- my $template = RT::Template->new( $RT::SystemUser );
+ my $template = RT::Template->new( RT->SystemUser );
($id, $msg) = $template->Create(
Name => 'my template',
Queue => $queue->id,
@@ -72,14 +72,14 @@ diag 'queue with template' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'queue with a right granted' if $ENV{'TEST_VERBOSE'};
+diag 'queue with a right granted' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $queue = RT::Queue->new( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
my ($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
- my $group = RT::Group->new( $RT::SystemUser );
+ my $group = RT::Group->new( RT->SystemUser );
$group->LoadSystemInternalGroup('Everyone');
ok($group->id, 'loaded group');
@@ -95,16 +95,16 @@ diag 'queue with a right granted' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'queue with a watcher' if $ENV{'TEST_VERBOSE'};
+diag 'queue with a watcher' if $ENV{TEST_VERBOSE};
{
# XXX, FIXME: if uncomment these lines then we'll get 'Bizarre...'
# create_savepoint('clean');
- my $group = RT::Group->new( $RT::SystemUser );
+ my $group = RT::Group->new( RT->SystemUser );
my ($id, $msg) = $group->CreateUserDefinedGroup(Name => 'my group');
ok($id, 'created group') or diag "error: $msg";
create_savepoint('bqcreate');
- my $queue = RT::Queue->new( $RT::SystemUser );
+ my $queue = RT::Queue->new( RT->SystemUser );
($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
diff --git a/rt/t/shredder/02template.t b/rt/t/shredder/02template.t
index d4c323e09..16fa61588 100644
--- a/rt/t/shredder/02template.t
+++ b/rt/t/shredder/02template.t
@@ -15,10 +15,10 @@ BEGIN {
init_db();
-diag 'global template' if $ENV{'TEST_VERBOSE'};
+diag 'global template' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $template = RT::Template->new( $RT::SystemUser );
+ my $template = RT::Template->new( RT->SystemUser );
my ($id, $msg) = $template->Create(
Name => 'my template',
Content => "\nsome content",
@@ -31,10 +31,10 @@ diag 'global template' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'local template' if $ENV{'TEST_VERBOSE'};
+diag 'local template' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $template = RT::Template->new( $RT::SystemUser );
+ my $template = RT::Template->new( RT->SystemUser );
my ($id, $msg) = $template->Create(
Name => 'my template',
Queue => 'General',
@@ -48,10 +48,10 @@ diag 'local template' if $ENV{'TEST_VERBOSE'};
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
-diag 'template used in scrip' if $ENV{'TEST_VERBOSE'};
+diag 'template used in scrip' if $ENV{TEST_VERBOSE};
{
create_savepoint('clean');
- my $template = RT::Template->new( $RT::SystemUser );
+ my $template = RT::Template->new( RT->SystemUser );
my ($id, $msg) = $template->Create(
Name => 'my template',
Queue => 'General',
@@ -59,7 +59,7 @@ diag 'template used in scrip' if $ENV{'TEST_VERBOSE'};
);
ok($id, 'created template') or diag "error: $msg";
- my $scrip = RT::Scrip->new( $RT::SystemUser );
+ my $scrip = RT::Scrip->new( RT->SystemUser );
($id, $msg) = $scrip->Create(
Description => 'my scrip',
Queue => 'General',
diff --git a/rt/t/shredder/02user.t b/rt/t/shredder/02user.t
index 03abd6c69..8c8657c7d 100644
--- a/rt/t/shredder/02user.t
+++ b/rt/t/shredder/02user.t
@@ -17,16 +17,16 @@ init_db();
create_savepoint('clean');
-my $queue = RT::Queue->new( $RT::SystemUser );
+my $queue = RT::Queue->new( RT->SystemUser );
my ($qid) = $queue->Load( 'General' );
ok( $qid, "loaded queue" );
-my $ticket = RT::Ticket->new( $RT::SystemUser );
+my $ticket = RT::Ticket->new( RT->SystemUser );
my ($tid) = $ticket->Create( Queue => $qid, Subject => 'test' );
ok( $tid, "ticket created" );
create_savepoint('bucreate'); # berfore user create
-my $user = RT::User->new( $RT::SystemUser );
+my $user = RT::User->new( RT->SystemUser );
my ($uid, $msg) = $user->Create( Name => 'new user', Privileged => 1, Disabled => 0 );
ok( $uid, "created new user" ) or diag "error: $msg";
is( $user->id, $uid, "id is correct" );
@@ -38,7 +38,7 @@ create_savepoint('aucreate'); # after user create
my $resolver = sub {
my %args = (@_);
my $t = $args{'TargetObject'};
- my $resolver_uid = $RT::SystemUser->id;
+ my $resolver_uid = RT->SystemUser->id;
foreach my $method ( qw(Creator LastUpdatedBy) ) {
next unless $t->_Accessible( $method => 'read' );
$t->__Set( Field => $method, Value => $resolver_uid );
@@ -52,7 +52,7 @@ create_savepoint('aucreate'); # after user create
{
restore_savepoint('aucreate');
- my $user = RT::User->new( $RT::SystemUser );
+ my $user = RT::User->new( RT->SystemUser );
$user->Load($uid);
ok($user->id, "loaded user after restore");
my $shredder = shredder_new();
diff --git a/rt/t/shredder/03plugin.t b/rt/t/shredder/03plugin.t
index 190f40acf..cf51e448d 100644
--- a/rt/t/shredder/03plugin.t
+++ b/rt/t/shredder/03plugin.t
@@ -17,7 +17,7 @@ my @PLUGINS = sort qw(Attachments Base Objects SQLDump Summary Tickets Users);
use_ok('RT::Shredder::Plugin');
{
- my $plugin = new RT::Shredder::Plugin;
+ my $plugin = RT::Shredder::Plugin->new;
isa_ok($plugin, 'RT::Shredder::Plugin');
my %plugins = $plugin->List;
cmp_deeply( [sort keys %plugins], [@PLUGINS], "correct plugins" );
@@ -28,7 +28,7 @@ use_ok('RT::Shredder::Plugin');
}
{ # reblessing on LoadByName
foreach (@PLUGINS) {
- my $plugin = new RT::Shredder::Plugin;
+ my $plugin = RT::Shredder::Plugin->new;
isa_ok($plugin, 'RT::Shredder::Plugin');
my ($status, $msg) = $plugin->LoadByName( $_ );
ok($status, "loaded plugin by name") or diag("error: $msg");
@@ -36,7 +36,7 @@ use_ok('RT::Shredder::Plugin');
}
}
{ # error checking in LoadByName
- my $plugin = new RT::Shredder::Plugin;
+ my $plugin = RT::Shredder::Plugin->new;
isa_ok($plugin, 'RT::Shredder::Plugin');
my ($status, $msg) = $plugin->LoadByName;
ok(!$status, "not loaded plugin - empty name");
diff --git a/rt/t/shredder/03plugin_summary.t b/rt/t/shredder/03plugin_summary.t
index 30606af41..2744531db 100644
--- a/rt/t/shredder/03plugin_summary.t
+++ b/rt/t/shredder/03plugin_summary.t
@@ -6,7 +6,7 @@ use warnings;
use Test::Deep;
use File::Spec;
use Test::More tests => 4;
-use RT::Test ();
+use RT::Test nodb => 1;
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
File::Spec->curdir());
@@ -15,7 +15,7 @@ BEGIN {
use_ok('RT::Shredder::Plugin');
-my $plugin_obj = new RT::Shredder::Plugin;
+my $plugin_obj = RT::Shredder::Plugin->new;
isa_ok($plugin_obj, 'RT::Shredder::Plugin');
my ($status, $msg) = $plugin_obj->LoadByName('Summary');
ok($status, 'loaded summary plugin') or diag "error: $msg";
diff --git a/rt/t/shredder/03plugin_tickets.t b/rt/t/shredder/03plugin_tickets.t
index 3d742ff83..092b57052 100644
--- a/rt/t/shredder/03plugin_tickets.t
+++ b/rt/t/shredder/03plugin_tickets.t
@@ -16,7 +16,7 @@ BEGIN {
use_ok('RT::Shredder::Plugin::Tickets');
{
- my $plugin = new RT::Shredder::Plugin::Tickets;
+ my $plugin = RT::Shredder::Plugin::Tickets->new;
isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
is(lc $plugin->Type, 'search', 'correct type');
@@ -28,15 +28,14 @@ use_ok('RT::Ticket');
use_ok('RT::Tickets');
{ # create parent and child and check functionality of 'with_linked' arg
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
ok( $pid, "created new ticket" );
-
- my $child = RT::Ticket->new( $RT::SystemUser );
+ my $child = RT::Ticket->new( RT->SystemUser );
my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
ok( $cid, "created new ticket" );
- my $plugin = new RT::Shredder::Plugin::Tickets;
+ my $plugin = RT::Shredder::Plugin::Tickets->new;
isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
my ($status, $msg, @objs);
@@ -67,18 +66,18 @@ use_ok('RT::Tickets');
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
{ # create parent and child and link them reqursively to check that we don't hang
- my $parent = RT::Ticket->new( $RT::SystemUser );
+ my $parent = RT::Ticket->new( RT->SystemUser );
my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
ok( $pid, "created new ticket" );
- my $child = RT::Ticket->new( $RT::SystemUser );
+ my $child = RT::Ticket->new( RT->SystemUser );
my ($cid) = $child->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
ok( $cid, "created new ticket" );
my ($status, $msg) = $child->AddLink( Target => $pid, Type => 'DependsOn' );
ok($status, "added reqursive link") or diag "error: $msg";
- my $plugin = new RT::Shredder::Plugin::Tickets;
+ my $plugin = RT::Shredder::Plugin::Tickets->new;
isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
my (@objs);
@@ -109,18 +108,20 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"
cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");
{ # create parent and child and check functionality of 'apply_query_to_linked' arg
- my $parent = RT::Ticket->new( $RT::SystemUser );
- my ($pid) = $parent->Create( Subject => 'parent', Queue => 1, Status => 'resolved' );
+ my $parent = RT::Ticket->new( RT->SystemUser );
+ my ($pid) = $parent->Create( Subject => 'parent', Queue => 1 );
ok( $pid, "created new ticket" );
+ $parent->SetStatus('resolved');
- my $child1 = RT::Ticket->new( $RT::SystemUser );
+ my $child1 = RT::Ticket->new( RT->SystemUser );
my ($cid1) = $child1->Create( Subject => 'child', Queue => 1, MemberOf => $pid );
ok( $cid1, "created new ticket" );
- my $child2 = RT::Ticket->new( $RT::SystemUser );
- my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid, Status => 'resolved' );
+ my $child2 = RT::Ticket->new( RT->SystemUser );
+ my ($cid2) = $child2->Create( Subject => 'child', Queue => 1, MemberOf => $pid);
ok( $cid2, "created new ticket" );
+ $child2->SetStatus('resolved');
- my $plugin = new RT::Shredder::Plugin::Tickets;
+ my $plugin = RT::Shredder::Plugin::Tickets->new;
isa_ok($plugin, 'RT::Shredder::Plugin::Tickets');
my ($status, $msg) = $plugin->TestArgs( query => 'Status = "resolved"', apply_query_to_linked => 1 );
@@ -140,7 +141,7 @@ cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint"
$shredder->PutObjects( Objects => \@objs );
$shredder->WipeoutAll;
- my $ticket = RT::Ticket->new( $RT::SystemUser );
+ my $ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $cid1 );
is($ticket->id, $cid1, 'loaded ticket');
diff --git a/rt/t/shredder/03plugin_users.t b/rt/t/shredder/03plugin_users.t
index 45fc8a27e..4f4ecc89c 100644
--- a/rt/t/shredder/03plugin_users.t
+++ b/rt/t/shredder/03plugin_users.t
@@ -6,7 +6,7 @@ use warnings;
use Test::Deep;
use File::Spec;
use Test::More tests => 9;
-use RT::Test ();
+use RT::Test nodb => 1;
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
File::Spec->curdir());
@@ -18,7 +18,7 @@ my @ARGS = sort qw(limit status name member_of email replace_relations no_ticket
use_ok('RT::Shredder::Plugin::Users');
{
- my $plugin = new RT::Shredder::Plugin::Users;
+ my $plugin = RT::Shredder::Plugin::Users->new;
isa_ok($plugin, 'RT::Shredder::Plugin::Users');
is(lc $plugin->Type, 'search', 'correct type');
diff --git a/rt/t/shredder/utils.pl b/rt/t/shredder/utils.pl
index 54243318e..5f5c1822f 100644
--- a/rt/t/shredder/utils.pl
+++ b/rt/t/shredder/utils.pl
@@ -3,21 +3,15 @@
use strict;
use warnings;
-use File::Spec;
-use File::Temp 0.19 ();
-require File::Path;
require File::Copy;
require Cwd;
+require RT::Test;
BEGIN {
### after: push @INC, qw(@RT_LIB_PATH@);
- push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib);
}
use RT::Shredder;
-# where to keep temporary generated test data
-my $tmpdir = '';
-
=head1 DESCRIPTION
RT::Shredder test suite utilities
@@ -95,8 +89,9 @@ sub rewrite_rtconfig
config_set( '$LogStackTraces' , 'crit' );
# logging to standalone file
config_set( '$LogToFile' , 'debug' );
- my $fname = File::Spec->catfile(create_tmpdir(), test_name() .".log");
+ my $fname = File::Spec->catfile(RT::Test->temp_directory(), test_name() .".log");
config_set( '$LogToFileNamed' , $fname );
+ config_set('@LexiconLanguages', qw(en));
}
=head3 config_set
@@ -127,7 +122,7 @@ in most situations.
sub init_db
{
- create_tmpdir();
+ RT::Test->bootstrap_tempdir() unless RT::Test->temp_directory();
RT::LoadConfig();
rewrite_rtconfig();
RT::InitLogging();
@@ -161,13 +156,13 @@ sub _init_db
=head3 db_name
Returns the absolute file path to the current DB.
-It is <$tmpdir . test_name() .'.db'>.
+It is <<RT::Test->temp_directory . test_name() .'.db'>>.
See also the C<test_name> function.
=cut
-sub db_name { return File::Spec->catfile(create_tmpdir(), test_name() .".db") }
+sub db_name { return File::Spec->catfile(RT::Test->temp_directory(), test_name() .".db") }
=head3 connect_sqlite
@@ -192,9 +187,9 @@ Creates and returns a new RT::Shredder object.
sub shredder_new
{
- my $obj = new RT::Shredder;
+ my $obj = RT::Shredder->new;
- my $file = File::Spec->catfile( create_tmpdir(), test_name() .'.XXXX.sql' );
+ my $file = File::Spec->catfile( RT::Test->temp_directory, test_name() .'.XXXX.sql' );
$obj->AddDumpPlugin( Arguments => {
file_name => $file,
from_storage => 0,
@@ -223,44 +218,6 @@ sub test_name
return $name;
}
-=head2 TEMPORARY DIRECTORY
-
-=head3 tmpdir
-
-Returns the absolute path to a tmp dir used in tests.
-
-=cut
-
-sub tmpdir {
- if (-d $tmpdir) {
- return $tmpdir;
- } else {
- $tmpdir = File::Temp->newdir(TEMPLATE => 'shredderXXXXX', CLEANUP => 0);
- return $tmpdir;
- }
-}
-
-=head2 create_tmpdir
-
-Creates a tmp dir if one doesn't exist already. Returns tmpdir path.
-
-=cut
-
-sub create_tmpdir { my $n = tmpdir(); File::Path::mkpath( [$n] ); return $n }
-
-=head3 cleanup_tmp
-
-Deletes all the tmp dir used in the tests.
-See also the C<test_name> function.
-
-=cut
-
-sub cleanup_tmp
-{
- my $dir = File::Spec->catdir(tmpdir(), test_name());
- return File::Path::rmtree( File::Spec->catdir( tmpdir(), test_name() ));
-}
-
=head2 SAVEPOINTS
=head3 savepoint_name
@@ -273,7 +230,7 @@ Takes one argument - savepoint name, by default C<sp>.
sub savepoint_name
{
my $name = shift || 'sp';
- return File::Spec->catfile( create_tmpdir(), test_name() .".$name.db" );
+ return File::Spec->catfile( RT::Test->temp_directory, test_name() .".$name.db" );
}
=head3 create_savepoint
@@ -293,14 +250,9 @@ sub restore_savepoint { return __cp_db( savepoint_name( shift ) => db_name() ) }
sub __cp_db
{
my( $orig, $dest ) = @_;
- $RT::Handle->dbh->disconnect;
- # DIRTY HACK: undef Handles to force reconnect
- $RT::Handle = undef;
- %DBIx::SearchBuilder::DBIHandle = ();
- $DBIx::SearchBuilder::PrevHandle = undef;
-
+ RT::Test::__disconnect_rt();
File::Copy::copy( $orig, $dest ) or die "Couldn't copy '$orig' => '$dest': $!";
- RT::ConnectToDatabase();
+ RT::Test::__reconnect_rt();
return;
}
@@ -337,7 +289,7 @@ sub dump_sqlite
my $res = {};
foreach my $t( @tables ) {
next if lc($t) eq 'sessions';
- $res->{$t} = $dbh->selectall_hashref("SELECT * FROM $t", 'id');
+ $res->{$t} = $dbh->selectall_hashref("SELECT * FROM $t".dump_sqlite_exceptions($t), 'id');
clean_dates( $res->{$t} ) if $args{'CleanDates'};
die $DBI::err if $DBI::err;
}
@@ -346,6 +298,27 @@ sub dump_sqlite
return $res;
}
+=head3 dump_sqlite_exceptions
+
+If there are parts of the DB which can change from creating and deleting
+a queue, skip them when doing the comparison. One example is the global
+queue cache attribute on RT::System which will be updated on Queue creation
+and can't be rolled back by the shredder. It may actually make sense for
+Shredder to be updating this at some point in the future.
+
+=cut
+
+sub dump_sqlite_exceptions {
+ my $table = shift;
+
+ my $special_wheres = {
+ attributes => " WHERE Name != 'QueueCacheNeedsUpdate'"
+ };
+
+ return $special_wheres->{lc $table}||'';
+
+}
+
=head3 dump_current_and_savepoint
Returns dump of the current DB and of the named savepoint.
@@ -396,7 +369,7 @@ Returns a note about debug info that you can display if tests fail.
sub note_on_fail
{
my $name = test_name();
- my $tmpdir = tmpdir();
+ my $tmpdir = RT::Test->temp_directory();
return <<END;
Some tests in '$0' file failed.
You can find debug info in '$tmpdir' dir.
@@ -408,27 +381,9 @@ See also perldoc t/shredder/utils.pl for how to use this info.
END
}
-=head2 OTHER
-
-=head3 all_were_successful
-
-Returns true if all tests that have already run were successful.
-
-=cut
-
-sub all_were_successful
-{
- use Test::Builder;
- my $Test = Test::Builder->new;
- return grep( !$_, $Test->summary )? 0: 1;
-}
-
END {
- return unless -e tmpdir();
- if ( all_were_successful() ) {
- cleanup_tmp();
- } else {
- diag( note_on_fail() );
+ if ( ! RT::Test->builder->is_passing ) {
+ diag( note_on_fail() );
}
}