1# -- 2# Copyright (C) 2001-2020 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) 10use strict; 11use warnings; 12use utf8; 13 14use vars (qw($Self)); 15 16use Kernel::System::VariableCheck qw(:all); 17 18# get needed objects 19my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Activity'); 20my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog'); 21my $ProcessObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Process'); 22my $TransitionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Transition'); 23my $TransitionActionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::TransitionAction'); 24 25# get helper object 26$Kernel::OM->ObjectParamAdd( 27 'Kernel::System::UnitTest::Helper' => { 28 RestoreDatabase => 1, 29 }, 30); 31my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper'); 32 33# define needed variables 34my $UserID = 1; 35 36# Add process Parts 37my $ProcessID = $ProcessObject->ProcessAdd( 38 EntityID => 'P-Test1', 39 Name => 'Process 1', 40 StateEntityID => 'S1', 41 Layout => {}, 42 Config => { 43 Description => 'a Description', 44 StartActivity => 'ATest1', 45 StartActivityDialog => 'ADTest1', 46 Path => { # New way: 47 'A-Test1' => { 48 'T-Test1' => { 49 'ActivityID' => 'A-Test2', 50 'Action' => [ 51 'TA-Test1', 52 'TA-Test2', 53 'TA-Test3', 54 ], 55 }, 56 'T-Test2' => { 57 'ActivityID' => 'A-Test3', 58 }, 59 }, 60 }, 61 }, 62 UserID => $UserID, 63); 64 65$Self->IsNot( 66 $ProcessID, 67 undef, 68 "ProcessADD() | ProcessID is not undef", 69); 70 71my $ActivityID = $ActivityObject->ActivityAdd( 72 EntityID => 'A-Test1', 73 Name => 'Activity 1', 74 Config => { 75 ActivityDialog => { 76 1 => 'AD-Test1', 77 2 => { 78 ActivityDialogID => 'AD-Test2', 79 Overwrite => { 80 FieldOrder => [ 1, 2, 4, 3 ], 81 }, 82 }, 83 }, 84 }, 85 UserID => $UserID, 86); 87 88$Self->IsNot( 89 $ActivityID, 90 undef, 91 "ActivityADD() | ActivityID is not undef", 92); 93 94my $ActivityDialogID = $ActivityDialogObject->ActivityDialogAdd( 95 EntityID => 'AD-Test1', 96 Name => 'Activity Dialog 1', 97 Config => { 98 DescriptionShort => 'Short description', 99 DescriptionLong => 'Longer description', 100 Fields => { 101 DynamicField_Marke => { 102 DescriptionShort => 'Short description', 103 DescriptionLong => 'Longer description', 104 Display => 2, 105 }, 106 DynamicField_VWModell => { 107 DescriptionShort => 'Short description', 108 DescriptionLong => 'Longer description', 109 Display => 2, 110 }, 111 DynamicField_PeugeotModell => { 112 DescriptionShort => 'Short description', 113 DescriptionLong => 'Longer description', 114 Display => 0, 115 }, 116 Title => { 117 DescriptionShort => 'Short description', 118 DescriptionLong => 'Longer description', 119 Display => 2, 120 DefaultValue => 'Default title', 121 }, 122 PriorityID => { 123 DescriptionShort => 'Short description', 124 DescriptionLong => 'Longer description', 125 Display => 0, 126 DefaultValue => 1, 127 }, 128 StateID => { 129 DescriptionShort => 'Short description', 130 DescriptionLong => 'Longer description', 131 Display => 0, 132 DefaultValue => 1, 133 }, 134 QueueID => { 135 DescriptionShort => 'Short description', 136 DescriptionLong => 'Longer description', 137 Display => 0, 138 DefaultValue => 1, 139 }, 140 Lock => { 141 DescriptionShort => 'Short description', 142 DescriptionLong => 'Longer description', 143 Display => 0, 144 DefaultValue => 'unlock', 145 }, 146 CustomerID => { 147 DescriptionShort => 'Short description', 148 DescriptionLong => 'Longer description', 149 Display => 0, 150 DefaultValue => 12345, 151 }, 152 153 }, 154 FieldOrder => [ 155 'StateID', 156 'DynamicField_Marke', 157 'DynamicField_PeugeotModell', 158 'DynamicField_PeugeotModell', 159 ], 160 Permission => 'ro', 161 RequiredLock => '1', 162 SubmitAdviceText => 'Waring test...', 163 SubmitButtonText => 'Submit äëïöüÄËÏÖÜáéíóúÁÉÍÓÚñÑ€исß', 164 }, 165 UserID => $UserID, 166); 167 168$Self->IsNot( 169 $ActivityDialogID, 170 undef, 171 "ActivityDialogADD() | ActivityDialogID is not undef", 172); 173 174my $TransitionID = $TransitionObject->TransitionAdd( 175 EntityID => 'T-Test1', 176 Name => 'Transition 1', 177 Config => { 178 ConditionLinking => 'or', 179 Condition => { 180 Cond1 => { 181 Type => 'and', 182 Fields => { 183 DynamicField_Marke => { 184 Type => 'String', 185 Match => 'Teststring', 186 }, 187 DynamicField_VWModell => ['1'], 188 DynamicField_Regex => { 189 Type => 'Regexp', 190 Match => 'My[ ]Regexp', 191 }, 192 DynamicField_Regex2 => { 193 Type => 'Regexp', 194 Match => '.*', 195 }, 196 DynamicField_String => { 197 Type => 'String', 198 Match => 'Teststring', 199 }, 200 }, 201 }, 202 Cond2 => { 203 DynamicField_Marke => ['2'], 204 DynamicField_PeugeotModell => ['1'], 205 }, 206 }, 207 }, 208 UserID => $UserID, 209); 210 211$Self->IsNot( 212 $TransitionID, 213 undef, 214 "TransitionADD() | TransitionID is not undef", 215); 216 217my $TransitionActionID = $TransitionActionObject->TransitionActionAdd( 218 EntityID => 'TA-Test1', 219 Name => 'Queue Move', 220 Config => { 221 Module => 'Kernel::System::Process::Transition::Action::QueueMove', 222 Config => { 223 TargetQueue => 'Raw', 224 NewOwner => 'root@localhost', 225 }, 226 }, 227 UserID => $UserID, 228); 229 230$Self->IsNot( 231 $TransitionActionID, 232 undef, 233 "TransitionActionADD() | TransitionActionID is not undef", 234); 235 236my $ExpectedResult; 237 238$ExpectedResult->{Transition} = { 239 'T-Test1' => { 240 Name => 'Transition 1', 241 Condition => { 242 Cond1 => { 243 Type => 'and', 244 Fields => { 245 DynamicField_Marke => { 246 Type => 'String', 247 Match => 'Teststring', 248 }, 249 DynamicField_VWModell => ['1'], 250 DynamicField_Regex => { 251 Type => 'Regexp', 252 Match => 'My[ ]Regexp', 253 }, 254 DynamicField_Regex2 => { 255 Type => 'Regexp', 256 Match => '.*', 257 }, 258 DynamicField_String => { 259 Type => 'String', 260 Match => 'Teststring', 261 }, 262 }, 263 }, 264 Cond2 => { 265 DynamicField_Marke => ['2'], 266 DynamicField_PeugeotModell => ['1'], 267 }, 268 }, 269 ConditionLinking => 'or', 270 }, 271}; 272 273# actual tests 274my $ConfigHash = $ProcessObject->ProcessDump( 275 ResultType => 'HASH', 276 UserID => 1, 277); 278 279$Self->Is( 280 ref $ConfigHash, 281 'HASH', 282 "ProcessDump() HASH | Output is a hash", 283); 284 285# remove elements for easy compare 286delete $ConfigHash->{Transition}->{'T-Test1'}->{CreateTime}; 287delete $ConfigHash->{Transition}->{'T-Test1'}->{ChangeTime}; 288 289$Self->IsDeeply( 290 $ConfigHash->{Transition}->{'T-Test1'}, 291 $ExpectedResult->{Transition}->{'T-Test1'}, 292 "ProcessDump() HASH | Transition Expected result", 293); 294 295my $Output = $ProcessObject->ProcessDump( UserID => $UserID ); 296 297$Self->IsNot( 298 length $Output, 299 0, 300 "ProcessDump() STRING | Output length", 301); 302 303for my $Part ( 304 qw( 305 Process Process::Activity Process::ActivityDialog Process::Transition Process::TransitionAction 306 ) 307 ) 308{ 309 my $Success; 310 if ( $Output =~ m{ \$Self->\{ '$Part' \} \s+? = \s+? \{ }msx ) { 311 $Success = 1; 312 } 313 $Self->True( 314 $Success, 315 "ProcessDump() STRING | contains \$Self->{$Part} = { with True", 316 ); 317} 318 319for my $Entity (qw(P-Test1 A-Test1 AD-Test1 T-Test1 TA-Test1)) { 320 my $Success; 321 if ( $Output =~ m{'$Entity' \s+? =\> \s+? \{ }msx ) { 322 $Success = 1; 323 } 324 $Self->True( 325 $Success, 326 "ProcessDump() STRING | contains $Entity => { with True", 327 ); 328} 329 330# cleanup is done by RestoreDatabase 331 3321; 333