"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/scripts/test/ProcessManagement/DB/Activity.t" (12 Dec 2019, 28112 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.

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