1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
## no critic (Modules::RequireExplicitPackage)
use strict;
use warnings;
use utf8;
use vars (qw($Self));
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest::Helper' => {
RestoreDatabase => 1,
UseTmpArticleDir => 1,
},
);
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
$ConfigObject->Set(
Key => 'CheckEmailAddresses',
Value => '0',
);
# Force rich text editor.
my $Success = $ConfigObject->Set(
Key => 'Frontend::RichText',
Value => 1,
);
$Self->True(
$Success,
'Force RichText with true',
);
# Use DoNotSendEmail email backend.
$Success = $ConfigObject->Set(
Key => 'SendmailModule',
Value => 'Kernel::System::Email::DoNotSendEmail',
);
$Self->True(
$Success,
'Set DoNotSendEmail backend with true',
);
# Set Default Language.
$Success = $ConfigObject->Set(
Key => 'DefaultLanguage',
Value => 'en',
);
$Self->True(
$Success,
'Set default language to English',
);
my $RandomID = $HelperObject->GetRandomID();
# Create customer users.
my $TestUserLoginEN = $HelperObject->TestCustomerUserCreate(
Language => 'en',
);
my $TestUserLoginDE = $HelperObject->TestCustomerUserCreate(
Language => 'de',
);
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
# Create new queue.
my $QueueName = 'Some::Queue' . $RandomID;
my %QueueTemplate = (
Name => $QueueName,
ValidID => 1,
GroupID => 1,
SystemAddressID => 1,
SalutationID => 1,
SignatureID => 1,
Comment => 'Some comment',
UserID => 1,
);
my $QueueID = $QueueObject->QueueAdd(%QueueTemplate);
$Self->IsNot(
$QueueID,
undef,
'QueueAdd() - QueueID should not be undef',
);
my $AutoResponseObject = $Kernel::OM->Get('Kernel::System::AutoResponse');
# Create new auto response.
my $AutoResonseName = 'Some::AutoResponse' . $RandomID;
my %AutoResponseTemplate = (
Name => $AutoResonseName,
ValidID => 1,
Subject => 'Some Subject..',
Response => 'S: <OTRS_TICKET_State>', # include non-breaking space (bug#12097)
ContentType => 'text/html',
AddressID => 1,
TypeID => 4, # auto reply/new ticket
UserID => 1,
);
my $AutoResponseID = $AutoResponseObject->AutoResponseAdd(%AutoResponseTemplate);
$Self->IsNot(
$AutoResponseID,
undef,
'AutoResponseAdd() - AutoResonseID should not be undef',
);
# Assign auto response to queue.
$Success = $AutoResponseObject->AutoResponseQueue(
QueueID => $QueueID,
AutoResponseIDs => [$AutoResponseID],
UserID => 1,
);
$Self->True(
$Success,
"AutoResponseQueue() - assigned auto response - $AutoResonseName to queue - $QueueName",
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(
ChannelName => 'Email',
);
# Create a new ticket.
my $TicketID = $TicketObject->TicketCreate(
Title => 'Some Ticket Title',
QueueID => $QueueID,
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => '123465',
CustomerUser => 'customer@example.com',
OwnerID => 1,
UserID => 1,
);
$Self->IsNot(
$TicketID,
undef,
'TicketCreate() - TicketID should not be undef',
);
my $HTMLTemplate
= '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">%s</body></html>';
my @Tests = (
{
Name => 'English Language Customer',
CustomerUser => $TestUserLoginEN,
ExpectedResult => sprintf( $HTMLTemplate, 'S: new' ),
},
{
Name => 'German Language Customer',
CustomerUser => $TestUserLoginDE,
ExpectedResult => sprintf( $HTMLTemplate, 'S: neu' ),
},
{
Name => 'Not existing Customer',
CustomerUser => 'customer@example.com',
ExpectedResult => sprintf( $HTMLTemplate, 'S: new' ),
},
);
my $TemplateGeneratorObject = $Kernel::OM->Get('Kernel::System::TemplateGenerator');
for my $Test (@Tests) {
# Set ticket customer.
my $Success = $TicketObject->TicketCustomerSet(
User => $Test->{CustomerUser},
TicketID => $TicketID,
UserID => 1,
);
$Self->True(
$Success,
"$Test->{Name} TicketCustomerSet() - for customer $Test->{CustomerUser} with true",
);
# Get assigned auto response.
my %AutoResponse = $TemplateGeneratorObject->AutoResponse(
TicketID => $TicketID,
OrigHeader => {},
AutoResponseType => 'auto reply/new ticket',
UserID => 1,
);
$Self->Is(
$AutoResponse{Text},
$Test->{ExpectedResult},
"$Test->{Name} AutoResponse() - Text"
);
# Create auto response article (bug#12097).
my $ArticleID = $ArticleBackendObject->SendAutoResponse(
TicketID => $TicketID,
AutoResponseType => 'auto reply/new ticket',
OrigHeader => {
From => $Test->{CustomerUser},
},
IsVisibleForCustomer => 1,
UserID => 1,
);
$Self->IsNot(
$ArticleID,
undef,
"$Test->{Name} SendAutoResponse() - ArticleID should not be undef"
);
}
# Check replacing time attribute tags (see bug#13865 - https://bugs.otrs.org/show_bug.cgi?id=13865).
# Create datetime dynamic field.
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
my $DynamicFieldName = "DateTimeDF$RandomID";
my $DynamicFieldID = $DynamicFieldObject->DynamicFieldAdd(
Name => $DynamicFieldName,
Label => $DynamicFieldName,
FieldOrder => 9991,
FieldType => 'DateTime',
ObjectType => 'Ticket',
Config => {},
ValidID => 1,
UserID => 1,
);
$Self->True(
$DynamicFieldID,
"DynamicFieldID $DynamicFieldID is created",
);
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
ID => $DynamicFieldID,
);
# Create test queue.
my $TestQueueID = $QueueObject->QueueAdd(
Name => "TestQueue$RandomID",
ValidID => 1,
GroupID => 1,
SystemAddressID => 1,
SalutationID => 1,
SignatureID => 1,
Comment => 'Some comment',
UserID => 1,
);
$Self->True(
$TestQueueID,
"TestQueueID $TestQueueID is created",
);
my $TestAutoResponse = '<!DOCTYPE html><html>' .
'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>'
. '<body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">'
. 'OTRS_TICKET_Created: <OTRS_TICKET_Created><br />'
. 'OTRS_TICKET_Changed: <OTRS_TICKET_Changed><br />'
. 'OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. ': <OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '><br />'
. 'OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '_Value: <OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '_Value><br />'
. '</body>'
. '</html>';
# Create test auto response with tags.
my $TestAutoResponseID = $AutoResponseObject->AutoResponseAdd(
Name => "TestAutoResponse$RandomID",
ValidID => 1,
Subject => "$RandomID - <OTRS_TICKET_Created>",
Response => $TestAutoResponse,
ContentType => 'text/html',
AddressID => 1,
TypeID => 1,
UserID => 1,
);
$Self->True(
$TestAutoResponseID,
"TestAutoResponseID $TestAutoResponseID is created",
);
# Assign auto response to queue.
$Success = $AutoResponseObject->AutoResponseQueue(
QueueID => $TestQueueID,
AutoResponseIDs => [$TestAutoResponseID],
UserID => 1,
);
$Self->True(
$Success,
"Auto response ID $TestAutoResponseID is assigned to QueueID $TestQueueID",
);
# Set fixed time.
$HelperObject->FixedTimeSet(
$Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
String => '2018-12-06 12:00:00',
},
)->ToEpoch()
);
# Create test customer user.
my $TestCustomerUserLogin = $HelperObject->TestCustomerUserCreate();
# Create test ticket.
my $TestTicketID = $TicketObject->TicketCreate(
Title => 'Some Ticket Title',
QueueID => $TestQueueID,
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => $TestCustomerUserLogin,
CustomerUser => $TestCustomerUserLogin,
OwnerID => 1,
UserID => 1,
);
$Self->True(
$TestTicketID,
"TestTicketID $TestTicketID is created",
);
# Get ticket number.
my $TicketNumber = $TicketObject->TicketNumberLookup(
TicketID => $TestTicketID,
);
# Set datetime dynamic field value for test ticket.
$Success = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueSet(
DynamicFieldConfig => $DynamicFieldConfig,
Value => '2018-12-03 15:00:00',
UserID => 1,
ObjectID => $TestTicketID,
);
$Self->True(
$Success,
"Dynamic field value is set successfully",
);
@Tests = (
{
Timezone => 'Europe/Berlin',
Language => 'de',
ExpectedSubject => "[Ticket#$TicketNumber] $RandomID - 06.12.2018 13:00 (Europe/Berlin)",
ExpectedText =>
'<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">OTRS_TICKET_Created: 06.12.2018 13:00 (Europe/Berlin)<br />OTRS_TICKET_Changed: 06.12.2018 13:00 (Europe/Berlin)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. ': 2018-12-03 16:00:00 (Europe/Berlin)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '_Value: 03.12.2018 16:00 (Europe/Berlin)<br /></body></html>',
},
{
Timezone => 'America/Bogota',
Language => 'es',
ExpectedSubject => "[Ticket#$TicketNumber] $RandomID - 06/12/2018 - 07:00 (America/Bogota)",
ExpectedText =>
'<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">OTRS_TICKET_Created: 06/12/2018 - 07:00 (America/Bogota)<br />OTRS_TICKET_Changed: 06/12/2018 - 07:00 (America/Bogota)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. ': 2018-12-03 10:00:00 (America/Bogota)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '_Value: 03/12/2018 - 10:00 (America/Bogota)<br /></body></html>',
},
{
Timezone => 'Asia/Bangkok',
Language => 'en',
ExpectedSubject => "[Ticket#$TicketNumber] $RandomID - 12/06/2018 19:00 (Asia/Bangkok)",
ExpectedText =>
'<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">OTRS_TICKET_Created: 12/06/2018 19:00 (Asia/Bangkok)<br />OTRS_TICKET_Changed: 12/06/2018 19:00 (Asia/Bangkok)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. ': 2018-12-03 22:00:00 (Asia/Bangkok)<br />OTRS_TICKET_DynamicField_'
. $DynamicFieldName
. '_Value: 12/03/2018 22:00 (Asia/Bangkok)<br /></body></html>',
}
);
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
for my $Test (@Tests) {
# Set customer user's timezone and language.
$CustomerUserObject->SetPreferences(
Key => 'UserTimeZone',
Value => $Test->{Timezone},
UserID => $TestCustomerUserLogin,
);
$CustomerUserObject->SetPreferences(
Key => 'UserLanguage',
Value => $Test->{Language},
UserID => $TestCustomerUserLogin,
);
# Call AutoResponse function.
my %TestAutoResponse = $TemplateGeneratorObject->AutoResponse(
TicketID => $TestTicketID,
OrigHeader => {},
AutoResponseType => 'auto reply',
UserID => 1,
);
# Check replaced subject.
$Self->Is(
$TestAutoResponse{Subject},
$Test->{ExpectedSubject},
"AutoResponse subject - Language: $Test->{Language}, Timezone: $Test->{Timezone} - tags are replaced correctly"
);
# Check replaced text.
$Self->Is(
$TestAutoResponse{Text},
$Test->{ExpectedText},
"AutoResponse text - Language: $Test->{Language}, Timezone: $Test->{Timezone} - tags are replaced correctly"
);
}
# Cleanup is done by RestoreDatabase.
1;
|