[Rt-commit] r5244 - in RT-Extension-CommandByEmail: t

ruz at bestpractical.com ruz at bestpractical.com
Wed May 17 20:40:21 EDT 2006


Author: ruz
Date: Wed May 17 20:40:20 2006
New Revision: 5244

Added:
   RT-Extension-CommandByEmail/t/01.internals.t
   RT-Extension-CommandByEmail/t/utils.pl
Modified:
   RT-Extension-CommandByEmail/lib/RT/Interface/Email/Filter/TakeAction.pm
   RT-Extension-CommandByEmail/t/00.load.t

Log:
* internal tests 

Modified: RT-Extension-CommandByEmail/lib/RT/Interface/Email/Filter/TakeAction.pm
==============================================================================
--- RT-Extension-CommandByEmail/lib/RT/Interface/Email/Filter/TakeAction.pm	(original)
+++ RT-Extension-CommandByEmail/lib/RT/Interface/Email/Filter/TakeAction.pm	Wed May 17 20:40:20 2006
@@ -3,6 +3,8 @@
 use warnings;
 use strict;
 
+use RT::Interface::Email;
+
 our @REGULAR_ATTRIBUTES = qw(Queue Status Priority FinalPriority
                              TimeWorked TimeLeft TimeEstimated Subject );
 our @DATE_ATTRIBUTES    = qw(Due Starts Started Resolved Told);
@@ -400,8 +402,15 @@
 
 sub _CompileAdditiveForCreate {
     my %cmd = @_;
+
+    unless ( exists $cmd{'Default'} && defined $cmd{'Default'} ) {
+        $cmd{'Default'} = [];
+    } elsif ( ref $cmd{'Default'} ne 'ARRAY' ) {
+        $cmd{'Default'} = [ $cmd{'Default'} ];
+    }
+
     my @list;
-    @list = @{ $cmd{'Default'} } if $cmd{'Default'} && !$cmd{'Set'};
+    @list = @{ $cmd{'Default'} } unless $cmd{'Set'};
     @list = @{ $cmd{'Set'} } if $cmd{'Set'};
     push @list, @{ $cmd{'Add'} } if $cmd{'Add'};
     if ( $cmd{'Del'} ) {
@@ -417,8 +426,14 @@
 
     my @new = _CompileAdditiveForCreate( %cmd );
 
+    unless ( exists $cmd{'Default'} && defined $cmd{'Default'} ) {
+        $cmd{'Default'} = [];
+    } elsif ( ref $cmd{'Default'} ne 'ARRAY' ) {
+        $cmd{'Default'} = [ $cmd{'Default'} ];
+    }
+
     my ($add, $del);
-    if ( !$cmd{'Default'} ) {
+    unless ( @{ $cmd{'Default'} } ) {
         $add = \@new;
     } elsif ( !@new ) {
         $del = $cmd{'Default'};
@@ -426,12 +441,12 @@
         my (%cur, %new);
         $cur{$_} = 1 foreach @{ $cmd{'Default'} };
         $new{$_} = 1 foreach @new;
-        my %tmp;
+
         $add = [ grep !$cur{$_}, @new ];
         $del = [ grep !$new{$_}, @{ $cmd{'Default'} } ];
     }
     $_ ||= [] foreach ($add, $del);
-    return $add, $del;
+    return ($add, $del);
 }
 
 sub _SetAttribute {
@@ -456,28 +471,6 @@
     return $key;
 }
 
-sub _SetWatcherAttribute {
-    my $ticket    = shift;
-    my $method    = shift;
-    my $attribute = shift;
-    my $type      = shift;
-    my $email     = shift;
-    my $results   = shift;
-    my ( $val, $msg ) = $ticket->DelWatcher(
-        Type  => $type,
-        Email => $email
-    );
-
-    $results->{$attribute} = {
-        value   => $email,
-        result  => $val,
-        message => $msg
-    };
-
-}
-
-
-
 sub _ReportResults {
     my %args = ( Ticket => undef, Message => undef, Results => {}, @_ );
 

Modified: RT-Extension-CommandByEmail/t/00.load.t
==============================================================================
--- RT-Extension-CommandByEmail/t/00.load.t	(original)
+++ RT-Extension-CommandByEmail/t/00.load.t	Wed May 17 20:40:20 2006
@@ -1,7 +1,11 @@
-use Test::More tests => 1;
+use Test::More tests => 3;
 
+BEGIN { require 't/utils.pl' }
 BEGIN {
-use_ok( 'RT::Extension::CommandByMail' );
+    use_ok( 'RT' );
+    RT::LoadConfig();
+    use_ok( 'RT::Extension::CommandByMail' );
+    use_ok( 'RT::Interface::Email::Filter::TakeAction' );
 }
 
 diag( "Testing RT::Extension::CommandByMail $RT::Extension::CommandByMail::VERSION" );

Added: RT-Extension-CommandByEmail/t/01.internals.t
==============================================================================
--- (empty file)
+++ RT-Extension-CommandByEmail/t/01.internals.t	Wed May 17 20:40:20 2006
@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+use_ok('RT');
+RT::LoadConfig();
+
+use_ok('RT::Interface::Email::Filter::TakeAction');
+
+diag( "test _ParseAdditiveCommand") if $ENV{'TEST_VERBOSE'};
+{
+    my %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand({}, 0, 'Foo');
+    is_deeply( \%res, {}, 'empty' );
+
+    my $cmd = { foo => 'qwe' };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo');
+    is_deeply(\%res, { Set => ['qwe'] }, 'simple set');
+
+    $cmd = { foo => ['qwe', 'asd'] };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo');
+    is_deeply(\%res, { Set => ['qwe', 'asd'] }, 'simple set with array ref');
+
+    $cmd = { foos => 'qwe' };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 1, 'Foo');
+    is_deeply(\%res, { Set => ['qwe'] }, 'simple set with plural form');
+
+    $cmd = { foos => 'qwe' };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo');
+    is_deeply(\%res, { }, 'single form shouldnt eat plural forms');
+
+    $cmd = { foo => 'qwe', foos => 'qwe' };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 1, 'Foo');
+    is_deeply(\%res, { Set => ['qwe', 'qwe'] }, 'set with plural and single form at the same time');
+
+    $cmd = { foo => 'qwe', addfoo  => 'asd' };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo');
+    is_deeply(\%res, { Set => ['qwe'], Add => ['asd'] }, 'set+add');
+
+    $cmd = { foo => ['qwe'], addfoo  => ['asd'], delfoo => ['zxc'] };
+    %res = RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo');
+    is_deeply(\%res, { Set => ['qwe'], Add => ['asd'], Del => ['zxc'] }, 'set+add+del');
+}
+
+diag( "test _CompileAdditiveForCreate") if $ENV{'TEST_VERBOSE'};
+{
+    my @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand({}, 0, 'Foo')
+    );
+    is_deeply(\@res, [], 'empty');
+
+    my $cmd = { foo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, ['qwe'], 'simple set');
+
+    $cmd = { foo => 'qwe', addfoo => 'asd' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, ['qwe', 'asd'], 'set+add');
+
+    $cmd = { foo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, ['qwe'], 'set+default: set overrides defaults');
+
+    $cmd = { addfoo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, ['def', 'qwe'], 'add+default: add adds to defaults');
+
+    $cmd = { addfoo => 'qwe', delfoo => 'def' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForCreate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, ['qwe'], 'add+default+del: delete default');
+}
+
+diag( "test _CompileAdditiveForUpdate") if $ENV{'TEST_VERBOSE'};
+{
+    my @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand({}, 0, 'Foo')
+    );
+    is_deeply(\@res, [[], []], 'empty');
+
+    my $cmd = { foo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [['qwe'],[]], 'simple set');
+
+    $cmd = { foo => 'qwe', addfoo => 'asd' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [['qwe', 'asd'],[]], 'set+add');
+
+    $cmd = { foo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [['qwe'],['def']], 'set+default: set overrides defaults');
+
+    $cmd = { addfoo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [['qwe'],[]], 'add+default: add adds to defaults');
+
+    $cmd = { addfoo => 'def' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [[],[]], 'add current: do nothing');
+
+    $cmd = { addfoo => 'qwe', delfoo => 'def' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [['qwe'],['def']], 'add+default+del: delete default');
+
+    $cmd = { delfoo => 'qwe' };
+    @res = RT::Interface::Email::Filter::TakeAction::_CompileAdditiveForUpdate(
+        Default => 'def',
+        RT::Interface::Email::Filter::TakeAction::_ParseAdditiveCommand($cmd, 0, 'Foo')
+    );
+    is_deeply(\@res, [[],[]], 'del not current: do nothing');
+}

Added: RT-Extension-CommandByEmail/t/utils.pl
==============================================================================
--- (empty file)
+++ RT-Extension-CommandByEmail/t/utils.pl	Wed May 17 20:40:20 2006
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+
+BEGIN {
+### after:  push @INC, qw(@RT_LIB_PATH@);
+    push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib);
+}
+
+1;
+


More information about the Rt-commit mailing list