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
|
# --
# 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));
# Get config object.
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# Get helper object.
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest::Helper' => {
RestoreDatabase => 1,
UseTmpArticleDir => 1,
},
);
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
# UIse DoNotSendEmail email backend.
my $Success = $ConfigObject->Set(
Key => 'SendmailModule',
Value => 'Kernel::System::Email::DoNotSendEmail',
);
$Self->True(
$Success,
"Set Send Mail Module to DoNotSendEmail",
);
# Set default language to English.
$Success = $ConfigObject->Set(
Key => 'DefaultLanguage',
Value => 'en',
);
$Self->True(
$Success,
"Set default language to English",
);
# Disable email checks to create new user.
$Success = $ConfigObject->Set(
Key => 'CheckMXRecord',
Value => 0,
);
$Self->True(
$Success,
"Disabled CheckMXRecord",
);
$Success = $ConfigObject->Set(
Key => 'CheckEmailAddresses',
Value => 0,
);
$Self->True(
$Success,
"Disabled CheckEmailAddress",
);
# Enable lock after create event.
$Success = $ConfigObject->Set(
Key => 'Ticket::EventModulePost###3100-LockAfterCreate',
Value => {
Action => 'AgentTicketPhone|AgentTicketEmail',
Event => 'TicketCreate',
Module => 'Kernel::System::Ticket::Event::LockAfterCreate',
Transaction => 0,
},
);
$Self->True(
$Success,
"Enabled event LockAfterCreate",
);
# Create a new user for current test.
my $UserLogin = $HelperObject->TestUserCreate(
Groups => ['admin'],
);
my %UserData = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
User => $UserLogin,
);
my $UserID = $UserData{UserID};
# Create a new customer user for current test.
my $CustomerUserLogin = $HelperObject->TestCustomerUserCreate();
my %TicketCreateTemplate = (
Title => 'Ticket Title',
QueueID => 1,
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => 'example.com',
CustomerUser => $CustomerUserLogin,
OwnerID => $UserID,
UserID => $UserID,
);
my @Tests = (
{
Name => 'UserID 1',
Request => 'Action=AgentTicketPhone',
TicketCreate => {
UserID => 1,
},
Success => 0,
},
{
Name => 'Closed Ticket',
Request => 'Action=AgentTicketPhone',
TicketCreate => {
State => 'closed successful',
},
Success => 0,
},
{
Name => 'Wrong Action',
Request => 'Action=AgentTicketActionCommon',
TicketCreate => {},
Success => 0,
},
{
Name => 'Missing Action',
Request => 'SubAction=StoreNew',
TicketCreate => {},
Success => 0,
},
{
Name => 'Success Phone',
Request => 'Action=AgentTicketPhone',
TicketCreate => {},
Success => 1,
},
{
Name => 'Success Email',
Request => 'Action=AgentTicketEmail',
TicketCreate => {},
Success => 1,
},
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
for my $Test (@Tests) {
# Fake a web request, as Action is used by the LockAfterCreate event.
local %ENV = (
REQUEST_METHOD => 'GET',
QUERY_STRING => $Test->{Request} || '',
);
CGI->initialize_globals();
my $Request = Kernel::System::Web::Request->new();
# Create an unlocked ticket,
my $TicketID = $TicketObject->TicketCreate(
%TicketCreateTemplate,
%{ $Test->{TicketCreate} }
);
$Self->True(
$TicketID,
"$Test->{Name} TicketCreate() successful for Ticket ID $TicketID",
);
# Check ticket lock.
my $TicketLock = $TicketObject->TicketLockGet( TicketID => $TicketID );
$Self->Is(
$TicketLock // 0,
$Test->{Success},
"$Test->{Name} TicketLockGet() for Ticket ID $TicketID",
);
# Discard web request object as it is used by OM in LockAfterCreate event.
$Kernel::OM->ObjectsDiscard(
Objects => ['Kernel::System::Web::Request'],
);
}
# Cleanup is done by RestoreDatabase.
1;
|