"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/scripts/test/ProcessManagement/DB/ActivityDialog.t" (12 Dec 2019, 30307 Bytes) of package /linux/www/otrs-5.0.40.tar.bz2:


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 last Fossies "Diffs" side-by-side code changes report for "ActivityDialog.t": rel-6_0_25_vs_rel-6_0_26.

    1 # --
    2 # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
    3 # --
    4 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
    5 # the enclosed file COPYING for license information (GPL). If you
    6 # did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
    7 # --
    8 
    9 ## no critic (Modules::RequireExplicitPackage)
   10 use strict;
   11 use warnings;
   12 use utf8;
   13 
   14 use vars (qw($Self));
   15 
   16 use Kernel::System::VariableCheck qw(:all);
   17 
   18 # get needed objects
   19 my $CacheObject          = $Kernel::OM->Get('Kernel::System::Cache');
   20 my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog');
   21 
   22 # get helper object
   23 $Kernel::OM->ObjectParamAdd(
   24     'Kernel::System::UnitTest::Helper' => {
   25         RestoreDatabase => 1,
   26     },
   27 );
   28 my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
   29 
   30 # set fixed time
   31 $Helper->FixedTimeSet();
   32 
   33 # define needed variables
   34 my $RandomID = $Helper->GetRandomID();
   35 my $UserID   = 1;
   36 
   37 my $EntityID = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Entity')->EntityIDGenerate(
   38     EntityType => 'ActivityDialog',
   39     UserID     => 1,
   40 );
   41 
   42 # get original ActivityDialog list
   43 my $OriginalActivityDialogList = $ActivityDialogObject->ActivityDialogList( UserID => $UserID )
   44     || {};
   45 
   46 #
   47 # Tests for ActivityDialogAdd
   48 #
   49 my @Tests = (
   50     {
   51         Name    => 'ActivityDialogAdd Test 1: No Params',
   52         Config  => {},
   53         Success => 0,
   54     },
   55     {
   56         Name   => 'ActivityDialogAdd Test 2: No EntityID',
   57         Config => {
   58             EntityID => undef,
   59             Name     => 'ActivityDialog-$RandomID',
   60             Config   => {
   61                 DescriptionShort => 'a Description',
   62                 Fields           => {},
   63                 FieldOrder       => [],
   64             },
   65             UserID => $UserID,
   66         },
   67         Success => 0,
   68 
   69     },
   70     {
   71         Name   => 'ActivityDialogAdd Test 3: No Name',
   72         Config => {
   73             EntityID => $RandomID,
   74             Name     => undef,
   75             Config   => {
   76                 DescriptionShort => 'a Description',
   77                 Fields           => {},
   78                 FieldOrder       => [],
   79             },
   80             UserID => $UserID,
   81         },
   82         Success => 0,
   83 
   84     },
   85     {
   86         Name   => 'ActivityDialogAdd Test 4: No Config',
   87         Config => {
   88             EntityID => $RandomID,
   89             Name     => "ActivityDialog-$RandomID",
   90             Config   => undef,
   91             UserID   => $UserID,
   92         },
   93         Success => 0,
   94     },
   95     {
   96         Name   => 'ActivityDialogAdd Test 5: No Config DescriptionShort',
   97         Config => {
   98             EntityID => $RandomID,
   99             Name     => "ActivityDialog-$RandomID",
  100             Config   => {
  101                 Data       => 1,
  102                 Fields     => {},
  103                 FieldOrder => [],
  104             },
  105             UserID => $UserID,
  106         },
  107         Success => 0,
  108     },
  109     {
  110         Name   => 'ActivityDialogAdd Test 6: No Config Fields',
  111         Config => {
  112             EntityID => $RandomID,
  113             Name     => "ActivityDialog-$RandomID",
  114             Config   => {
  115                 DescriptionShort => 'a Description',
  116                 Fields           => undef,
  117                 FieldOrder       => [],
  118             },
  119             UserID => $UserID,
  120         },
  121         Success => 0,
  122     },
  123     {
  124         Name   => 'ActivityDialogAdd Test 7: No Config FieldOrder',
  125         Config => {
  126             EntityID => $RandomID,
  127             Name     => "ActivityDialog-$RandomID",
  128             Config   => {
  129                 DescriptionShort => 'a Description',
  130                 Fields           => {},
  131                 FieldOrder       => undef,
  132             },
  133             UserID => $UserID,
  134         },
  135         Success => 0,
  136     },
  137     {
  138         Name   => 'ActivityDialogAdd Test 8: No UserID',
  139         Config => {
  140             EntityID => $RandomID,
  141             Name     => "ActivityDialog-$RandomID",
  142             Config   => {
  143                 DescriptionShort => 'a Description',
  144                 Fields           => {},
  145                 FieldOrder       => undef,
  146             },
  147             UserID => undef,
  148 
  149         },
  150         Success => 0,
  151     },
  152     {
  153         Name   => 'ActivityDialogAdd Test 9: Wrong Config format',
  154         Config => {
  155             EntityID => $RandomID,
  156             Name     => "ActivityDialog-$RandomID",
  157             Config   => {},
  158             UserID   => $UserID,
  159         },
  160         Success => 0,
  161     },
  162     {
  163         Name   => 'ActivityDialogAdd Test 10: Wrong Config format 2',
  164         Config => {
  165             EntityID => $RandomID,
  166             Name     => "ActivityDialog-$RandomID",
  167             Config   => 'Config',
  168             UserID   => $UserID,
  169         },
  170         Success => 0,
  171     },
  172     {
  173         Name   => 'ActivityDialogAdd Test 11: Wrong Config Fields format',
  174         Config => {
  175             EntityID => $RandomID,
  176             Name     => "ActivityDialog-$RandomID",
  177             Config   => {
  178                 DescriptionShort => 'a Description',
  179                 Fields           => 'fields',
  180                 FieldOrder       => [],
  181             },
  182             UserID => $UserID,
  183         },
  184         Success => 0,
  185     },
  186     {
  187         Name   => 'ActivityDialogAdd Test 12: Wrong Config FieldOrder format',
  188         Config => {
  189             EntityID => $RandomID,
  190             Name     => "ActivityDialog-$RandomID",
  191             Config   => {
  192                 DescriptionShort => 'a Description',
  193                 Fields           => {},
  194                 FieldOrder       => 'fieldorder',
  195             },
  196             UserID => $UserID,
  197         },
  198         Success => 0,
  199     },
  200     {
  201         Name   => 'ActivityDialogAdd Test 13: Correct ASCII',
  202         Config => {
  203             EntityID => $RandomID,
  204             Name     => "ActivityDialog-$RandomID",
  205             Config   => {
  206                 DescriptionShort => 'a Description',
  207                 Fields           => {
  208                     PriorityID => {
  209                         DescriptionShort => 'Short description',
  210                         DescriptionLong  => 'Longer description',
  211                         Display          => 0,
  212                         DefaultValue     => 1,
  213                     },
  214                 },
  215                 FieldOrder => ['PriotityID'],
  216             },
  217             UserID => $UserID,
  218         },
  219         Success => 1,
  220     },
  221     {
  222         Name   => 'ActivityDialogAdd Test 14: Duplicated EntityID',
  223         Config => {
  224             EntityID => $RandomID,
  225             Name     => "ActivityDialog-$RandomID",
  226             Config   => {
  227                 DescriptionShort => 'a Description',
  228                 Fields           => {
  229                     PriorityID => {
  230                         DescriptionShort => 'Short description',
  231                         DescriptionLong  => 'Longer description',
  232                         Display          => 0,
  233                         DefaultValue     => 1,
  234                     },
  235                 },
  236                 FieldOrder => ['PriotityID'],
  237             },
  238             UserID => $UserID,
  239         },
  240         Success => 0,
  241     },
  242     {
  243         Name   => 'ActivityDialogAdd Test 15: Correct UTF8',
  244         Config => {
  245             EntityID => "$RandomID-1",
  246             Name     => "ActivityDialog-$RandomID-!§$%&/()=?Ü*ÄÖL:L@,.-",
  247             Config   => {
  248                 DescriptionShort => 'a Description !§$%&/()=?Ü*ÄÖL:L@,.-',
  249                 Fields           => {
  250                     PriorityID => {
  251                         DescriptionShort => 'Short description',
  252                         DescriptionLong  => 'Longer description',
  253                         Display          => 0,
  254                         DefaultValue     => 1,
  255                     },
  256                     StateID => {
  257                         DescriptionShort => 'Short description',
  258                         DescriptionLong  => 'Longer description',
  259                         Display          => 0,
  260                         DefaultValue     => 1,
  261                     },
  262                 },
  263                 FieldOrder => [ 'PriotityID', 'StateID' ],
  264             },
  265             UserID => $UserID,
  266         },
  267         Success => 1,
  268     },
  269     {
  270         Name   => 'ActivityDialogAdd Test 15: Correct UTF8 2',
  271         Config => {
  272             EntityID => "$RandomID-2",
  273             Name     => "ActivityDialog-$RandomID--äöüßÄÖÜ€исáéíúóúÁÉÍÓÚñÑ",
  274             Config   => {
  275                 DescriptionShort =>
  276                     'a Description -äöüßÄÖÜ€исáéíúóúÁÉÍÓÚñÑ',
  277                 Fields => {
  278                     PriorityID => {
  279                         DescriptionShort => 'Short description',
  280                         DescriptionLong  => 'Longer description',
  281                         Display          => 0,
  282                         DefaultValue     => 1,
  283                     },
  284                     StateID => {
  285                         DescriptionShort => 'Short description',
  286                         DescriptionLong  => 'Longer description',
  287                         Display          => 0,
  288                         DefaultValue     => 1,
  289                     },
  290                     QueueID => {
  291                         DescriptionShort => 'Short description',
  292                         DescriptionLong  => 'Longer description',
  293                         Display          => 0,
  294                         DefaultValue     => 1,
  295                     },
  296                 },
  297                 FieldOrder => [ 'PriotityID', 'StateID', 'QueueID' ],
  298             },
  299             UserID => $UserID,
  300         },
  301         Success => 1,
  302     },
  303     {
  304         Name   => 'ActivityDialogAdd Test 15: EntityID Full Length',
  305         Config => {
  306             EntityID => $EntityID,
  307             Name     => $EntityID,
  308             Config   => {
  309                 DescriptionShort =>
  310                     'a Description -äöüßÄÖÜ€исáéíúóúÁÉÍÓÚñÑ',
  311                 Fields => {
  312                     PriorityID => {
  313                         DescriptionShort => 'Short description',
  314                         DescriptionLong  => 'Longer description',
  315                         Display          => 0,
  316                         DefaultValue     => 1,
  317                     },
  318                     StateID => {
  319                         DescriptionShort => 'Short description',
  320                         DescriptionLong  => 'Longer description',
  321                         Display          => 0,
  322                         DefaultValue     => 1,
  323                     },
  324                     QueueID => {
  325                         DescriptionShort => 'Short description',
  326                         DescriptionLong  => 'Longer description',
  327                         Display          => 0,
  328                         DefaultValue     => 1,
  329                     },
  330                 },
  331                 FieldOrder => [ 'PriotityID', 'StateID', 'QueueID' ],
  332             },
  333             UserID => $UserID,
  334         },
  335         Success => 1,
  336     },
  337 );
  338 
  339 my %AddedActivityDialogs;
  340 for my $Test (@Tests) {
  341     my $ActivityDialogID = $ActivityDialogObject->ActivityDialogAdd( %{ $Test->{Config} } );
  342 
  343     if ( $Test->{Success} ) {
  344         $Self->IsNot(
  345             $ActivityDialogID,
  346             0,
  347             "$Test->{Name} | ActivityDialogID should not be 0",
  348         );
  349         $AddedActivityDialogs{$ActivityDialogID} = $Test->{Config};
  350     }
  351     else {
  352         $Self->Is(
  353             $ActivityDialogID,
  354             undef,
  355             "$Test->{Name} | ActivityDialogID should be undef",
  356         );
  357     }
  358 }
  359 
  360 #
  361 # ActivityDialogGet()
  362 #
  363 
  364 my @AddedActivityDialogsList = map {$_} sort keys %AddedActivityDialogs;
  365 @Tests = (
  366     {
  367         Name    => 'ActivityDialogGet Test 1: No params',
  368         Config  => {},
  369         Success => 0,
  370     },
  371     {
  372         Name   => 'ActivityDialogGet Test 2: No ID and EntityID',
  373         Config => {
  374             ID       => undef,
  375             EntityID => undef,
  376             UserID   => $UserID,
  377         },
  378         Success => 0,
  379     },
  380     {
  381         Name   => 'ActivityDialogGet Test 3: No UserID',
  382         Config => {
  383             ID       => 1,
  384             EntityID => undef,
  385             UserID   => undef,
  386         },
  387         Success => 0,
  388     },
  389     {
  390         Name   => 'ActivityDialogGet Test 4: Wrong ID',
  391         Config => {
  392             ID       => '9999999',
  393             EntityID => undef,
  394             UserID   => $UserID,
  395         },
  396         Success => 0,
  397     },
  398     {
  399         Name   => 'ActivityDialogGet Test 5: Wrong EntityID',
  400         Config => {
  401             ID       => undef,
  402             EntityID => '9999999',
  403             UserID   => $UserID,
  404         },
  405         Success => 0,
  406     },
  407     {
  408         Name   => 'ActivityDialogGet Test 6: Correct ASCII, W/ID',
  409         Config => {
  410             ID       => $AddedActivityDialogsList[0],
  411             EntityID => undef,
  412             UserID   => $UserID,
  413         },
  414         Success => 1,
  415     },
  416     {
  417         Name   => 'ActivityDialogGet Test 7: Correct UTF8, W/ID',
  418         Config => {
  419             ID       => $AddedActivityDialogsList[1],
  420             EntityID => undef,
  421             UserID   => $UserID,
  422         },
  423         Success => 1,
  424     },
  425     {
  426         Name   => 'ActivityDialogGet Test 8: Correct UTF82, W/ID',
  427         Config => {
  428             ID       => $AddedActivityDialogsList[2],
  429             EntityID => undef,
  430             UserID   => $UserID,
  431         },
  432         Success => 1,
  433     },
  434     {
  435         Name   => 'ActivityDialogGet Test 9: Correct ASCII, W/EntityID,',
  436         Config => {
  437             ID       => undef,
  438             EntityID => $AddedActivityDialogs{ $AddedActivityDialogsList[0] }->{EntityID},
  439             UserID   => $UserID,
  440         },
  441         Success => 1,
  442     },
  443     {
  444         Name   => 'ActivityDialogGet Test 10: Correct UTF8, W/EntityID,',
  445         Config => {
  446             ID       => undef,
  447             EntityID => $AddedActivityDialogs{ $AddedActivityDialogsList[1] }->{EntityID},
  448             UserID   => $UserID,
  449         },
  450         Success => 1,
  451     },
  452     {
  453         Name   => 'ActivityDialogGet Test 11: Correct UTF82, W/EntityID,',
  454         Config => {
  455             ID       => undef,
  456             EntityID => $AddedActivityDialogs{ $AddedActivityDialogsList[2] }->{EntityID},
  457             UserID   => $UserID,
  458         },
  459         Success => 1,
  460     },
  461 );
  462 
  463 for my $Test (@Tests) {
  464     my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet( %{ $Test->{Config} } );
  465 
  466     if ( $Test->{Success} ) {
  467         $Self->Is(
  468             ref $ActivityDialog,
  469             'HASH',
  470             "$Test->{Name} | ActivityDialog structure is HASH",
  471         );
  472         $Self->True(
  473             IsHashRefWithData($ActivityDialog),
  474             "$Test->{Name} | ActivityDialog structure is non empty HASH",
  475         );
  476 
  477         # check cache
  478         my $CacheKey;
  479         if ( $Test->{Config}->{ID} ) {
  480             $CacheKey = 'ActivityDialogGet::ID::' . $Test->{Config}->{ID};
  481         }
  482         else {
  483             $CacheKey = 'ActivityDialogGet::EntityID::' . $Test->{Config}->{EntityID};
  484         }
  485 
  486         my $Cache = $CacheObject->Get(
  487             Type => 'ProcessManagement_ActivityDialog',
  488             Key  => $CacheKey,
  489         );
  490 
  491         $Self->IsDeeply(
  492             $Cache,
  493             $ActivityDialog,
  494             "$Test->{Name} | ActivityDialog cache"
  495         );
  496 
  497         # remove not need parameters
  498         my %ExpectedActivityDialog = %{ $AddedActivityDialogs{ $ActivityDialog->{ID} } };
  499         delete $ExpectedActivityDialog{UserID};
  500 
  501         # create a variable copy otherwise the cache will be altered
  502         my %ActivityDialogCopy = %{$ActivityDialog};
  503 
  504         for my $Attribute (qw(ID CreateTime ChangeTime)) {
  505             $Self->IsNot(
  506                 $ActivityDialogCopy{$Attribute},
  507                 undef,
  508                 "$Test->{Name} | ActivityDialog{$Attribute} should not be undef",
  509             );
  510             delete $ActivityDialogCopy{$Attribute};
  511         }
  512 
  513         $Self->IsDeeply(
  514             \%ActivityDialogCopy,
  515             \%ExpectedActivityDialog,
  516             "$Test->{Name} | ActivityDialog"
  517         );
  518     }
  519     else {
  520         $Self->False(
  521             ref $ActivityDialog eq 'HASH',
  522             "$Test->{Name} | ActivityDialog structure is not HASH",
  523         );
  524         $Self->Is(
  525             $ActivityDialog,
  526             undef,
  527             "$Test->{Name} | ActivityDialog should be undefined",
  528         );
  529     }
  530 }
  531 
  532 #
  533 # ActivityDialogUpdate() tests
  534 #
  535 @Tests = (
  536     {
  537         Name    => 'ActivityDialogUpdate Test 1: No params',
  538         Config  => {},
  539         Success => 0,
  540     },
  541     {
  542         Name   => 'ActivityDialogUpdate Test 2: No ID',
  543         Config => {
  544             ID       => undef,
  545             EntityID => $RandomID . '-U',
  546             Name     => "ActivityDialog-$RandomID",
  547             Config   => {
  548                 Description => 'a Description',
  549             },
  550             UserID => $UserID,
  551         },
  552         Success => 0,
  553     },
  554     {
  555         Name   => 'ActivityDialogUpdate Test 3: No EntityID',
  556         Config => {
  557             ID       => 1,
  558             EntityID => undef,
  559             Name     => "ActivityDialog-$RandomID",
  560             Config   => {
  561                 Description => 'a Description',
  562             },
  563             UserID => $UserID,
  564         },
  565         Success => 0,
  566     },
  567     {
  568         Name   => 'ActivityDialogUpdate Test 4: No Name',
  569         Config => {
  570             ID       => 1,
  571             EntityID => $RandomID . '-U',
  572             Name     => undef,
  573             Config   => {
  574                 Description => 'a Description',
  575             },
  576             UserID => $UserID,
  577         },
  578         Success => 0,
  579     },
  580     {
  581         Name   => 'ActivityDialogUpdate Test 5: No Config',
  582         Config => {
  583             ID       => 1,
  584             EntityID => $RandomID . '-U',
  585             Name     => "ActivityDialog-$RandomID",
  586             Config   => undef,
  587             UserID   => $UserID,
  588         },
  589         Success => 0,
  590     },
  591     {
  592         Name   => 'ActivityDialogUpdate Test 6: No UserID',
  593         Config => {
  594             ID       => 1,
  595             EntityID => $RandomID . '-U',
  596             Name     => "ActivityDialog-$RandomID",
  597             Config   => {
  598                 Description => 'a Description',
  599             },
  600             UserID => undef,
  601         },
  602         Success => 0,
  603     },
  604     {
  605         Name   => 'ActivityDialogUpdate Test 7: Correct ASCII',
  606         Config => {
  607             ID       => $AddedActivityDialogsList[0],
  608             EntityID => $RandomID . '-U',
  609             Name     => "ActivityDialog-$RandomID -U",
  610             Config   => {
  611                 DescriptionShort => 'a Description-u',
  612                 Fields           => {
  613                     PriorityID => {
  614                         DescriptionShort => 'Short description',
  615                         DescriptionLong  => 'Longer description',
  616                         Display          => 0,
  617                         DefaultValue     => 1,
  618                     },
  619                 },
  620                 FieldOrder => ['PriotityID'],
  621             },
  622             UserID => $UserID,
  623         },
  624         Success  => 1,
  625         UpdateDB => 1
  626     },
  627     {
  628         Name   => 'ActivityDialogUpdate Test 8: Correct UTF8',
  629         Config => {
  630             ID       => $AddedActivityDialogsList[1],
  631             EntityID => $RandomID . '-1-U',
  632             Name     => "ActivityDialog-$RandomID -!§$%&/()=?Ü*ÄÖL:L@,.--U",
  633             Config   => {
  634                 DescriptionShort => 'a Description !§$%&/()=?Ü*ÄÖL:L@,.--U',
  635                 Fields           => {
  636                     PriorityID => {
  637                         DescriptionShort => 'Short description',
  638                         DescriptionLong  => 'Longer description',
  639                         Display          => 0,
  640                         DefaultValue     => 1,
  641                     },
  642                     StateID => {
  643                         DescriptionShort => 'Short description',
  644                         DescriptionLong  => 'Longer description',
  645                         Display          => 0,
  646                         DefaultValue     => 1,
  647                     },
  648                 },
  649                 FieldOrder => [ 'PriotityID', 'StateID' ],
  650             },
  651             UserID => $UserID,
  652         },
  653         Success  => 1,
  654         UpdateDB => 1
  655     },
  656     {
  657         Name   => 'ActivityDialogUpdate Test 9: Correct UTF8 2',
  658         Config => {
  659             ID       => $AddedActivityDialogsList[1],
  660             EntityID => $RandomID . '-2-U',
  661             Name     => "ActivityDialog-$RandomID--äöüßÄÖÜ€исáéíúóúÁÉÍÓÚñё-U",
  662             Config   => {
  663                 DescriptionShort =>
  664                     'a Description -äöüßÄÖÜ€исáéíúóúÁÉÍÓÚñÑ--U',
  665                 Fields => {
  666                     PriorityID => {
  667                         DescriptionShort => 'Short description',
  668                         DescriptionLong  => 'Longer description',
  669                         Display          => 0,
  670                         DefaultValue     => 1,
  671                     },
  672                     StateID => {
  673                         DescriptionShort => 'Short description',
  674                         DescriptionLong  => 'Longer description',
  675                         Display          => 0,
  676                         DefaultValue     => 1,
  677                     },
  678                     QueueID => {
  679                         DescriptionShort => 'Short description',
  680                         DescriptionLong  => 'Longer description',
  681                         Display          => 0,
  682                         DefaultValue     => 1,
  683                     },
  684                 },
  685                 FieldOrder => [ 'PriotityID', 'StateID', 'QueueID' ],
  686             },
  687             UserID => $UserID,
  688         },
  689         Success  => 1,
  690         UpdateDB => 1
  691     },
  692     {
  693         Name   => 'ActivityDialogUpdate Test 10: Correct ASCII No DBUpdate',
  694         Config => {
  695             ID       => $AddedActivityDialogsList[0],
  696             EntityID => $RandomID . '-U',
  697             Name     => "ActivityDialog-$RandomID -U",
  698             Config   => {
  699                 Description => 'a Description-U',
  700             },
  701             UserID => $UserID,
  702         },
  703         Success  => 1,
  704         UpdateDB => 0,
  705     },
  706 );
  707 
  708 for my $Test (@Tests) {
  709 
  710     # get the old ActivityDialog (if any)
  711     my $OldActivityDialog = $ActivityDialogObject->ActivityDialogGet(
  712         ID     => $Test->{Config}->{ID} || 0,
  713         UserID => $Test->{Config}->{UserID},
  714     );
  715 
  716     if ( $Test->{Success} ) {
  717 
  718         # try to update the ActivityDialog
  719         print "Force a gap between create and update ActivityDialog, Waiting 2s\n";
  720 
  721         # wait 2 seconds
  722         $Helper->FixedTimeAddSeconds(2);
  723 
  724         my $Success = $ActivityDialogObject->ActivityDialogUpdate( %{ $Test->{Config} } );
  725 
  726         $Self->IsNot(
  727             $Success,
  728             0,
  729             "$Test->{Name} | Result should be 1"
  730         );
  731 
  732         # check cache
  733         my $CacheKey = 'ActivityDialogGet::ID::' . $Test->{Config}->{ID};
  734 
  735         my $Cache = $CacheObject->Get(
  736             Type => 'ProcessManagement_ActivityDialog',
  737             Key  => $CacheKey,
  738         );
  739 
  740         if ( $Test->{UpdateDB} ) {
  741             $Self->Is(
  742                 $Cache,
  743                 undef,
  744                 "$Test->{Name} | Cache should be deleted after update, should be undef",
  745             );
  746         }
  747         else {
  748             $Self->IsNot(
  749                 $Cache,
  750                 undef,
  751                 "$Test->{Name} | Cache should not be deleted after update, since no update needed",
  752             );
  753         }
  754 
  755         # get the new ActivityDialog
  756         my $NewActivityDialog = $ActivityDialogObject->ActivityDialogGet(
  757             ID     => $Test->{Config}->{ID},
  758             UserID => $Test->{Config}->{UserID},
  759         );
  760 
  761         # check cache
  762         $Cache = $CacheObject->Get(
  763             Type => 'ProcessManagement_ActivityDialog',
  764             Key  => $CacheKey,
  765         );
  766 
  767         $Self->IsDeeply(
  768             $Cache,
  769             $NewActivityDialog,
  770             "$Test->{Name} | Cache is equal to updated ActivityDialog",
  771         );
  772 
  773         if ( $Test->{UpdateDB} ) {
  774             $Self->IsNotDeeply(
  775                 $NewActivityDialog,
  776                 $OldActivityDialog,
  777                 "$Test->{Name} | Updated ActivityDialog is different than original",
  778             );
  779 
  780             # check create and change times
  781             $Self->Is(
  782                 $NewActivityDialog->{CreateTime},
  783                 $OldActivityDialog->{CreateTime},
  784                 "$Test->{Name} | Updated ActivityDialog create time should not change",
  785             );
  786             $Self->IsNot(
  787                 $NewActivityDialog->{ChangeTime},
  788                 $OldActivityDialog->{ChangeTime},
  789                 "$Test->{Name} | Updated ActivityDialog change time should be different",
  790             );
  791 
  792             # remove not need parameters
  793             my %ExpectedActivityDialog = %{ $Test->{Config} };
  794             delete $ExpectedActivityDialog{UserID};
  795 
  796             # create a variable copy otherwise the cache will be altered
  797             my %NewActivityDialogCopy = %{$NewActivityDialog};
  798 
  799             for my $Attribute (qw( Activities CreateTime ChangeTime State)) {
  800                 delete $NewActivityDialogCopy{$Attribute};
  801             }
  802 
  803             $Self->IsDeeply(
  804                 \%NewActivityDialogCopy,
  805                 \%ExpectedActivityDialog,
  806                 "$Test->{Name} | ActivityDialog"
  807             );
  808         }
  809         else {
  810             $Self->IsDeeply(
  811                 $NewActivityDialog,
  812                 $OldActivityDialog,
  813                 "$Test->{Name} | Updated ActivityDialog is equal than original",
  814             );
  815         }
  816     }
  817     else {
  818         my $Success = $ActivityDialogObject->ActivityDialogUpdate( %{ $Test->{Config} } );
  819 
  820         $Self->False(
  821             $Success,
  822             "$Test->{Name} | Result should fail",
  823         );
  824     }
  825 }
  826 
  827 #
  828 # ActivityDialogList() tests
  829 #
  830 
  831 # no params
  832 my $TestActivityDialogList = $ActivityDialogObject->ActivityDialogList();
  833 
  834 $Self->Is(
  835     $TestActivityDialogList,
  836     undef,
  837     "ActivityDialogList Test 1: No Params | Should be undef",
  838 );
  839 
  840 # normal ActivityDialog list
  841 $TestActivityDialogList = $ActivityDialogObject->ActivityDialogList( UserID => $UserID );
  842 
  843 $Self->Is(
  844     ref $TestActivityDialogList,
  845     'HASH',
  846     "ActivityDialogList Test 2: All | Should be a HASH",
  847 );
  848 
  849 $Self->True(
  850     IsHashRefWithData($TestActivityDialogList),
  851     "ActivityDialogList Test 2: All | Should be not empty HASH",
  852 );
  853 
  854 $Self->IsNotDeeply(
  855     $TestActivityDialogList,
  856     $OriginalActivityDialogList,
  857     "ActivityDialogList Test 2: All | Should be different than the original",
  858 );
  859 
  860 # create a variable copy otherwise the cache will be altered
  861 my %TestActivityDialogListCopy = %{$TestActivityDialogList};
  862 
  863 # delete original ActivityDialogs
  864 for my $ActivityDialogID ( sort keys %{$OriginalActivityDialogList} ) {
  865     delete $TestActivityDialogListCopy{$ActivityDialogID};
  866 }
  867 
  868 $Self->Is(
  869     scalar keys %TestActivityDialogListCopy,
  870     scalar @AddedActivityDialogsList,
  871     "ActivityDialogList Test 2: All ActivityDialog | Number of ActivityDialogs match added ActivityDialogs",
  872 );
  873 
  874 my $Counter = 0;
  875 for my $ActivityDialogID ( sort { $a <=> $b } keys %TestActivityDialogListCopy ) {
  876     $Self->Is(
  877         $ActivityDialogID,
  878         $AddedActivityDialogsList[$Counter],
  879         "ActivityDialogList Test 2: All | ActivityDialogID match AddedActivityDialogID",
  880     );
  881     $Counter++;
  882 }
  883 
  884 #
  885 # ActivityDialogDelete() (test for fail, test for success are done by removing activity dialogs
  886 # at the end)
  887 #
  888 @Tests = (
  889     {
  890         Name    => 'ActivityDialogDelete Test 1: No params',
  891         Config  => {},
  892         Success => 0,
  893     },
  894     {
  895         Name   => 'ActivityDialogDelete Test 2: No ActivityDialog ID',
  896         Config => {
  897             ID     => undef,
  898             UserID => $RandomID,
  899         },
  900         Success => 0,
  901     },
  902     {
  903         Name   => 'ActivityDialogDelete Test 3: No UserID',
  904         Config => {
  905             ID     => $RandomID,
  906             UserID => undef,
  907         },
  908         Success => 0,
  909     },
  910     {
  911         Name   => 'ActivityDialogDelete Test 4: Wrong ActivityDialog ID',
  912         Config => {
  913             ID     => '9999999',
  914             UserID => $UserID,
  915         },
  916         Success => 0,
  917     },
  918 );
  919 
  920 for my $Test (@Tests) {
  921     my $Success = $ActivityDialogObject->ActivityDialogDelete( %{ $Test->{Config} } );
  922 
  923     if ( $Test->{Success} ) {
  924         $Self->True(
  925             $Success,
  926             "$Test->{Name} | ActivityDialog deleted with true",
  927         );
  928     }
  929     else {
  930         $Self->False(
  931             $Success,
  932             "$Test->{Name} | ActivityDialog delete with false",
  933         );
  934     }
  935 }
  936 
  937 #
  938 # ActivityDialogListGet() tests
  939 #
  940 
  941 my $FullList = $ActivityDialogObject->ActivityDialogListGet(
  942     UserID => undef,
  943 );
  944 
  945 $Self->IsNot(
  946     ref $FullList,
  947     'ARRAY',
  948     "ActivityDialogListGet Test 1: No UserID | List Should not be an array",
  949 );
  950 
  951 # get the List of activity dialogs with all details
  952 $FullList = $ActivityDialogObject->ActivityDialogListGet(
  953     UserID => $UserID,
  954 );
  955 
  956 # get simple list of activity dialogs
  957 my $List = $ActivityDialogObject->ActivityDialogList(
  958     UserID => $UserID,
  959 );
  960 
  961 # create the list of activity dialogs with details manually
  962 my $ExpectedActivityDialogList;
  963 for my $ActivityDialogID ( sort { $a <=> $b } keys %{$List} ) {
  964 
  965     my $ActivityDialogData = $ActivityDialogObject->ActivityDialogGet(
  966         ID     => $ActivityDialogID,
  967         UserID => $UserID,
  968     );
  969     push @{$ExpectedActivityDialogList}, $ActivityDialogData;
  970 }
  971 
  972 $Self->Is(
  973     ref $FullList,
  974     'ARRAY',
  975     "ActivityDialogListGet Test 2: Correct List | Should be an array",
  976 );
  977 
  978 $Self->True(
  979     IsArrayRefWithData($FullList),
  980     "ActivityDialogListGet Test 2: Correct List | The list is not empty",
  981 );
  982 
  983 $Self->IsDeeply(
  984     $FullList,
  985     $ExpectedActivityDialogList,
  986     "ActivityDialogListGet Test 2: Correct List | Activity List",
  987 );
  988 
  989 # check cache
  990 my $CacheKey = 'ActivityDialogListGet';
  991 
  992 my $Cache = $CacheObject->Get(
  993     Type => 'ProcessManagement_ActivityDialog',
  994     Key  => $CacheKey,
  995 );
  996 
  997 $Self->IsDeeply(
  998     $Cache,
  999     $FullList,
 1000     "ActivityDialogListGet Test 2: Correct List | Cache",
 1001 );
 1002 
 1003 # cleanup is done by RestoreDatabase
 1004 
 1005 1;