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
|
# --
# 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.
# --
use strict;
use warnings;
use utf8;
use vars (qw($Self));
# get selenium object
my $Selenium = $Kernel::OM->Get('Kernel::System::UnitTest::Selenium');
$Selenium->RunTest(
sub {
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
# create test customer user
my $TestCustomerUserLogin = $HelperObject->TestCustomerUserCreate() || die "Did not get test customer user";
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
my $CustomerCompanyObject = $Kernel::OM->Get('Kernel::System::CustomerCompany');
my $CustomerGroupObject = $Kernel::OM->Get('Kernel::System::CustomerGroup');
my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
$HelperObject->ConfigSettingChange(
Key => 'CheckEmailAddresses',
Value => 0,
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CustomerGroupAlwaysGroups',
Value => [],
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CustomerGroupCompanyAlwaysGroups',
Value => [],
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CustomerGroupSupport',
Value => 1,
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Frontend::RichText',
Value => 0,
);
my $PermissionContextDirect = 'UnitTestPermission-direct';
my $PermissionContextOtherCustomerID = 'UnitTestPermission-other-CustomerID';
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'CustomerGroupPermissionContext',
Value => {
'001-CustomerID-same' => { Value => $PermissionContextDirect },
'100-CustomerID-other' => { Value => $PermissionContextOtherCustomerID },
},
);
$Kernel::OM->Get('Kernel::Config')->Set(
Key => 'CustomerGroupPermissionContext',
Value => {
'001-CustomerID-same' => { Value => $PermissionContextDirect },
'100-CustomerID-other' => { Value => $PermissionContextOtherCustomerID },
},
);
# create two test customer companies
my ( @CustomerIDs, @GroupIDs, @QueueIDs );
for my $Count ( 1 .. 2 ) {
my $CustomerCompanyID = $CustomerCompanyObject->CustomerCompanyAdd(
CustomerID => "$TestCustomerUserLogin-$Count",
CustomerCompanyName => "$TestCustomerUserLogin-$Count",
ValidID => 1,
UserID => 1,
);
$Self->True(
$CustomerCompanyID,
"Created test customer company $CustomerCompanyID",
);
push @CustomerIDs, $CustomerCompanyID;
# create test group
my $GroupID = $GroupObject->GroupAdd(
Name => $CustomerCompanyID,
ValidID => 1,
UserID => 1,
);
$Self->True(
$GroupID,
"Created test group $CustomerCompanyID ($GroupID)",
);
push @GroupIDs, $GroupID;
# add customer relations
my $Success = $CustomerGroupObject->GroupCustomerAdd(
GID => $GroupID,
CustomerID => $CustomerCompanyID,
Permission => {
$PermissionContextDirect => {
ro => 1,
},
},
UserID => 1,
);
$Self->True(
$Success,
"Added customer company to group $CustomerCompanyID",
);
# create test queue
my $QueueID = $QueueObject->QueueAdd(
Name => $CustomerCompanyID,
ValidID => 1,
GroupID => $GroupID,
SystemAddressID => 1,
SalutationID => 1,
SignatureID => 1,
UserID => 1,
);
$Self->True(
$QueueID,
"Created test queue $CustomerCompanyID ($QueueID)",
);
push @QueueIDs, $QueueID;
}
# add customer user to first company
my %CustomerUser = $CustomerUserObject->CustomerUserDataGet(
User => $TestCustomerUserLogin,
);
my $CustomerUserUpdate = $CustomerUserObject->CustomerUserUpdate(
ID => $TestCustomerUserLogin,
UserLogin => $CustomerUser{UserLogin},
UserFirstname => $CustomerUser{UserFirstname},
UserLastname => $CustomerUser{UserLastname},
UserEmail => $CustomerUser{UserEmail},
UserCustomerID => $CustomerIDs[0],
ValidID => 1,
UserID => 1,
);
$Self->True(
$CustomerUserUpdate,
"Added customer user to customer company $CustomerIDs[0]",
);
# create test ticket and set it to second customer id
my $TicketNumber = $TicketObject->TicketCreateNumber();
my $TicketID = $TicketObject->TicketCreate(
TN => $TicketNumber,
Title => 'Some Ticket Title',
Queue => $CustomerIDs[1],
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => $CustomerIDs[1],
CustomerUser => '', # empty
OwnerID => 1,
UserID => 1,
);
$Self->True(
$TicketID,
"Ticket is created - $TicketID",
);
# login test customer user
$Selenium->Login(
Type => 'Customer',
User => $TestCustomerUserLogin,
Password => $TestCustomerUserLogin,
);
my $ScriptAlias = $Kernel::OM->Get('Kernel::Config')->Get('ScriptAlias');
$Selenium->VerifiedGet("${ScriptAlias}customer.pl?Action=CustomerTicketZoom;TicketNumber=$TicketNumber");
$Self->True(
index( $Selenium->get_page_source(), 'No Permission' ) > -1,
'Customer does not have permission for test ticket',
);
# add first customer company to second group with RW permissions
my $Success = $CustomerGroupObject->GroupCustomerAdd(
GID => $GroupIDs[1],
CustomerID => $CustomerIDs[0],
Permission => {
$PermissionContextDirect => {
rw => 1,
},
$PermissionContextOtherCustomerID => {
rw => 1,
},
},
UserID => 1,
);
$Self->True(
$Success,
"Added customer company $CustomerIDs[0] to group $GroupIDs[1]",
);
# refresh the page
$Selenium->VerifiedRefresh();
# check ticket data
$Self->True(
index( $Selenium->get_page_source(), $TicketNumber ) > -1,
"Ticket number is $TicketNumber",
);
$Self->True(
index( $Selenium->get_page_source(), 'Some Ticket Title' ) > -1,
"Ticket title is 'Some Ticket Title'",
);
$Self->True(
index( $Selenium->get_page_source(), $CustomerIDs[1] ) > -1,
"Queue is $CustomerIDs[1]",
);
# check buttons
$Selenium->find_element("//a[contains(\@id, \'ReplyButton' )]");
$Selenium->find_element("//button[contains(\@value, \'Submit' )]");
# clean up test data from the DB
$Success = $TicketObject->TicketDelete(
TicketID => $TicketID,
UserID => 1,
);
# Ticket deletion could fail if apache still writes to ticket history. Try again in this case.
if ( !$Success ) {
sleep 3;
$Success = $TicketObject->TicketDelete(
TicketID => $TicketID,
UserID => 1,
);
}
$Self->True(
$Success,
"Ticket is deleted - $TicketID",
);
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
for my $CustomerID (@CustomerIDs) {
my $Success = $DBObject->Do(
SQL => "DELETE FROM customer_company WHERE customer_id = ?",
Bind => [ \$CustomerID ],
);
$Self->True(
$Success,
"Deleted Customer - $CustomerID",
);
}
for my $QueueID (@QueueIDs) {
my $Success = $DBObject->Do(
SQL => "DELETE FROM queue WHERE id = $QueueID",
);
if ($Success) {
$Self->True(
$Success,
"Deleted Queue - $QueueID",
);
}
}
for my $GroupID (@GroupIDs) {
my $Success = $DBObject->Do(
SQL => "DELETE FROM group_customer WHERE group_id = $GroupID",
);
if ($Success) {
$Self->True(
$Success,
"Deleted Customer Group - $GroupID",
);
}
$Success = $DBObject->Do(
SQL => "DELETE FROM permission_groups WHERE id = $GroupID",
);
$Self->True(
$Success,
"Deleted Group - $GroupID",
);
}
# make sure the cache is correct
for my $Cache (
qw(Group CustomerGroup CustomerCompany Queue Ticket)
)
{
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp( Type => $Cache );
}
},
);
1;
|