File indexing completed on 2024-04-14 11:07:36

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "kemailclientlauncherjobtest.h"
0009 #include "kemailclientlauncherjob.h"
0010 
0011 #include <QStandardPaths>
0012 #include <QTest>
0013 
0014 QTEST_GUILESS_MAIN(KEMailClientLauncherJobTest)
0015 
0016 void KEMailClientLauncherJobTest::initTestCase()
0017 {
0018     QStandardPaths::setTestModeEnabled(true);
0019 }
0020 
0021 void KEMailClientLauncherJobTest::testEmpty()
0022 {
0023     KEMailClientLauncherJob job;
0024     QCOMPARE(job.mailToUrl().toString(), QString());
0025     const QStringList expected{QStringLiteral("-compose")};
0026     QCOMPARE(job.thunderbirdArguments(), expected);
0027 }
0028 
0029 void KEMailClientLauncherJobTest::testTo()
0030 {
0031     KEMailClientLauncherJob job;
0032     job.setTo({"someone@example.com"});
0033     QCOMPARE(job.mailToUrl().toString(), "mailto:someone@example.com");
0034 
0035     const QStringList expected{QStringLiteral("-compose"), QStringLiteral("to='someone@example.com'")};
0036     QCOMPARE(job.thunderbirdArguments(), expected);
0037 }
0038 
0039 void KEMailClientLauncherJobTest::testManyFields()
0040 {
0041     KEMailClientLauncherJob job;
0042     job.setTo({"someone@example.com", "Someone Else <someoneelse@example.com>"});
0043     job.setCc({"Boss who likes €£¥ <boss@example.com>", "ceo@example.com"});
0044     job.setSubject("See you on Hauptstraße");
0045     job.setBody("Hauptstraße is an excuse to test UTF-8 & URLs.\nBest regards.");
0046     const QString expected =
0047         "mailto:someone@example.com?to=Someone Else %3Csomeoneelse@example.com%3E&cc=Boss who likes €£¥ %3Cboss@example.com%3E&cc=ceo@example.com&subject=See "
0048         "you on Hauptstraße&body=Hauptstraße is an excuse to test UTF-8 %26 URLs.%0ABest regards.";
0049     QCOMPARE(job.mailToUrl().toString(), expected);
0050     const QStringList tbExpected{QStringLiteral("-compose"),
0051                                  "to='someone@example.com,Someone Else <someoneelse@example.com>',cc='Boss who likes €£¥ "
0052                                  "<boss@example.com>,ceo@example.com',subject='See you on Hauptstraße',body='Hauptstraße is an excuse to test UTF-8 & URLs."
0053                                  "\nBest regards.'"};
0054     QCOMPARE(job.thunderbirdArguments(), tbExpected);
0055 }
0056 
0057 void KEMailClientLauncherJobTest::testAttachments()
0058 {
0059     KEMailClientLauncherJob job;
0060     const QUrl thisExe = QUrl::fromLocalFile(QCoreApplication::applicationFilePath());
0061     job.setAttachments({thisExe, thisExe});
0062     const QString path = thisExe.toString(); // let's hope no '&' or '#' in the path :)
0063     const QString expected = "mailto:?attach=" + path + "&attach=" + path;
0064     QCOMPARE(job.mailToUrl().toString(), expected);
0065 }
0066 
0067 #include "moc_kemailclientlauncherjobtest.cpp"