File indexing completed on 2024-05-12 16:46:23
0001 /*************************************************************************** 0002 Copyright (C) 2021 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "rpggeekfetchertest.h" 0028 0029 #include "../fetch/rpggeekfetcher.h" 0030 #include "../collection.h" 0031 #include "../collections/bookcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../entry.h" 0034 #include "../images/imagefactory.h" 0035 #include "../utils/datafileregistry.h" 0036 0037 #include <KSharedConfig> 0038 #include <KConfigGroup> 0039 0040 #include <QTest> 0041 0042 QTEST_GUILESS_MAIN( RPGGeekFetcherTest ) 0043 0044 RPGGeekFetcherTest::RPGGeekFetcherTest() : AbstractFetcherTest() { 0045 } 0046 0047 void RPGGeekFetcherTest::initTestCase() { 0048 Tellico::RegisterCollection<Tellico::Data::Collection> registerColl(Tellico::Data::Collection::Base, "entry"); 0049 Tellico::ImageFactory::init(); 0050 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/boardgamegeek2tellico.xsl")); 0051 } 0052 0053 void RPGGeekFetcherTest::testKeyword() { 0054 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("rpggeek")); 0055 cg.writeEntry("Custom Fields", QStringLiteral("genre,year,publisher,artist,designer,producer,mechanism,description,rpggeek-link")); 0056 0057 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Base, Tellico::Fetch::Keyword, 0058 QStringLiteral("Winds of the North")); 0059 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::RPGGeekFetcher(this)); 0060 fetcher->readConfig(cg); 0061 0062 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0063 0064 QCOMPARE(results.size(), 1); 0065 0066 Tellico::Data::EntryPtr entry = results.at(0); 0067 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Base); 0068 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Winds of the North")); 0069 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("(Self-Published)")); 0070 QCOMPARE(entry->field(QStringLiteral("designer")), QStringLiteral("Thomas King")); 0071 QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Nils Bergslien")); 0072 QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Thomas King")); 0073 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Culture; History; History (Medieval); History (Vikings); Mythology / Folklore")); 0074 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("0")); 0075 auto genres = Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("genre"))); 0076 QVERIFY(genres.count() > 2); 0077 QVERIFY(genres.contains(QStringLiteral("Culture"))); 0078 auto mechs = Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("mechanism"))); 0079 QVERIFY(mechs.count() > 2); 0080 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0081 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0082 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0083 QCOMPARE(entry->field(QStringLiteral("rpggeek-link")), QStringLiteral("https://rpggeek.com/rpgitem/338762")); 0084 }