File indexing completed on 2025-01-05 03:58:12
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-03-22 0007 * Description : a MediaWiki C++ interface 0008 * 0009 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com> 0011 * SPDX-FileCopyrightText: 2011 by Hormiere Guillaume <hormiere dot guillaume at gmail dot com> 0012 * SPDX-FileCopyrightText: 2011 by Manuel Campomanes <campomanes dot manuel at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 // Qt includes 0019 0020 #include <QObject> 0021 #include <QTest> 0022 0023 // KDE includes 0024 0025 #include <kjob.h> 0026 0027 // Local includes 0028 0029 #include "mediawiki_iface.h" 0030 #include "mediawiki_logout.h" 0031 #include "fakeserver/fakeserver.h" 0032 0033 using MediaWiki::Iface; 0034 using MediaWiki::Logout; 0035 0036 class Q_DECL_HIDDEN LogoutTest : public QObject 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 0042 explicit LogoutTest(QObject* const parent = nullptr) 0043 { 0044 Q_UNUSED(parent); 0045 logoutCount = 0; 0046 m_mediaWiki = nullptr; 0047 m_server = nullptr; 0048 } 0049 0050 public Q_SLOTS: 0051 0052 void logoutHandle(KJob* job) 0053 { 0054 Q_UNUSED(job) 0055 logoutCount++; 0056 } 0057 0058 private Q_SLOTS: 0059 0060 void initTestCase() 0061 { 0062 logoutCount = 0; 0063 this->m_mediaWiki = new Iface(QUrl(QStringLiteral("http://127.0.0.1:12566"))); // krazy:exclude=insecurenet 0064 this->m_server = new FakeServer; 0065 this->request = QStringLiteral("/?format=xml&action=logout"); 0066 } 0067 0068 void logoutTestConnectTrue() 0069 { 0070 QString senario(QStringLiteral("<api />") ); 0071 QString cookie( QStringLiteral("cookieprefix=\"enwiki\" sessionid=\"17ab96bd8ffbe8ca58a78657a918558e\" expires=\"Sat, 12-Feb-2011 21:39:30 GMT\"")); 0072 m_server->setScenario(senario, cookie); 0073 m_server->startAndWait(); 0074 0075 logoutCount = 0; 0076 Logout logout(*m_mediaWiki); 0077 0078 connect(&logout, SIGNAL(result(KJob*)), 0079 this, SLOT(logoutHandle(KJob*))); 0080 0081 logout.exec(); // krazy:exclude=crashy 0082 QCOMPARE(this->logoutCount, 1); 0083 QCOMPARE(logout.error(), (int)Logout::NoError); 0084 0085 QList<FakeServer::Request> requests = m_server->getRequest(); 0086 QCOMPARE(requests.size(), 1); 0087 0088 FakeServer::Request request2 = requests[0]; 0089 QCOMPARE(request2.agent, m_mediaWiki->userAgent()); 0090 QCOMPARE(request2.type, QStringLiteral("GET")); 0091 QCOMPARE(request2.value, QStringLiteral("/?format=xml&action=logout")); 0092 } 0093 0094 void cleanupTestCase() 0095 { 0096 delete this->m_mediaWiki; 0097 delete this->m_server; 0098 } 0099 0100 private: 0101 0102 int logoutCount; 0103 QString request; 0104 Iface* m_mediaWiki; 0105 FakeServer* m_server; 0106 }; 0107 0108 QTEST_MAIN(LogoutTest) 0109 0110 #include "logout_utest.moc"