davcollectionsmultifetchjobtest.cpp 3.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/*
    SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "davcollectionsmultifetchjobtest.h"
#include "fakeserver.h"

#include <KDAV/DavCollectionsMultiFetchJob>

12
#include <QSignalSpy>
13
14
15
#include <QTest>

using KDAV::DavCollection;
16
Q_DECLARE_METATYPE(KDAV::Protocol)
17
18
19
20
21
22
23

void DavCollectionsMultiFetchJobTest::initTestCase()
{
    // To avoid a runtime dependency on klauncher
    qputenv("KDE_FORK_SLAVES", "yes");
    // To let ctest exit, we shouldn't start kio_http_cache_cleaner
    qputenv("KIO_DISABLE_CACHE_CLEANER", "yes");
24
25

    qRegisterMetaType<KDAV::Protocol>();
26
27
28
29
}

void DavCollectionsMultiFetchJobTest::runSuccessfullTest()
{
30
    FakeServer fakeServer(5990);
31
32
33
34
35
36
37
38
    QUrl url(QStringLiteral("http://localhost/caldav"));
    url.setPort(fakeServer.port());
    KDAV::DavUrl davUrl1(url, KDAV::CalDav);
    QUrl url2(url);
    url2.setPath(QStringLiteral("/carddav"));
    KDAV::DavUrl davUrl2(url2, KDAV::CardDav);

    auto job = new KDAV::DavCollectionsMultiFetchJob({davUrl1, davUrl2});
39
40

    QSignalSpy spy(job, &KDAV::DavCollectionsMultiFetchJob::collectionDiscovered);
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

    fakeServer.addScenarioFromFile(QLatin1String(AUTOTEST_DATA_DIR)+QStringLiteral("/dataitemmultifetchjob-caldav.txt"));
    fakeServer.addScenarioFromFile(QLatin1String(AUTOTEST_DATA_DIR)+QStringLiteral("/dataitemmultifetchjob-caldav-collections.txt"));
    fakeServer.addScenarioFromFile(QLatin1String(AUTOTEST_DATA_DIR)+QStringLiteral("/dataitemmultifetchjob-carddav.txt"));
    fakeServer.addScenarioFromFile(QLatin1String(AUTOTEST_DATA_DIR)+QStringLiteral("/dataitemmultifetchjob-carddav-collections.txt"));
    fakeServer.startAndWait();
    job->exec();
    fakeServer.quit();

    QVERIFY(fakeServer.isAllScenarioDone());
    QCOMPARE(job->error(), 0);

    const KDAV::DavCollection::List collections = job->collections();
    QCOMPARE(collections.count(), 2);

    const KDAV::DavCollection calendar = collections.at(0);
    QCOMPARE(calendar.displayName(), QStringLiteral("Test1 User"));
    QCOMPARE(calendar.contentTypes(), DavCollection::Events | DavCollection::Todos | DavCollection::FreeBusy | DavCollection::Journal);
    QCOMPARE(calendar.url().url().path(), QStringLiteral("/caldav.php/test1.user/home/"));
    QCOMPARE(calendar.CTag(), QStringLiteral("12345"));
    QCOMPARE(calendar.privileges(), KDAV::Read);

    const KDAV::DavCollection addressbook = collections.at(1);
    QCOMPARE(addressbook.displayName(), QStringLiteral("My Address Book"));
    QCOMPARE(addressbook.contentTypes(), DavCollection::Contacts);
    QCOMPARE(addressbook.url().url().path(), QStringLiteral("/carddav.php/test1.user/home/"));
    QCOMPARE(addressbook.CTag(), QStringLiteral("3145"));
    QCOMPARE(addressbook.privileges(), KDAV::All);
69
70
71
72
73
74
75
76
77

    QCOMPARE(spy.count(), 2);
    QCOMPARE(int(spy.at(0).at(0).value<KDAV::Protocol>()), int(KDAV::CalDav));
    QCOMPARE(spy.at(0).at(1).toString(), calendar.url().url().toString());
    QCOMPARE(spy.at(0).at(2).toString(), url.toString());

    QCOMPARE(int(spy.at(1).at(0).value<KDAV::Protocol>()), int(KDAV::CardDav));
    QCOMPARE(spy.at(1).at(1).toString(), addressbook.url().url().toString());
    QCOMPARE(spy.at(1).at(2).toString(), url2.toString());
78
79
80
}

QTEST_MAIN(DavCollectionsMultiFetchJobTest)