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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
|
# --
# 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));
use Socket;
use MIME::Base64;
use Kernel::GenericInterface::Debugger;
use Kernel::GenericInterface::Operation::Ticket::TicketCreate;
use Kernel::GenericInterface::Operation::Session::SessionCreate;
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
# get needed objects
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
# Skip SSL certificate verification.
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest::Helper' => {
SkipSSLVerify => 1,
},
);
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $RandomID = $HelperObject->GetRandomID();
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Ticket::Type',
Value => 1,
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Ticket::Frontend::AccountTime',
Value => 1,
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Ticket::Frontend::NeedAccountedTime',
Value => 1,
);
# disable DNS lookups
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CheckMXRecord',
Value => 0,
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CheckEmailAddresses',
Value => 1,
);
# disable SessionCheckRemoteIP setting
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'SessionCheckRemoteIP',
Value => 0,
);
# enable customer groups support
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CustomerGroupSupport',
Value => 1,
);
# check if SSL Certificate verification is disabled
$Self->Is(
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME},
0,
'Disabled SSL certificates verification in environment'
);
my $TestOwnerLogin = $HelperObject->TestUserCreate();
my $TestResponsibleLogin = $HelperObject->TestUserCreate();
my $TestCustomerUserLogin = $HelperObject->TestCustomerUserCreate();
my $TestUserLogin = $HelperObject->TestUserCreate(
Groups => [ 'admin', 'users', ],
);
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
my $OwnerID = $UserObject->UserLookup(
UserLogin => $TestOwnerLogin,
);
my $ResponsibleID = $UserObject->UserLookup(
UserLogin => $TestResponsibleLogin,
);
my $UserID = $UserObject->UserLookup(
UserLogin => $TestUserLogin,
);
my $InvalidID = $Kernel::OM->Get('Kernel::System::Valid')->ValidLookup( Valid => 'invalid' );
# sanity test
$Self->IsNot(
$InvalidID,
undef,
"ValidLookup() for 'invalid' should not be undef"
);
# get group object
my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
# create a new group
my $GroupID = $GroupObject->GroupAdd(
Name => 'TestSpecial' . $RandomID,
Comment => 'comment describing the group', # optional
ValidID => 1,
UserID => 1,
);
my %GroupData = $GroupObject->GroupGet( ID => $GroupID );
# sanity check
$Self->True(
IsHashRefWithData( \%GroupData ),
"GroupGet() - for testing group",
);
# create queue object
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
my @Queues;
my @QueueProperties = (
{
Name => 'queue1' . $RandomID,
GroupID => 1,
},
{
Name => 'queue2' . $RandomID,
GroupID => $GroupID,
}
);
# create queues
for my $QueueProperty (@QueueProperties) {
my $QueueID = $QueueObject->QueueAdd(
%{$QueueProperty},
ValidID => 1,
SystemAddressID => 1,
SalutationID => 1,
SignatureID => 1,
Comment => 'Some comment',
UserID => 1,
);
# sanity check
$Self->True(
$QueueID,
"QueueAdd() - create testing queue",
);
my %QueueData = $QueueObject->QueueGet( ID => $QueueID );
push @Queues, \%QueueData;
}
# get type object
my $TypeObject = $Kernel::OM->Get('Kernel::System::Type');
# create new type
my $TypeID = $TypeObject->TypeAdd(
Name => 'TestType' . $RandomID,
ValidID => 1,
UserID => 1,
);
# sanity check
$Self->True(
$TypeID,
"TypeAdd() - create testing type",
);
my %TypeData = $TypeObject->TypeGet(
ID => $TypeID,
);
# sanity check
$Self->True(
IsHashRefWithData( \%TypeData ),
"TypeGet() - for testing type",
);
# create service object
my $ServiceObject = $Kernel::OM->Get('Kernel::System::Service');
my $IsITSMInstalled = $Kernel::OM->Get('Kernel::System::Util')->IsITSMInstalled();
my %ITSMCoreSLA;
my %ITSMCoreService;
if ($IsITSMInstalled) {
# get the list of service types from general catalog
my $ServiceTypeList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
Class => 'ITSM::Service::Type',
);
# build a lookup hash
my %ServiceTypeName2ID = reverse %{$ServiceTypeList};
# get the list of sla types from general catalog
my $SLATypeList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
Class => 'ITSM::SLA::Type',
);
# build a lookup hash
my %SLATypeName2ID = reverse %{$SLATypeList};
%ITSMCoreSLA = (
TypeID => $SLATypeName2ID{Other},
);
%ITSMCoreService = (
TypeID => $ServiceTypeName2ID{Training},
Criticality => '3 normal',
);
}
# create new service
my $ServiceID = $ServiceObject->ServiceAdd(
Name => 'TestService' . $RandomID,
ValidID => 1,
UserID => 1,
%ITSMCoreService,
);
# sanity check
$Self->True(
$ServiceID,
"ServiceAdd() - create testing service",
);
my %ServiceData = $ServiceObject->ServiceGet(
ServiceID => $ServiceID,
UserID => 1,
);
# sanity check
$Self->True(
IsHashRefWithData( \%ServiceData ),
"ServiceGet() - for testing service",
);
# set service for the customer
$ServiceObject->CustomerUserServiceMemberAdd(
CustomerUserLogin => $TestCustomerUserLogin,
ServiceID => $ServiceID,
Active => 1,
UserID => 1,
);
# create SLA object
my $SLAObject = $Kernel::OM->Get('Kernel::System::SLA');
# create new SLA
my $SLAID = $SLAObject->SLAAdd(
Name => 'TestSLA' . $RandomID,
ServiceIDs => [$ServiceID],
ValidID => 1,
UserID => 1,
%ITSMCoreSLA,
);
# sanity check
$Self->True(
$SLAID,
"SLAAdd() - create testing SLA",
);
my %SLAData = $SLAObject->SLAGet(
SLAID => $SLAID,
UserID => 1,
);
# sanity check
$Self->True(
IsHashRefWithData( \%SLAData ),
"SLAGet() - for testing SLA",
);
# create state object
my $StateObject = $Kernel::OM->Get('Kernel::System::State');
# create new state
my $StateID = $StateObject->StateAdd(
Name => 'TestState' . $RandomID,
TypeID => 2,
ValidID => 1,
UserID => 1,
);
# sanity check
$Self->True(
$StateID,
"StateAdd() - create testing state",
);
my %StateData = $StateObject->StateGet(
ID => $StateID,
);
# sanity check
$Self->True(
IsHashRefWithData( \%StateData ),
"StateGet() - for testing state",
);
# create priority object
my $PriorityObject = $Kernel::OM->Get('Kernel::System::Priority');
# create new priority
my $PriorityID = $PriorityObject->PriorityAdd(
Name => 'TestPriority' . $RandomID,
ValidID => 1,
UserID => 1,
);
# sanity check
$Self->True(
$PriorityID,
"PriorityAdd() - create testing priority",
);
my %PriorityData = $PriorityObject->PriorityGet(
PriorityID => $PriorityID,
UserID => 1,
);
# sanity check
$Self->True(
IsHashRefWithData( \%PriorityData ),
"PriorityGet() - for testing priority",
);
# create dynamic field object
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
# create new dynamic field
my $DynamicFieldID = $DynamicFieldObject->DynamicFieldAdd(
Name => 'TestDynamicFieldGI' . $HelperObject->GetRandomNumber(),
Label => 'GI Test Field',
FieldOrder => 9991,
FieldType => 'DateTime',
ObjectType => 'Ticket',
Config => {
DefaultValue => 0,
YearsInFuture => 0,
YearsInPast => 0,
YearsPeriod => 0,
},
ValidID => 1,
UserID => 1,
);
my $DynamicFieldID2 = $DynamicFieldObject->DynamicFieldAdd(
Name => 'TestDynamicFieldGI2' . $HelperObject->GetRandomNumber(),
Label => 'GI Test Field2',
FieldOrder => 9992,
FieldType => 'Text',
ObjectType => 'Article',
Config => {
DefaultValue => '',
},
ValidID => 1,
UserID => 1,
);
# sanity check
$Self->True(
$DynamicFieldID,
"DynamicFieldAdd() - create testing dynamic field",
);
my $DynamicFieldData = $DynamicFieldObject->DynamicFieldGet(
ID => $DynamicFieldID,
);
$Self->True(
$DynamicFieldID2,
"DynamicFieldAdd() - create testing dynamic field",
);
my $DynamicFieldData2 = $DynamicFieldObject->DynamicFieldGet(
ID => $DynamicFieldID2,
);
# sanity check
$Self->True(
IsHashRefWithData($DynamicFieldData),
"DynamicFieldGet() - for testing dynamic field",
);
# create web service object
my $WebserviceObject = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice');
$Self->Is(
ref $WebserviceObject,
'Kernel::System::GenericInterface::Webservice',
"Create web service object",
);
# set web service name
my $WebserviceName = 'Operation::Ticket::TicketCreateIncludeTicketData-Test-' . $RandomID;
my $WebserviceID = $WebserviceObject->WebserviceAdd(
Name => $WebserviceName,
Config => {
Debugger => {
DebugThreshold => 'debug',
},
Provider => {
Transport => {
Type => '',
},
},
},
ValidID => 1,
UserID => 1,
);
$Self->True(
$WebserviceID,
"Added web service",
);
# get remote host with some precautions for certain unit test systems
my $Host = $HelperObject->GetTestHTTPHostname();
# prepare web service config
my $RemoteSystem =
$ConfigObject->Get('HttpType')
. '://'
. $Host
. '/'
. $ConfigObject->Get('ScriptAlias')
. '/nph-genericinterface.pl/WebserviceID/'
. $WebserviceID;
my $WebserviceConfig = {
# Name => '',
Description =>
'Test for Ticket Connector using SOAP transport backend.',
Debugger => {
DebugThreshold => 'debug',
TestMode => 1,
},
Provider => {
Transport => {
Type => 'HTTP::SOAP',
Config => {
MaxLength => 10000000,
NameSpace => 'http://otrs.org/SoapTestInterface/',
Endpoint => $RemoteSystem,
},
},
Operation => {
TicketCreate => {
Type => 'Ticket::TicketCreate',
IncludeTicketData => 1,
},
SessionCreate => {
Type => 'Session::SessionCreate',
},
},
},
Requester => {
Transport => {
Type => 'HTTP::SOAP',
Config => {
NameSpace => 'http://otrs.org/SoapTestInterface/',
Encoding => 'UTF-8',
Endpoint => $RemoteSystem,
Timeout => 120,
},
},
Invoker => {
TicketCreate => {
Type => 'Test::TestSimple',
},
SessionCreate => {
Type => 'Test::TestSimple',
},
},
},
};
# update web service with real config
my $WebserviceUpdate = $WebserviceObject->WebserviceUpdate(
ID => $WebserviceID,
Name => $WebserviceName,
Config => $WebserviceConfig,
ValidID => 1,
UserID => 1,
);
$Self->True(
$WebserviceUpdate,
"Updated web service $WebserviceID - $WebserviceName",
);
# Get SessionID
# create requester object
my $RequesterSessionObject = $Kernel::OM->Get('Kernel::GenericInterface::Requester');
$Self->Is(
ref $RequesterSessionObject,
'Kernel::GenericInterface::Requester',
"SessionID - Create requester object",
);
# create a new user for current test
my $UserLogin = $HelperObject->TestUserCreate(
Groups => [ 'admin', 'users' ],
);
my $Password = $UserLogin;
# create a new user without permissions for current test
my $UserLogin2 = $HelperObject->TestUserCreate();
my $Password2 = $UserLogin2;
# create a customer where a ticket will use and will have permissions
my $CustomerUserLogin = $HelperObject->TestCustomerUserCreate();
my $CustomerPassword = $CustomerUserLogin;
# create a customer that will not have permissions
my $CustomerUserLogin2 = $HelperObject->TestCustomerUserCreate();
my $CustomerPassword2 = $CustomerUserLogin2;
# start requester with our web service
my $RequesterSessionResult = $RequesterSessionObject->Run(
WebserviceID => $WebserviceID,
Invoker => 'SessionCreate',
Data => {
UserLogin => $UserLogin,
Password => $Password,
},
);
my $NewSessionID = $RequesterSessionResult->{Data}->{SessionID};
my @Tests = (
{
Name => 'Ticket with IDs',
SuccessRequest => 1,
SuccessCreate => 1,
RequestData => {
Ticket => {
Title => 'Ticket Title',
CustomerUser => $TestCustomerUserLogin,
QueueID => $Queues[0]->{QueueID},
TypeID => $TypeID,
ServiceID => $ServiceID,
SLAID => $SLAID,
StateID => $StateID,
PriorityID => $PriorityID,
OwnerID => $OwnerID,
ResponsibleID => $ResponsibleID,
PendingTime => {
Year => 2012,
Month => 12,
Day => 16,
Hour => 20,
Minute => 48,
},
},
Article => {
Subject => 'Article subject',
Body => 'Article body',
AutoResponseType => 'auto reply',
SenderTypeID => 1,
IsVisibleForCustomer => 1,
CommunicationChannel => 'Email',
From => 'enjoy@otrs.com',
ContentType => 'text/plain; charset=UTF8',
HistoryType => 'NewTicket',
HistoryComment => '% % ',
TimeUnit => 25,
ForceNotificationToUserID => [$UserID],
ExcludeNotificationToUserID => [$UserID],
ExcludeMuteNotificationToUserID => [$UserID],
},
DynamicField => [
{
Name => $DynamicFieldData->{Name},
Value => '2012-01-17 12:40:00',
},
{
Name => $DynamicFieldData2->{Name},
Value => 'DynamicFieldTypeArticle',
},
],
Attachment => [
{
Content => 'VGhpcyBpcyBhIHRlc3QgdGV4dC4=',
ContentType => 'text/plain; charset=UTF8',
Filename => 'Test.txt',
Disposition => 'attachment',
},
],
},
Operation => 'TicketCreate',
},
);
# debugger object
my $DebuggerObject = Kernel::GenericInterface::Debugger->new(
DebuggerConfig => {
DebugThreshold => 'debug',
TestMode => 1,
},
WebserviceID => $WebserviceID,
CommunicationType => 'Provider',
);
$Self->Is(
ref $DebuggerObject,
'Kernel::GenericInterface::Debugger',
'DebuggerObject instantiate correctly',
);
for my $Test (@Tests) {
# create local object
my $LocalObject = "Kernel::GenericInterface::Operation::Ticket::$Test->{Operation}"->new(
DebuggerObject => $DebuggerObject,
WebserviceID => $WebserviceID,
Operation => $Test->{Operation},
);
$Self->Is(
ref $LocalObject,
"Kernel::GenericInterface::Operation::Ticket::$Test->{Operation}",
"$Test->{Name} - Create local object",
);
my %Auth = (
UserLogin => $UserLogin,
Password => $Password,
);
if ( IsHashRefWithData( $Test->{Auth} ) ) {
%Auth = %{ $Test->{Auth} };
}
# start requester with our web service
my $LocalResult = $LocalObject->Run(
WebserviceID => $WebserviceID,
Invoker => $Test->{Operation},
Data => {
%Auth,
%{ $Test->{RequestData} },
},
);
# check result
$Self->Is(
ref $LocalResult,
'HASH',
"$Test->{Name} - Local result structure is valid",
);
# create requester object
my $RequesterObject = $Kernel::OM->Get('Kernel::GenericInterface::Requester');
$Self->Is(
ref $RequesterObject,
'Kernel::GenericInterface::Requester',
"$Test->{Name} - Create requester object",
);
# start requester with our web service
my $RequesterResult = $RequesterObject->Run(
WebserviceID => $WebserviceID,
Invoker => $Test->{Operation},
Data => {
%Auth,
%{ $Test->{RequestData} },
},
);
# check result
$Self->Is(
ref $RequesterResult,
'HASH',
"$Test->{Name} - Requester result structure is valid",
);
$Self->Is(
$RequesterResult->{Success},
$Test->{SuccessRequest},
"$Test->{Name} - Requester successful result",
);
# tests supposed to succeed
if ( $Test->{SuccessCreate} ) {
my $Article = $LocalResult->{Data}->{Ticket}->{Article} // {};
# Use first article if multiple articles were returned
if ( IsArrayRefWithData($Article) ) {
$Article = $Article->[0] // {};
}
# local results
$Self->True(
$LocalResult->{Data}->{TicketID},
"$Test->{Name} - Local result TicketID with True.",
);
$Self->True(
$LocalResult->{Data}->{TicketNumber},
"$Test->{Name} - Local result TicketNumber with True.",
);
$Self->True(
$LocalResult->{Data}->{ArticleID},
"$Test->{Name} - Local result ArticleID with True.",
);
$Self->Is(
$LocalResult->{Data}->{Error},
undef,
"$Test->{Name} - Local result Error is undefined.",
);
# requester results
$Self->True(
$RequesterResult->{Data}->{TicketID},
"$Test->{Name} - Requester result TicketID with True.",
);
$Self->True(
$RequesterResult->{Data}->{TicketNumber},
"$Test->{Name} - Requester result TicketNumber with True.",
);
$Self->True(
$RequesterResult->{Data}->{ArticleID},
"$Test->{Name} - Requester result ArticleID with True.",
);
$Self->Is(
$RequesterResult->{Data}->{Error},
undef,
"$Test->{Name} - Requester result Error is undefined.",
);
# create ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# check several ticket and article data
$Self->Is(
$LocalResult->{Data}->{Ticket}->{Title},
$Test->{RequestData}->{Ticket}->{Title},
"$Test->{Name} - Ticket title Ok.",
);
$Self->Is(
$LocalResult->{Data}->{Ticket}->{QueueID},
$Test->{RequestData}->{Ticket}->{QueueID},
"$Test->{Name} - Ticket QueueID Ok.",
);
$Self->Is(
$Article->{Body},
$Test->{RequestData}->{Article}->{Body},
"$Test->{Name} - Article body Ok.",
);
$Self->Is(
$Article->{From},
$Test->{RequestData}->{Article}->{From},
"$Test->{Name} - Article from Ok.",
);
# check dynamic fields
my %CompareDynamicFieldTest;
for my $Field ( @{ $Test->{RequestData}->{DynamicField} } ) {
if ( $Field->{Name} eq $DynamicFieldData->{Name} ) {
$CompareDynamicFieldTest{Ticket} = $Field;
}
elsif ( $Field->{Name} eq $DynamicFieldData2->{Name} ) {
$CompareDynamicFieldTest{Article} = $Field;
}
}
my %CompareDynamicFieldLocal;
LOCALRESULTTICKET:
for my $Field ( @{ $LocalResult->{Data}->{Ticket}->{DynamicField} } ) {
next LOCALRESULTTICKET if $Field->{Name} ne $DynamicFieldData->{Name};
$CompareDynamicFieldLocal{Ticket} = $Field;
}
LOCALRESULTARTICLE:
for my $Field ( @{ $Article->{DynamicField} } ) {
next LOCALRESULTARTICLE if $Field->{Name} ne $DynamicFieldData2->{Name};
$CompareDynamicFieldLocal{Article} = $Field;
}
$Self->IsDeeply(
\%CompareDynamicFieldLocal,
\%CompareDynamicFieldTest,
"$Test->{Name} - local Ticket->DynamicField match test definition.",
);
$Self->Is(
$Article->{Attachment}->[0]->{Filename},
$Test->{RequestData}->{Attachment}->[0]->{Filename},
"$Test->{Name} - Attachment filename Ok.",
);
$Self->Is(
$RequesterResult->{Data}->{Ticket}->{Title},
$Test->{RequestData}->{Ticket}->{Title},
"$Test->{Name} - Ticket title Ok.",
);
$Self->Is(
$RequesterResult->{Data}->{Ticket}->{QueueID},
$Test->{RequestData}->{Ticket}->{QueueID},
"$Test->{Name} - Ticket QueueID Ok.",
);
$Self->Is(
$RequesterResult->{Data}->{Ticket}->{Article}->{Body},
$Test->{RequestData}->{Article}->{Body},
"$Test->{Name} - Article body Ok.",
);
$Self->Is(
$RequesterResult->{Data}->{Ticket}->{Article}->{From},
$Test->{RequestData}->{Article}->{From},
"$Test->{Name} - Article from Ok.",
);
# check dynamic fields
my %CompareDynamicFieldReq;
if ( IsHashRefWithData( $RequesterResult->{Data}->{Ticket}->{DynamicField} ) ) {
$RequesterResult->{Data}->{Ticket}->{DynamicField} = [ $RequesterResult->{Data}->{Ticket}->{DynamicField} ];
}
LOCALRESULTTICKET:
for my $Field ( @{ $RequesterResult->{Data}->{Ticket}->{DynamicField} } ) {
next LOCALRESULTTICKET if $Field->{Name} ne $DynamicFieldData->{Name};
$CompareDynamicFieldReq{Ticket} = $Field;
}
# Check for type of key containing article dynamic field data, since it might be a hash on systems without
# multiple fields defined. In this case normalize it to an array of hashes for easier comparison later.
if ( ref $RequesterResult->{Data}->{Ticket}->{Article}->{DynamicField} eq 'HASH' ) {
$RequesterResult->{Data}->{Ticket}->{Article}->{DynamicField}
= [ $RequesterResult->{Data}->{Ticket}->{Article}->{DynamicField} ];
}
LOCALRESULTARTICLE:
for my $Field ( @{ $RequesterResult->{Data}->{Ticket}->{Article}->{DynamicField} } ) {
next LOCALRESULTARTICLE if $Field->{Name} ne $DynamicFieldData2->{Name};
$CompareDynamicFieldReq{Article} = $Field;
}
$Self->IsDeeply(
\%CompareDynamicFieldReq,
\%CompareDynamicFieldTest,
"$Test->{Name} - req Ticket->DynamicField match test definition.",
);
# check attachment
$Self->Is(
$RequesterResult->{Data}->{Ticket}->{Article}->{Attachment}->{Filename},
$Test->{RequestData}->{Attachment}->[0]->{Filename},
"$Test->{Name} - Attachment filename Ok.",
);
# delete the tickets
for my $TicketID (
$LocalResult->{Data}->{TicketID},
$RequesterResult->{Data}->{TicketID}
)
{
# Allow some time for all history entries to be written to the ticket before deleting it,
# otherwise TicketDelete could fail.
sleep 1;
my $TicketDelete = $TicketObject->TicketDelete(
TicketID => $TicketID,
UserID => 1,
);
# sanity check
$Self->True(
$TicketDelete,
"TicketDelete() successful for Ticket ID $TicketID",
);
}
}
}
# delete web service
my $WebserviceDelete = $WebserviceObject->WebserviceDelete(
ID => $WebserviceID,
UserID => 1,
);
$Self->True(
$WebserviceDelete,
"Deleted web service $WebserviceID",
);
# get DB object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
my $Success;
# delete queues
for my $QueueData (@Queues) {
$Success = $DBObject->Do(
SQL => "DELETE FROM queue WHERE id = $QueueData->{QueueID}",
);
$Self->True(
$Success,
"Queue with ID $QueueData->{QueueID} is deleted!",
);
}
# delete group
$Success = $DBObject->Do(
SQL => "DELETE FROM permission_groups WHERE id = $GroupID",
);
$Self->True(
$Success,
"Group with ID $GroupID is deleted!",
);
# delete type
$Success = $DBObject->Do(
SQL => "DELETE FROM ticket_type WHERE id = $TypeID",
);
$Self->True(
$Success,
"Type with ID $TypeID is deleted!",
);
# delete service_customer_user and service
$Success = $DBObject->Do(
SQL => "DELETE FROM service_customer_user WHERE service_id = $ServiceID",
);
$Self->True(
$Success,
"Service user referenced to service ID $ServiceID is deleted!",
);
$Success = $DBObject->Do(
SQL => "DELETE FROM service_sla WHERE service_id = $ServiceID OR sla_id = $SLAID",
);
$Self->True(
$Success,
"Service SLA referenced to service ID $ServiceID is deleted!",
);
$Success = $DBObject->Do(
SQL => "DELETE FROM service WHERE id = $ServiceID",
);
$Self->True(
$Success,
"Service with ID $ServiceID is deleted!",
);
# delete SLA
$Success = $DBObject->Do(
SQL => "DELETE FROM sla WHERE id = $SLAID",
);
$Self->True(
$Success,
"SLA with ID $SLAID is deleted!",
);
# delete state
$Success = $DBObject->Do(
SQL => "DELETE FROM ticket_state WHERE id = $StateID",
);
$Self->True(
$Success,
"State with ID $StateID is deleted!",
);
# delete priority
$Success = $DBObject->Do(
SQL => "DELETE FROM ticket_priority WHERE id = $PriorityID",
);
$Self->True(
$Success,
"Priority with ID $PriorityID is deleted!",
);
# Delete test dynamic fields.
$Success = $DBObject->Do(
SQL => 'DELETE FROM dynamic_field WHERE id = ? OR id = ?',
Bind => [ \$DynamicFieldID, \$DynamicFieldID2 ],
);
$Self->True(
$Success,
"Dynamic fields with ID $DynamicFieldID and $DynamicFieldID2 are deleted!",
);
# cleanup cache
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp();
1;
|