• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • filter
  • autotests
filteractionaddheadertest.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "filteractionaddheadertest.h"
19 #include "../filteractions/filteractionaddheader.h"
20 #include <KLineEdit>
21 #include <QLabel>
22 #include <itemcontext.h>
23 #include <qtest_kde.h>
24 #include <widgets/minimumcombobox.h>
25 
26 FilterActionAddHeaderTest::FilterActionAddHeaderTest(QObject *parent)
27  : QObject(parent)
28 {
29 
30 }
31 
32 FilterActionAddHeaderTest::~FilterActionAddHeaderTest()
33 {
34 
35 }
36 
37 void FilterActionAddHeaderTest::shouldCreateWidget()
38 {
39  MailCommon::FilterActionAddHeader filter;
40  QWidget* widget = filter.createParamWidget(0);
41  QVERIFY(widget);
42  PimCommon::MinimumComboBox *comboBox = widget->findChild<PimCommon::MinimumComboBox *>(QLatin1String("combo"));
43  QVERIFY(comboBox);
44  QVERIFY(comboBox->isEditable());
45  QLabel *label = widget->findChild<QLabel *>(QLatin1String("label_value"));
46  QVERIFY(label);
47  KLineEdit *lineEdit = widget->findChild<KLineEdit *>(QLatin1String("ledit"));
48  QVERIFY(lineEdit);
49  QVERIFY(lineEdit->text().isEmpty());
50 }
51 
52 void FilterActionAddHeaderTest::shouldAddValue_data()
53 {
54  QTest::addColumn<QString>("argsinput");
55  QTest::addColumn<QString>("resultheader");
56  QTest::addColumn<QString>("resultvalue");
57  QTest::newRow("empty") << QString() << QString() << QString();
58  QString val = QLatin1String("bla") + QLatin1Char('\t') + QLatin1String("blo");
59  QTest::newRow("real value") << val << QString(QLatin1String("bla")) << QString(QLatin1String("blo"));
60 }
61 
62 void FilterActionAddHeaderTest::shouldClearWidget()
63 {
64  MailCommon::FilterActionAddHeader filter;
65  QWidget* widget = filter.createParamWidget(0);
66  PimCommon::MinimumComboBox *comboBox = widget->findChild<PimCommon::MinimumComboBox *>(QLatin1String("combo"));
67  KLineEdit *lineEdit = widget->findChild<KLineEdit *>(QLatin1String("ledit"));
68  comboBox->lineEdit()->setText(QLatin1String("test"));
69  lineEdit->setText(QLatin1String("blo"));
70  filter.clearParamWidget(widget);
71  QVERIFY(comboBox->lineEdit()->text().isEmpty());
72  QVERIFY(lineEdit->text().isEmpty());
73 }
74 
75 void FilterActionAddHeaderTest::shouldReturnSieveCode()
76 {
77  MailCommon::FilterActionAddHeader filter;
78  QCOMPARE(filter.sieveRequires().join(QLatin1String(",")), QLatin1String("editheader"));
79 }
80 
81 void FilterActionAddHeaderTest::shouldBeEmpty()
82 {
83  MailCommon::FilterActionAddHeader filter;
84  QVERIFY(filter.isEmpty());
85 
86  filter.argsFromString(QString());
87  QVERIFY(filter.isEmpty());
88 
89  filter.argsFromString(QLatin1String("foo\tbla"));
90  QVERIFY(!filter.isEmpty());
91 }
92 
93 void FilterActionAddHeaderTest::shouldNotExecuteActionWhenParameterIsEmpty()
94 {
95  MailCommon::FilterActionAddHeader filter(this);
96  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
97  Akonadi::Item item;
98  item.setPayload<KMime::Message::Ptr>(msgPtr);
99  MailCommon::ItemContext context(item, true);
100 
101  filter.argsFromString("");
102  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn);
103  QCOMPARE(context.needsPayloadStore(), false);
104  QCOMPARE(context.deleteItem(), false);
105  QCOMPARE(context.needsFlagStore(), false);
106 }
107 
108 void FilterActionAddHeaderTest::shouldNotExecuteActionWhenValueIsEmpty()
109 {
110  MailCommon::FilterActionAddHeader filter(this);
111  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
112  Akonadi::Item item;
113  item.setPayload<KMime::Message::Ptr>(msgPtr);
114  MailCommon::ItemContext context(item, true);
115 
116  filter.argsFromString("foo");
117  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn);
118  QCOMPARE(context.needsPayloadStore(), false);
119  QCOMPARE(context.deleteItem(), false);
120  QCOMPARE(context.needsFlagStore(), false);
121 }
122 
123 void FilterActionAddHeaderTest::shouldAddNewHeaderWhenNotExistingHeader()
124 {
125  const QByteArray data = "From: foo@kde.org\n"
126  "To: foo@kde.org\n"
127  "Subject: test\n"
128  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
129  "MIME-Version: 1.0\n"
130  "\n"
131  "test";
132  const QByteArray output = "From: foo@kde.org\n"
133  "To: foo@kde.org\n"
134  "Subject: test\n"
135  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
136  "MIME-Version: 1.0\n"
137  "testheader: foo\n"
138  "\n"
139  "test";
140 
141  MailCommon::FilterActionAddHeader filter(this);
142  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
143  msgPtr->setContent(data);
144  msgPtr->parse();
145  Akonadi::Item item;
146  item.setPayload<KMime::Message::Ptr>(msgPtr);
147  MailCommon::ItemContext context(item, true);
148 
149  filter.argsFromString("testheader\tfoo");
150  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
151  QCOMPARE(context.needsPayloadStore(), true);
152  QCOMPARE(msgPtr->encodedContent(), output);
153  QCOMPARE(context.deleteItem(), false);
154  QCOMPARE(context.needsFlagStore(), false);
155 }
156 
157 void FilterActionAddHeaderTest::shouldReplaceHeaderWhenExistingHeader()
158 {
159  const QByteArray data = "From: foo@kde.org\n"
160  "To: foo@kde.org\n"
161  "Subject: test\n"
162  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
163  "MIME-Version: 1.0\n"
164  "testheader: bla\n"
165  "\n"
166  "test";
167  const QByteArray output = "From: foo@kde.org\n"
168  "To: foo@kde.org\n"
169  "Subject: test\n"
170  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
171  "MIME-Version: 1.0\n"
172  "testheader: foo\n"
173  "\n"
174  "test";
175 
176  MailCommon::FilterActionAddHeader filter(this);
177  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
178  msgPtr->setContent(data);
179  msgPtr->parse();
180  Akonadi::Item item;
181  item.setPayload<KMime::Message::Ptr>(msgPtr);
182  MailCommon::ItemContext context(item, true);
183 
184  filter.argsFromString("testheader\tfoo");
185  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
186  QCOMPARE(context.needsPayloadStore(), true);
187  QCOMPARE(msgPtr->encodedContent(), output);
188  QCOMPARE(context.deleteItem(), false);
189  QCOMPARE(context.needsFlagStore(), false);
190 }
191 
192 void FilterActionAddHeaderTest::shouldAddValue()
193 {
194  QFETCH( QString, argsinput );
195  QFETCH( QString, resultheader );
196  QFETCH( QString, resultvalue );
197 
198  MailCommon::FilterActionAddHeader filter;
199  QWidget* widget = filter.createParamWidget(0);
200  filter.argsFromString(argsinput);
201  filter.setParamWidgetValue(widget);
202  PimCommon::MinimumComboBox *comboBox = widget->findChild<PimCommon::MinimumComboBox *>(QLatin1String("combo"));
203  KLineEdit *lineEdit = widget->findChild<KLineEdit *>(QLatin1String("ledit"));
204  QCOMPARE(comboBox->lineEdit()->text(), resultheader);
205  QCOMPARE(lineEdit->text(), resultvalue);
206 }
207 
208 void FilterActionAddHeaderTest::shouldRequiresSieve()
209 {
210  MailCommon::FilterActionAddHeader filter;
211  QCOMPARE(filter.sieveRequires(), QStringList() << QLatin1String("editheader"));
212 }
213 
214 
215 QTEST_KDEMAIN(FilterActionAddHeaderTest, GUI)
QWidget
MailCommon::FilterAction::GoOn
Go on with applying filter actions.
Definition: filteraction.h:62
MailCommon::FilterActionAddHeader::process
ReturnCode process(ItemContext &context, bool applyOnOutbound) const
Execute action on given message (inside the item context).
Definition: filteractionaddheader.cpp:52
QByteArray
MailCommon::FilterActionAddHeader::clearParamWidget
void clearParamWidget(QWidget *paramWidget) const
The filter action shall clear it's parameter widget's contents.
Definition: filteractionaddheader.cpp:150
MailCommon::FilterActionAddHeader::createParamWidget
QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
Definition: filteractionaddheader.cpp:74
QStringList::join
QString join(const QString &separator) const
MailCommon::FilterActionAddHeader
Definition: filteractionaddheader.h:31
FilterActionAddHeaderTest
Definition: filteractionaddheadertest.h:24
itemcontext.h
MailCommon::FilterAction::ErrorButGoOn
A non-critical error occurred.
Definition: filteraction.h:63
QObject
MailCommon::FilterActionAddHeader::setParamWidgetValue
void setParamWidgetValue(QWidget *paramWidget) const
The filter action shall set it's widget's contents from it's parameter.
Definition: filteractionaddheader.cpp:117
QString
FilterActionAddHeaderTest::~FilterActionAddHeaderTest
~FilterActionAddHeaderTest()
Definition: filteractionaddheadertest.cpp:32
QStringList
filteractionaddheadertest.h
QLatin1Char
MailCommon::FilterActionAddHeader::argsFromString
void argsFromString(const QString &argsStr)
Read extra arguments from given string.
Definition: filteractionaddheader.cpp:181
QTest::newRow
QTestData & newRow(const char *dataTag)
QLatin1String
context
const char * context
Definition: searchpatternedit.cpp:54
FilterActionAddHeaderTest::FilterActionAddHeaderTest
FilterActionAddHeaderTest(QObject *parent=0)
Definition: filteractionaddheadertest.cpp:26
MailCommon::FilterActionAddHeader::isEmpty
bool isEmpty() const
Determines whether this action is valid.
Definition: filteractionaddheader.cpp:47
MailCommon::FilterActionAddHeader::sieveRequires
QStringList sieveRequires() const
Definition: filteractionaddheader.cpp:207
MailCommon::ItemContext
A helper class for the filtering process.
Definition: itemcontext.h:39
QLabel
QObject::findChild
T findChild(const QString &name) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal