/usr/share/otrs/scripts/test/StdAttachment.t is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use utf8;
use vars (qw($Self));
use Kernel::System::VariableCheck qw(:all);
# get needed objects
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
my $StdAttachmentObject = $Kernel::OM->Get('Kernel::System::StdAttachment');
my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate');
# get helper object
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest::Helper' => {
RestoreDatabase => 1,
},
);
my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
my $Location;
# file checks
for my $File (qw(xls txt doc png pdf)) {
$Location = $Home . "/scripts/test/sample/StdAttachment/StdAttachment-Test1.$File";
my $ContentRef = $MainObject->FileRead(
Location => $Location,
Mode => 'binmode',
);
my $Content = ${$ContentRef};
my $MD5 = $MainObject->MD5sum( String => \$Content );
my $Add = $StdAttachmentObject->StdAttachmentAdd(
Name => 'Some Name 123456798',
ValidID => 1,
Content => $Content,
ContentType => 'text/xml',
Filename => 'StdAttachment Test1äöüß.' . $File,
Comment => 'Some Comment',
UserID => 1,
);
$Self->True(
$Add || '',
"StdAttachmentAdd() - ." . $File,
);
my %Data = $StdAttachmentObject->StdAttachmentGet( ID => $Add );
my $MD5Add = $MainObject->MD5sum( String => \$Data{Content} );
$Self->Is(
$MD5 || '',
$MD5Add || '',
"StdAttachmentGet() - MD5 ." . $File,
);
$Self->Is(
$Data{Name} || '',
'Some Name 123456798',
"StdAttachmentGet() - Name ." . $File,
);
$Self->Is(
$Data{ContentType} || '',
'text/xml',
"StdAttachmentGet() - ContentType ." . $File,
);
$Self->Is(
$Data{Comment} || '',
'Some Comment',
"StdAttachmentGet() - Comment ." . $File,
);
$Self->Is(
$Data{Filename} || '',
'StdAttachment Test1äöüß.' . $File,
"StdAttachmentGet() - Filename ." . $File,
);
my $ID = $StdAttachmentObject->StdAttachmentLookup( StdAttachment => 'Some Name 123456798' );
$Self->Is(
$ID || '',
$Add,
"StdAttachmentLookup() - ID ." . $File,
);
my $Name = $StdAttachmentObject->StdAttachmentLookup( StdAttachmentID => $ID );
$Self->Is(
$Name || '',
$Data{Name} || '',
"StdAttachmentLookup() - Name ." . $File,
);
my $Update = $StdAttachmentObject->StdAttachmentUpdate(
ID => $ID,
Name => 'Some Name',
ValidID => 1,
Content => $Data{Content},
ContentType => 'text/html',
Filename => 'SomeFile.' . $File,
Comment => 'Lala123öäüß',
UserID => 1,
);
$Self->True(
$Update || '',
"StdAttachmentUpdate() - ." . $File,
);
%Data = $StdAttachmentObject->StdAttachmentGet( ID => $ID );
my $MD5Update = $MainObject->MD5sum( String => \$Data{Content} );
$Self->Is(
$MD5 || '',
$MD5Update || '',
"StdAttachmentGet() - MD5 ." . $File,
);
$Self->Is(
$Data{Name} || '',
'Some Name',
"StdAttachmentGet() - Name ." . $File,
);
$Self->Is(
$Data{ContentType} || '',
'text/html',
"StdAttachmentGet() - ContentType ." . $File,
);
$Self->Is(
$Data{Comment} || '',
'Lala123öäüß',
"StdAttachmentGet() - Comment ." . $File,
);
$Self->Is(
$Data{Filename} || '',
'SomeFile.' . $File,
"StdAttachmentGet() - Filename ." . $File,
);
$ID = $StdAttachmentObject->StdAttachmentLookup( StdAttachment => 'Some Name' );
$Self->Is(
$ID || '',
$Add,
"StdAttachmentLookup() - ID ." . $File,
);
$Name = $StdAttachmentObject->StdAttachmentLookup( StdAttachmentID => $ID );
$Self->Is(
$Name || '',
$Data{Name} || '',
"StdAttachmentLookup() - Name ." . $File,
);
my $Delete = $StdAttachmentObject->StdAttachmentDelete( ID => $Add );
$Self->True(
$Delete || '',
"StdAttachmentDelete() - ." . $File,
);
}
# attachment -> templates tests
my $UserID = 1;
my $RandomID = $Helper->GetRandomID();
# create a new attachment
$Location = $Home . "/scripts/test/sample/StdAttachment/StdAttachment-Test1.png";
my $ContentRef = $MainObject->FileRead(
Location => $Location,
Mode => 'binmode',
);
my $Content = ${$ContentRef};
my $AttachmentName = 'Standard Attachment' . $RandomID;
my $Filename = 'StdAttachment-Test1.xml';
my $AttachmentID = $StdAttachmentObject->StdAttachmentAdd(
Name => $AttachmentName,
ValidID => 1,
Content => $Content,
ContentType => 'text/xml',
Filename => $Filename,
Comment => 'Some Comment',
UserID => $UserID,
);
$Self->IsNot(
$AttachmentID,
undef,
"StdAttachmentAdd() - for Attachment -> Template tests | Attachment ID should not be undef",
);
# create a new template
my $TemplateID = $StandardTemplateObject->StandardTemplateAdd(
Name => 'New Standard Template' . $RandomID,
Template => 'Thank you for your email.',
ContentType => 'text/plain; charset=utf-8',
TemplateType => 'Answer',
ValidID => 1,
UserID => $UserID,
);
$Self->IsNot(
$TemplateID,
undef,
"StandardTemplateAdd() for Attachment -> Template tests | TemplatID should not be undef",
);
my @Tests = (
{
Name => 'No Params',
Config => undef,
Success => 0,
},
{
Name => 'Empty Config',
Config => {},
Success => 0,
},
{
Name => 'Missing AttachmentID',
Config => {
AttachmentID => undef,
StandardTemplateID => $TemplateID,
Active => 1,
UserID => $UserID,
},
Success => 0,
},
{
Name => 'Missing StandardTemplateID',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => undef,
Active => 1,
UserID => $UserID,
},
Success => 0,
},
{
Name => 'Missing UserID',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => $TemplateID,
Active => 1,
UserID => undef,
},
Success => 0,
},
{
Name => 'Correct AttachmentID and TemplateID',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => $TemplateID,
Active => 1,
UserID => $UserID,
},
Success => 1,
},
{
Name => 'Correct AttachmentID and TemplateID (removal)',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => $TemplateID,
Active => 0,
UserID => $UserID,
},
Success => 1,
},
);
for my $Test (@Tests) {
my $Success = $StdAttachmentObject->StdAttachmentStandardTemplateMemberAdd( %{ $Test->{Config} } );
if ( $Test->{Success} ) {
$Self->True(
$Success,
"$Test->{Name} StdAttachmentStandardTemplateMemberAdd() with true",
);
# get assigned templates
my %Templates = $StdAttachmentObject->StdAttachmentStandardTemplateMemberList(
AttachmentID => $Test->{Config}->{AttachmentID},
);
if ( $Test->{Config}->{Active} ) {
$Self->IsNot(
$Templates{$TemplateID} || '',
'',
"$Test->{Name} StdAttachmentStandardTemplateMemberList() | $TemplateID should be"
. " assingned and must have a value",
);
}
else {
$Self->Is(
$Templates{$TemplateID} || '',
'',
"$Test->{Name} StdAttachmentStandardTemplateMemberList() | $TemplateID should not"
. " be assingned and must not have a value",
);
}
}
else {
$Self->False(
$Success,
"$Test->{Name} StdAttachmentStandardTemplateMemberAdd() with false",
);
}
}
# add relation to list after wards
my $Success = $StdAttachmentObject->StdAttachmentStandardTemplateMemberAdd(
AttachmentID => $AttachmentID,
StandardTemplateID => $TemplateID,
Active => 1,
UserID => $UserID
);
$Self->True(
$Success,
"StdAttachmentStandardTemplateMemberAdd() for Attachment -> Template tests | with True",
);
@Tests = (
{
Name => 'No Params',
Config => undef,
Success => 0,
},
{
Name => 'Empty Config',
Config => {},
Success => 0,
},
{
Name => 'Missing AttachmentID and TemplateID',
Config => {
AttachmentID => undef,
StandardTemplateID => undef,
UserID => $UserID,
},
Success => 0,
},
{
Name => 'both AttachmentID and TemplateID',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => $TemplateID,
UserID => $UserID,
},
Success => 0,
},
{
Name => 'Correct AttachmentID',
Config => {
AttachmentID => $AttachmentID,
StandardTemplateID => undef,
UserID => $UserID,
},
ExpectedResults => {
$TemplateID => 'New Standard Template' . $RandomID,
},
Success => 1,
},
{
Name => 'Correct TemplateID',
Config => {
AttachmentID => undef,
StandardTemplateID => $TemplateID,
UserID => $UserID,
},
ExpectedResults => {
$AttachmentID => $AttachmentName,
},
Success => 1,
},
);
for my $Test (@Tests) {
my %List = $StdAttachmentObject->StdAttachmentStandardTemplateMemberList( %{ $Test->{Config} } );
my $IsHashRefWithData = IsHashRefWithData( \%List );
if ( $Test->{Success} ) {
$Self->True(
$IsHashRefWithData,
"$Test->{Name} StdAttachmentStandardTemplateMemberList() | Result sould be a hash"
. " wiith data",
);
$Self->IsDeeply(
\%List,
$Test->{ExpectedResults},
"$Test->{Name} StdAttachmentStandardTemplateMemberList() | Expected results",
);
}
else {
$Self->False(
$IsHashRefWithData,
"$Test->{Name} StdAttachmentStandardTemplateMemberList() | Result sould not be hash"
. " wiith data",
);
}
}
my %StdAttachmentList = $StdAttachmentObject->StdAttachmentList(
Valid => 0,
);
$Self->True(
exists $StdAttachmentList{$AttachmentID} && $StdAttachmentList{$AttachmentID} eq "$AttachmentName ( $Filename )",
"StdAttachmentList() contains the StdAttachment $AttachmentName",
);
my $Update = $StdAttachmentObject->StdAttachmentUpdate(
ID => $AttachmentID,
Name => $AttachmentName,
ValidID => 2,
UserID => $UserID,
);
$Self->True(
$Update,
'StdAttachmentUpdate() - StdAttachment is set to invalid',
);
%StdAttachmentList = $StdAttachmentObject->StdAttachmentList(
Valid => 1,
);
$Self->False(
exists $StdAttachmentList{$AttachmentID},
"StdAttachmentList() does not contain the StdAttachment $AttachmentName",
);
# cleanup is done by RestoreDatabase
1;
|