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
|
# --
# 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));
use Kernel::System::PostMaster;
my $Selenium = $Kernel::OM->Get('Kernel::System::UnitTest::Selenium');
$Selenium->RunTest(
sub {
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# run test only if command exists
my $Result = qx{pdftohtml};
return 1 if !$Result;
# Enable MIME-Viewer for PDF attachment.
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'MIME-Viewer###application/pdf',
Value => "echo 'OTRS.org TEST'",
);
# Create test user.
my $TestUserLogin = $HelperObject->TestUserCreate(
Groups => [ 'admin', 'users' ],
) || die "Did not get test user";
# Get test user ID.
my $TestUserID = $Kernel::OM->Get('Kernel::System::User')->UserLookup(
UserLogin => $TestUserLogin,
);
# Create test ticket.
my $TicketID = $TicketObject->TicketCreate(
Title => 'Some Ticket Title',
Queue => 'Raw',
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => '123465',
CustomerUser => 'customer@example.com',
OwnerID => $TestUserID,
UserID => $TestUserID,
);
# Add article to test ticket with PDF test attachment.
my $Location = $Selenium->{Home}
. "/scripts/test/sample/StdAttachment/StdAttachment-Test1.pdf";
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $Location,
Mode => 'binmode',
);
my $Content = ${$ContentRef};
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(
ChannelName => 'Internal',
);
my $ArticleID = $ArticleBackendObject->ArticleCreate(
TicketID => $TicketID,
IsVisibleForCustomer => 0,
SenderType => 'agent',
Subject => 'some short description',
Body => 'the message text',
ContentType => 'text/html; charset=ISO-8859-15',
HistoryType => 'AddNote',
HistoryComment => 'Some free text!',
UserID => $TestUserID,
Attachment => [
{
Content => $Content,
ContentType => 'application/pdf',
Filename => 'StdAttachment-Test1.pdf',
},
],
);
# Login as test user.
$Selenium->Login(
Type => 'Agent',
User => $TestUserLogin,
Password => $TestUserLogin,
);
# Go to ticket zoom page of created test ticket.
my $ScriptAlias = $ConfigObject->Get('ScriptAlias');
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketZoom;TicketID=$TicketID");
# Check are there Download and Viewer links for test attachment.
$Self->True(
$Selenium->find_element("//a[contains(\@class, 'DownloadAttachment')]"),
"Download link for attachment is found"
);
$Self->True(
$Selenium->find_element("//a[contains(\@class, 'ViewAttachment')]"),
"View link for attachment is found"
);
# Check test attachment in MIME-Viwer, WaitFor will be done after switch to window.
$Selenium->execute_script("\$('a.ViewAttachment i').click();");
# Switch to link object window.
$Selenium->WaitFor( WindowCount => 2 );
my $Handles = $Selenium->get_window_handles();
$Selenium->switch_to_window( $Handles->[1] );
# Wait for page to load if necessary.
$Selenium->WaitFor( JavaScript => 'return document.readyState === "complete";' );
# Check expected values in PDF test attachment.
for my $ExpectedValue (qw(OTRS.org TEST)) {
$Self->True(
index( $Selenium->get_page_source(), $ExpectedValue ) > -1,
"Value is found on screen - $ExpectedValue"
);
}
$Selenium->close();
$Selenium->WaitFor( WindowCount => 1 );
$Handles = $Selenium->get_window_handles();
$Selenium->switch_to_window( $Handles->[0] );
# Import sample email.
$Location = $Selenium->{Home} . '/scripts/test/sample/PostMaster/PostMaster-Test20.box';
$ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $Location,
Mode => 'binmode',
Result => 'ARRAY',
);
# Set ticket number in mail subject to get a follow-up.
my $TicketNumber = $TicketObject->TicketNumberLookup(
TicketID => $TicketID,
);
my @Content = ();
for my $Line ( @{$ContentRef} ) {
if ( $Line =~ /^Subject:/ ) {
$Line = 'Subject: '
. $ConfigObject->Get('Ticket::Hook')
. $TicketNumber;
}
push @Content, $Line;
}
my @Return;
# Execute PostMaster with the read email.
{
my $CommunicationLogObject = $Kernel::OM->Create(
'Kernel::System::CommunicationLog',
ObjectParams => {
Transport => 'Email',
Direction => 'Incoming',
},
);
$CommunicationLogObject->ObjectLogStart( ObjectLogType => 'Message' );
my $PostMasterObject = Kernel::System::PostMaster->new(
CommunicationLogObject => $CommunicationLogObject,
Email => \@Content,
);
@Return = $PostMasterObject->Run();
$CommunicationLogObject->ObjectLogStop(
ObjectLogType => 'Message',
Status => 'Successful',
);
$CommunicationLogObject->CommunicationStop(
Status => 'Successful',
);
}
# Check we actually got a follow-up.
$Self->Is(
$Return[0] || 0,
2,
"PostMaster::Run() - FollowUp",
);
# Check we actually got the same ticket ID.
$Self->Is(
$Return[1] || 0,
$TicketID,
"PostMaster::Run() - FollowUp/TicketID",
);
# Refresh the screen.
$Selenium->VerifiedRefresh();
# Find article IFRAME content URL.
$Selenium->get_page_source() =~ m{<iframe [^>]+ src="(?!about:blank)(?<HTMLViewURL>.*?)"}xms;
die 'Could not find IFRAME content URL!' if !$+{HTMLViewURL};
# Get current SessionID and SessionName.
my $SessionID = $Selenium->execute_script('return Core.Config.Get("SessionID");');
my $SessionName = $Kernel::OM->Get('Kernel::Config')->Get('SessionName');
# Append session information to the url, since in the next selenium get request
# we don't have session information in the cookie.
my $URL = $+{HTMLViewURL} . ";$SessionName=$SessionID";
# Load article content only.
$Selenium->get($URL);
# Wait for page to load if necessary.
$Selenium->WaitFor( JavaScript => 'return document.readyState === "complete";' );
# Check if article is displayed in expected encoding.
$Self->True(
index( $Selenium->get_page_source(), 'MunguĂa' ) > -1,
'Article displayed using correct encoding'
);
# Delete created test ticket.
my $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 with ticket id $TicketID is deleted"
);
# Make sure the cache is correct.
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => 'Ticket'
);
}
);
1;
|