"Fossies" - the Fresh Open Source Software Archive

Member "rt-5.0.2/t/shredder/03plugin_users.t" (14 Sep 2021, 5989 Bytes) of package /linux/misc/rt-5.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "03plugin_users.t": 5.0.1_vs_5.0.2.

    1 
    2 use strict;
    3 use warnings;
    4 
    5 use Test::Deep;
    6 use RT::Test::Shredder tests => undef;
    7 my $test = "RT::Test::Shredder";
    8 
    9 my @ARGS = sort qw(limit status name member_of not_member_of email replace_relations no_tickets no_ticket_transactions);
   10 
   11 use_ok('RT::Shredder::Plugin::Users');
   12 {
   13     my $plugin = RT::Shredder::Plugin::Users->new;
   14     isa_ok($plugin, 'RT::Shredder::Plugin::Users');
   15 
   16     is(lc $plugin->Type, 'search', 'correct type');
   17 
   18     my @args = sort $plugin->SupportArgs;
   19     cmp_deeply(\@args, \@ARGS, "support all args");
   20 
   21 
   22     my ($status, $msg) = $plugin->TestArgs( name => 'r??t*' );
   23     ok($status, "arg name = 'r??t*'") or diag("error: $msg");
   24 
   25     for (qw(any disabled enabled)) {
   26         my ($status, $msg) = $plugin->TestArgs( status => $_ );
   27         ok($status, "arg status = '$_'") or diag("error: $msg");
   28     }
   29     ($status, $msg) = $plugin->TestArgs( status => '!@#' );
   30     ok(!$status, "bad 'status' arg value");
   31 }
   32 
   33 RT::Test->set_rights(
   34     { Principal => 'Everyone', Right => [qw(CreateTicket)] },
   35 );
   36 
   37 $test->create_savepoint('clean');
   38 
   39 { # Create two users and a ticket. Shred second user and replace relations with first user
   40     my ($uidA, $uidB, $msg);
   41     my $userA = RT::User->new( RT->SystemUser );
   42     ($uidA, $msg) = $userA->Create( Name => 'userA', Privileged => 1, Disabled => 0 );
   43     ok( $uidA, "created user A" ) or diag "error: $msg";
   44 
   45     my $userB = RT::User->new( RT->SystemUser );
   46     ($uidB, $msg) = $userB->Create( Name => 'userB', Privileged => 1, Disabled => 0 );
   47     ok( $uidB, "created user B" ) or diag "error: $msg";
   48 
   49     my ($tid, $trid);
   50     my $ticket = RT::Ticket->new( RT::CurrentUser->new($userB) );
   51     ($tid, $trid, $msg) = $ticket->Create( Subject => 'UserB Ticket', Queue => 1 );
   52     ok( $tid, "created new ticket") or diag "error: $msg";
   53     $ticket->ApplyTransactionBatch;
   54 
   55     my $transaction = RT::Transaction->new( RT->SystemUser );
   56     $transaction->Load($trid);
   57     is ( $transaction->Creator, $uidB, "ticket creator is user B" );
   58 
   59     my $plugin = RT::Shredder::Plugin::Users->new;
   60     isa_ok($plugin, 'RT::Shredder::Plugin::Users');
   61 
   62     my $status;
   63     ($status, $msg) = $plugin->TestArgs( status => 'any', name => 'userB', replace_relations => $uidA );
   64     ok($status, "plugin arguments are ok") or diag "error: $msg";
   65 
   66     my $shredder = $test->shredder_new();
   67 
   68     my @objs;
   69     ($status, @objs) = $plugin->Run;
   70     ok($status, "executed plugin successfully") or diag "error: @objs";
   71     @objs = RT::Shredder->CastObjectsToRecords( Objects => \@objs );
   72     is(scalar @objs, 1, "one object in the result set");
   73 
   74     ($status, $msg) = $plugin->SetResolvers( Shredder => $shredder );
   75     ok($status, "set conflicts resolver") or diag "error: $msg";
   76 
   77     $shredder->PutObjects( Objects => \@objs );
   78     $shredder->WipeoutAll;
   79 
   80     $ticket->Load( $tid );
   81     is($ticket->id, $tid, 'loaded ticket');
   82 
   83     $transaction->Load($trid);
   84     is ( $transaction->Creator, $uidA, "ticket creator is now user A" );
   85 
   86     $shredder->Wipeout( Object => $ticket );
   87     $shredder->Wipeout( Object => $userA );
   88 }
   89 cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
   90 
   91 { # Same as previous test, but pass Objects to PutObjects in the same form as the web interface
   92     my ($uidA, $uidB, $msg);
   93     my $userA = RT::User->new( RT->SystemUser );
   94     ($uidA, $msg) = $userA->Create( Name => 'userA', Privileged => 1, Disabled => 0 );
   95     ok( $uidA, "created user A" ) or diag "error: $msg";
   96 
   97     my $userB = RT::User->new( RT->SystemUser );
   98     ($uidB, $msg) = $userB->Create( Name => 'userB', Privileged => 1, Disabled => 0 );
   99     ok( $uidB, "created user B" ) or diag "error: $msg";
  100 
  101     my ($tid, $trid);
  102     my $ticket = RT::Ticket->new( RT::CurrentUser->new($userB) );
  103     ($tid, $trid, $msg) = $ticket->Create( Subject => 'UserB Ticket', Queue => 1 );
  104     ok( $tid, "created new ticket") or diag "error: $msg";
  105     $ticket->ApplyTransactionBatch;
  106 
  107     my $transaction = RT::Transaction->new( RT->SystemUser );
  108     $transaction->Load($trid);
  109     is ( $transaction->Creator, $uidB, "ticket creator is user B" );
  110 
  111     my $plugin = RT::Shredder::Plugin::Users->new;
  112     isa_ok($plugin, 'RT::Shredder::Plugin::Users');
  113 
  114     my $status;
  115     ($status, $msg) = $plugin->TestArgs( status => 'any', name => 'userB', replace_relations => $uidA );
  116     ok($status, "plugin arguments are ok") or diag "error: $msg";
  117 
  118     my $shredder = $test->shredder_new();
  119 
  120     my @objs;
  121     ($status, @objs) = $plugin->Run;
  122     ok($status, "executed plugin successfully") or diag "error: @objs";
  123 
  124     # Same form as param coming in via the web interface
  125     $shredder->PutObjects( Objects => ['RT::User-userB'] );
  126 
  127     ($status, $msg) = $plugin->SetResolvers( Shredder => $shredder );
  128     ok($status, "set conflicts resolver") or diag "error: $msg";
  129 
  130     $shredder->WipeoutAll;
  131 
  132     $ticket->Load( $tid );
  133     is($ticket->id, $tid, 'loaded ticket');
  134 
  135     $transaction->Load($trid);
  136     is ( $transaction->Creator, $uidA, "ticket creator is now user A" );
  137 
  138     $shredder->Wipeout( Object => $ticket );
  139     $shredder->Wipeout( Object => $userA );
  140 }
  141 cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
  142 
  143 diag "Shred a user whose name contains a hyphen";
  144 {
  145     my $user = RT::Test->load_or_create_user( Name => 'bilbo-bargins' );
  146     my $plugin = RT::Shredder::Plugin::Users->new;
  147     my ( $status, $msg ) = $plugin->TestArgs( status => 'any', name => 'bilbo-bargins' );
  148     ok( $status, "plugin arguments are ok" ) or diag "error: $msg";
  149 
  150     my $shredder = $test->shredder_new();
  151 
  152     ( $status, my $users ) = $plugin->Run;
  153     is( $users->Count, 1, 'found one user' );
  154     is( $users->First->Name, 'bilbo-bargins', 'found the user' );
  155     ok( $status, "executed plugin successfully" );
  156 
  157     $shredder->PutObjects( Objects => ['RT::User-bilbo-bargins'] );
  158     $shredder->WipeoutAll;
  159 }
  160 cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
  161 
  162 done_testing();