Commit 17f81052 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add new autotest

parent c2feb517
......@@ -170,7 +170,6 @@
#include <KIconUtils>
#include <KMessageBox>
#include <KRecentFilesAction>
#include <KRun>
#include <KShortcutsDialog>
#include <KSplitterCollapserButton>
#include <KStandardShortcut>
......
......@@ -7,4 +7,5 @@ macro(add_kmail_job_unittest _source)
endmacro ()
add_kmail_job_unittest(createreplymessagejobtest.cpp)
add_kmail_job_unittest(createforwardmessagejobtest.cpp)
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "createforwardmessagejobtest.h"
#include "job/createforwardmessagejob.h"
#include <QTest>
QTEST_MAIN(CreateForwardMessageJobTest)
CreateForwardMessageJobTest::CreateForwardMessageJobTest(QObject *parent)
: QObject(parent)
{
}
void CreateForwardMessageJobTest::shouldHaveDefaultValues()
{
CreateForwardMessageJobSettings settings;
QVERIFY(settings.url.isEmpty());
QVERIFY(settings.selection.isEmpty());
QVERIFY(settings.templateStr.isEmpty());
QVERIFY(!settings.msg);
QCOMPARE(settings.identity, 0);
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CREATEFORWARDMESSAGEJOBTEST_H
#define CREATEFORWARDMESSAGEJOBTEST_H
#include <QObject>
class CreateForwardMessageJobTest : public QObject
{
Q_OBJECT
public:
explicit CreateForwardMessageJobTest(QObject *parent = nullptr);
~CreateForwardMessageJobTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
#endif // CREATEFORWARDMESSAGEJOBTEST_H
......@@ -43,38 +43,38 @@ void CreateForwardMessageJob::setSettings(const CreateForwardMessageJobSettings
void CreateForwardMessageJob::start()
{
const auto col = CommonKernel->collectionFromId(mSettings.mItem.parentCollection().id());
mMessageFactory = new MessageComposer::MessageFactoryNG(mSettings.mMsg, mSettings.mItem.id(),
const auto col = CommonKernel->collectionFromId(mSettings.item.parentCollection().id());
mMessageFactory = new MessageComposer::MessageFactoryNG(mSettings.msg, mSettings.item.id(),
col);
connect(mMessageFactory, &MessageComposer::MessageFactoryNG::createForwardDone, this, &CreateForwardMessageJob::slotCreateForwardDone);
mMessageFactory->setIdentityManager(KMKernel::self()->identityManager());
mMessageFactory->setFolderIdentity(MailCommon::Util::folderIdentity(mSettings.mItem));
mMessageFactory->setSelection(mSettings.mSelection);
mMessageFactory->setTemplate(mSettings.mTemplate);
mMessageFactory->setFolderIdentity(MailCommon::Util::folderIdentity(mSettings.item));
mMessageFactory->setSelection(mSettings.selection);
mMessageFactory->setTemplate(mSettings.templateStr);
mMessageFactory->createForwardAsync();
}
void CreateForwardMessageJob::slotCreateForwardDone(const KMime::Message::Ptr &fmsg)
{
if (mSettings.mUrl.isValid()) {
fmsg->to()->fromUnicodeString(KEmailAddress::decodeMailtoUrl(mSettings.mUrl).toLower(), "utf-8");
if (mSettings.url.isValid()) {
fmsg->to()->fromUnicodeString(KEmailAddress::decodeMailtoUrl(mSettings.url).toLower(), "utf-8");
}
bool lastEncrypt = false;
bool lastSign = false;
KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, mSettings.mMsg);
KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, mSettings.msg);
if (mSettings.mUrl.isValid()) {
if (mSettings.url.isValid()) {
KMail::Composer *win = KMail::makeComposer(fmsg, lastSign, lastEncrypt, KMail::Composer::Forward);
win->show();
} else {
uint id = 0;
if (auto hrd = mSettings.mMsg->headerByType("X-KMail-Identity")) {
if (auto hrd = mSettings.msg->headerByType("X-KMail-Identity")) {
id = hrd->asUnicodeString().trimmed().toUInt();
}
if (id == 0) {
id = mSettings.mIdentity;
id = mSettings.identity;
}
KMail::Composer *win = KMail::makeComposer(fmsg, lastSign, lastEncrypt, KMail::Composer::Forward, id, QString(), mSettings.mTemplate);
KMail::Composer *win = KMail::makeComposer(fmsg, lastSign, lastEncrypt, KMail::Composer::Forward, id, QString(), mSettings.templateStr);
win->show();
}
deleteLater();
......
......@@ -29,12 +29,12 @@
struct KMAILTESTS_TESTS_EXPORT CreateForwardMessageJobSettings
{
QUrl mUrl;
Akonadi::Item mItem;
KMime::Message::Ptr mMsg;
QString mTemplate;
QString mSelection;
uint mIdentity = 0;
QUrl url;
Akonadi::Item item;
KMime::Message::Ptr msg = nullptr;
QString templateStr;
QString selection;
uint identity = 0;
};
class KMAILTESTS_TESTS_EXPORT CreateForwardMessageJob : public QObject
......
......@@ -56,8 +56,8 @@ public:
private:
Q_DISABLE_COPY(CreateReplyMessageJob)
MessageComposer::MessageFactoryNG *mMessageFactory = nullptr;
void slotCreateReplyDone(const MessageComposer::MessageFactoryNG::MessageReply &reply);
MessageComposer::MessageFactoryNG *mMessageFactory = nullptr;
CreateReplyMessageJobSettings mSettings;
};
......
......@@ -487,9 +487,9 @@ KMCommand::Result KMMailtoForwardCommand::execute()
return Failed;
}
CreateForwardMessageJobSettings settings;
settings.mItem = item;
settings.mMsg = msg;
settings.mUrl = mUrl;
settings.item = item;
settings.msg = msg;
settings.url = mUrl;
CreateForwardMessageJob *job = new CreateForwardMessageJob;
job->setSettings(settings);
......@@ -919,11 +919,11 @@ KMCommand::Result KMForwardCommand::createComposer(const Akonadi::Item &item)
#endif
CreateForwardMessageJobSettings settings;
settings.mItem = item;
settings.mMsg = msg;
settings.mIdentity = mIdentity;
settings.mTemplate = mTemplate;
settings.mSelection = mSelection;
settings.item = item;
settings.msg = msg;
settings.identity = mIdentity;
settings.templateStr = mTemplate;
settings.selection = mSelection;
CreateForwardMessageJob *job = new CreateForwardMessageJob;
job->setSettings(settings);
......
......@@ -20,7 +20,6 @@
#include "kmlaunchexternalcomponent.h"
#include <KMessageBox>
#include <KLocalizedString>
#include <KRun>
#include <AkonadiCore/AgentManager>
#include "util.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment