/usr/share/otrs/scripts/test/StandardTemplate.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 | # --
# 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));
# get StandardTemplate object
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 $RandomID = $Helper->GetRandomID();
# tests
my @Tests = (
{
Name => 'text',
Add => {
Name => 'text' . $RandomID,
ValidID => 1,
Template => 'Template text',
ContentType => 'text/plain; charset=iso-8859-1',
TemplateType => 'Answer',
Comment => 'some comment',
UserID => 1,
},
AddSecond => {
Name => 'text_second_' . $RandomID,
ValidID => 1,
Template => 'Template text',
ContentType => 'text/plain; charset=iso-8859-1',
TemplateType => 'Answer',
Comment => 'some comment',
UserID => 1,
},
AddGet => {
Name => 'text' . $RandomID,
ValidID => 1,
Template => 'Template text',
ContentType => 'text/plain; charset=iso-8859-1',
TemplateType => 'Answer',
Comment => 'some comment',
},
Update => {
Name => 'text2' . $RandomID,
ValidID => 1,
Template => 'Template text\'2',
ContentType => 'text/plain; charset=utf-8',
TemplateType => 'Forward',
Comment => 'some comment2',
UserID => 1,
},
UpdateGet => {
Name => 'text2' . $RandomID,
ValidID => 1,
Template => 'Template text\'2',
ContentType => 'text/plain; charset=utf-8',
TemplateType => 'Forward',
Comment => 'some comment2',
},
},
);
my @IDs;
for my $Test (@Tests) {
# add
my $ID = $StandardTemplateObject->StandardTemplateAdd(
%{ $Test->{Add} },
);
$Self->True(
$ID,
"StandardTemplateAdd() - $ID",
);
push( @IDs, $ID );
# add with existing name
my $IDWrong = $StandardTemplateObject->StandardTemplateAdd(
%{ $Test->{Add} },
);
$Self->False(
$IDWrong,
"StandardTemplateAdd() - Try to add the standard template with existing name",
);
my %Data = $StandardTemplateObject->StandardTemplateGet(
ID => $ID,
);
for my $Key ( sort keys %{ $Test->{AddGet} } ) {
$Self->Is(
$Test->{AddGet}->{$Key},
$Data{$Key},
"StandardTemplateGet() - $Key",
);
}
# lookup by ID
my $Name = $StandardTemplateObject->StandardTemplateLookup(
StandardTemplateID => $ID
);
$Self->Is(
$Name,
$Test->{Add}->{Name},
"StandardTemplateLookup()",
);
# lookup by Name
my $LookupID = $StandardTemplateObject->StandardTemplateLookup(
StandardTemplate => $Test->{Add}->{Name},
);
$Self->Is(
$ID,
$LookupID,
"StandardTemplateLookup()",
);
# update
my $Update = $StandardTemplateObject->StandardTemplateUpdate(
ID => $ID,
%{ $Test->{Update} },
);
$Self->True(
$ID,
"StandardTemplateUpdate()",
);
%Data = $StandardTemplateObject->StandardTemplateGet(
ID => $ID,
);
for my $Key ( sort keys %{ $Test->{UpdateGet} } ) {
$Self->Is(
$Test->{UpdateGet}->{$Key},
$Data{$Key},
"StandardTemplateGet() - $Key",
);
}
# add another standard template
my $IDSecond = $StandardTemplateObject->StandardTemplateAdd(
%{ $Test->{AddSecond} },
);
push( @IDs, $IDSecond );
$Self->True(
$IDSecond,
"StandardTemplateAdd() - $IDSecond",
);
# update with existing name
my $UpdateWrong = $StandardTemplateObject->StandardTemplateUpdate(
ID => $IDSecond,
%{ $Test->{Update} },
);
$Self->False(
$UpdateWrong,
"StandardTemplateUpdate() - Try to update the standard template with existing name",
);
# check function NameExistsCheck()
# check does it exist a standard template with certain Name or
# check is it possible to set Name for standard template with certain ID
my $Exist = $StandardTemplateObject->NameExistsCheck(
Name => $Test->{AddSecond}->{Name},
);
$Self->True(
$Exist,
"NameExistsCheck() - A standard template with \'$Test->{AddSecond}->{Name}\' already exists!",
);
# there is a standard template with certain name, now check if there is another one
$Exist = $StandardTemplateObject->NameExistsCheck(
Name => "$Test->{AddSecond}->{Name}",
ID => $IDSecond,
);
$Self->False(
$Exist,
"NameExistsCheck() - Another standard template \'$Test->{AddSecond}->{Name}\' for ID=$IDSecond does not exist!",
);
$Exist = $StandardTemplateObject->NameExistsCheck(
Name => $Test->{AddSecond}->{Name},
ID => $ID,
);
$Self->True(
$Exist,
"NameExistsCheck() - Another standard template \'$Test->{AddSecond}->{Name}\' for ID=$ID already exists!",
);
# check is there a standard template whose name has been updated in the meantime
$Exist = $StandardTemplateObject->NameExistsCheck(
Name => "$Test->{Add}->{Name}",
);
$Self->False(
$Exist,
"NameExistsCheck() - A standard template with \'$Test->{Add}->{Name}\' does not exist!",
);
$Exist = $StandardTemplateObject->NameExistsCheck(
Name => "$Test->{Add}->{Name}",
ID => $ID,
);
$Self->False(
$Exist,
"NameExistsCheck() - Another standard template \'$Test->{Add}->{Name}\' for ID=$ID does not exist!",
);
# test StandardTemplateList()
my %StandardTemplates = $StandardTemplateObject->StandardTemplateList();
my %AnswerStandardTemplates = $StandardTemplateObject->StandardTemplateList( Type => 'Answer' );
my %ForwardStandardTemplates = $StandardTemplateObject->StandardTemplateList( Type => 'Forward' );
$Self->IsNotDeeply(
\%StandardTemplates,
\%AnswerStandardTemplates,
'StandardTemplateList() - Full vs just Answer type should be different',
);
$Self->IsNotDeeply(
\%StandardTemplates,
\%ForwardStandardTemplates,
'StandardTemplateList() - Full vs just Forward type should be different',
);
$Self->IsNotDeeply(
\%AnswerStandardTemplates,
\%ForwardStandardTemplates,
'StandardTemplateList() - Answer vs Forward type should be different',
);
# test with not only valid templates
my %AllStandardTemplates = $StandardTemplateObject->StandardTemplateList( Valid => 0 );
$Self->IsNotDeeply(
\%AllStandardTemplates,
{},
'StandardTemplateList() - All templates is not an empty hash',
);
my %AllAnswerStandardTemplatess = $StandardTemplateObject->StandardTemplateList(
Valid => 0,
Type => 'Answer',
);
$Self->IsNotDeeply(
\%AllAnswerStandardTemplatess,
{},
'StandardTemplateList() - All Answer is not an empty hash',
);
# delete created standard template
for my $ID (@IDs) {
my $Delete = $StandardTemplateObject->StandardTemplateDelete(
ID => $ID,
);
$Self->True(
$Delete,
"StandardTemplateDelete() - $ID ",
);
}
}
# cleanup is done by RestoreDatabase
1;
|