davcollectionsmultifetchjobtest.cpp 2.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
    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>

#include <QTest>

using KDAV::DavCollection;

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");
}

void DavCollectionsMultiFetchJobTest::runSuccessfullTest()
{
26
    FakeServer fakeServer(5990);
27 28 29 30 31 32 33 34 35 36 37 38 39 40 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
    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});
    // TODO QSignalSpy spy(job, &KDAV::DavCollectionsMultiFetchJob::collectionDiscovered);

    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);
}

QTEST_MAIN(DavCollectionsMultiFetchJobTest)