1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
use strict;
use warnings;
use Test::Deep;
use RT::Test::Shredder tests => undef;
my $test = "RT::Test::Shredder";
diag 'simple queue' if $ENV{TEST_VERBOSE};
{
$test->create_savepoint('clean');
my $queue = RT::Queue->new( RT->SystemUser );
my ($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
diag 'queue with scrip' if $ENV{TEST_VERBOSE};
{
my $scrip = RT::Scrip->new( RT->SystemUser );
my ($id, $msg) = $scrip->Create(
Description => 'my scrip',
ScripCondition => 'On Create',
ScripAction => 'Open Tickets',
Template => 'Blank',
);
ok($id, 'created scrip') or diag "error: $msg";
ok( $scrip->RemoveFromObject(0), 'unapplied scrip from global' );
# Commit 7d5502ffe makes Scrips not be deleted when a queue is shredded.
# we need to create the savepoint before applying the scrip so we can test
# to make sure it's remaining after shredding the queue.
$test->create_savepoint('clean');
my $queue = RT::Queue->new( RT->SystemUser );
($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
# apply the scrip to the queue.
($id, $msg) = $scrip->AddToObject( ObjectId => $queue->id );
ok($id, 'applied scrip to queue') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
diag 'queue with template' if $ENV{TEST_VERBOSE};
{
$test->create_savepoint('clean');
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 );
($id, $msg) = $template->Create(
Name => 'my template',
Queue => $queue->id,
Content => "\nsome content",
);
ok($id, 'created template') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
diag 'queue with a right granted' if $ENV{TEST_VERBOSE};
{
$test->create_savepoint('clean');
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 );
$group->LoadSystemInternalGroup('Everyone');
ok($group->id, 'loaded group');
($id, $msg) = $group->PrincipalObj->GrantRight(
Right => 'CreateTicket',
Object => $queue,
);
ok($id, 'granted right') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
diag 'queue with a watcher' if $ENV{TEST_VERBOSE};
{
# XXX, FIXME: if uncomment these lines then we'll get 'Bizarre...'
# $test->create_savepoint('clean');
my $group = RT::Group->new( RT->SystemUser );
my ($id, $msg) = $group->CreateUserDefinedGroup(Name => 'my group');
ok($id, 'created group') or diag "error: $msg";
$test->create_savepoint('bqcreate');
my $queue = RT::Queue->new( RT->SystemUser );
($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
($id, $msg) = $queue->AddWatcher(
Type => 'Cc',
PrincipalId => $group->id,
);
ok($id, 'added watcher') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('bqcreate'), "current DB equal to savepoint");
# $shredder->PutObjects( Objects => $group );
# $shredder->WipeoutAll;
# cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
diag 'queue with custom fields' if $ENV{TEST_VERBOSE};
{
my $ticket_custom_field = RT::CustomField->new( RT->SystemUser );
my ($id, $msg) = $ticket_custom_field->Create(
Name => 'ticket custom field',
Type => 'Freeform',
LookupType => RT::Ticket->CustomFieldLookupType,
MaxValues => '1',
);
ok($id, 'created ticket custom field') or diag "error: $msg";
my $transaction_custom_field = RT::CustomField->new( RT->SystemUser );
($id, $msg) = $transaction_custom_field->Create(
Name => 'transaction custom field',
Type => 'Freeform',
LookupType => RT::Transaction->CustomFieldLookupType,
MaxValues => '1',
);
ok($id, 'created transaction custom field') or diag "error: $msg";
$test->create_savepoint('clean');
my $queue = RT::Queue->new( RT->SystemUser );
($id, $msg) = $queue->Create( Name => 'my queue' );
ok($id, 'created queue') or diag "error: $msg";
# apply the custom fields to the queue.
($id, $msg) = $ticket_custom_field->AddToObject( $queue );
ok($id, 'applied ticket cf to queue') or diag "error: $msg";
($id, $msg) = $transaction_custom_field->AddToObject( $queue );
ok($id, 'applied txn cf to queue') or diag "error: $msg";
my $shredder = $test->shredder_new();
$shredder->PutObjects( Objects => $queue );
$shredder->WipeoutAll;
$test->db_is_valid;
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
}
done_testing;
|