File indexing completed on 2024-05-12 05:10:05
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 "../collectionfactory.h" 0032 #include "../entry.h" 0033 #include "../images/imagefactory.h" 0034 #include "../utils/datafileregistry.h" 0035 0036 #include <KSharedConfig> 0037 #include <KConfigGroup> 0038 0039 #include <QTest> 0040 0041 QTEST_GUILESS_MAIN( RPGGeekFetcherTest ) 0042 0043 RPGGeekFetcherTest::RPGGeekFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void RPGGeekFetcherTest::initTestCase() { 0047 Tellico::RegisterCollection<Tellico::Data::Collection> registerColl(Tellico::Data::Collection::Base, "entry"); 0048 Tellico::ImageFactory::init(); 0049 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/boardgamegeek2tellico.xsl")); 0050 } 0051 0052 void RPGGeekFetcherTest::testKeyword() { 0053 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("rpggeek")); 0054 cg.writeEntry("Custom Fields", QStringLiteral("genre,year,publisher,artist,designer,producer,mechanism,description,rpggeek-link")); 0055 0056 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Base, Tellico::Fetch::Keyword, 0057 QStringLiteral("Winds of the North")); 0058 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::RPGGeekFetcher(this)); 0059 QVERIFY(fetcher->canSearch(request.key())); 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 } 0085 0086 void RPGGeekFetcherTest::testUpdate() { 0087 Tellico::Data::CollPtr coll(new Tellico::Data::Collection(true)); 0088 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("bggid"), QStringLiteral("bggid"))); 0089 coll->addField(field); 0090 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0091 coll->addEntries(entry); 0092 entry->setField(QStringLiteral("bggid"), QStringLiteral("338762")); 0093 0094 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("rpggeek")); 0095 cg.writeEntry("Custom Fields", QStringLiteral("genre,year,publisher,artist,designer,producer,mechanism,description,rpggeek-link")); 0096 0097 Tellico::Fetch::RPGGeekFetcher fetcher(this); 0098 auto request = fetcher.updateRequest(entry); 0099 request.setCollectionType(coll->type()); 0100 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0101 QCOMPARE(request.value(), QStringLiteral("338762")); 0102 fetcher.readConfig(cg); 0103 0104 Tellico::Data::EntryList results = DO_FETCH1(&fetcher, request, 1); 0105 QCOMPARE(results.size(), 1); 0106 0107 entry = results.at(0); 0108 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Base); 0109 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Winds of the North")); 0110 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("(Self-Published)")); 0111 QCOMPARE(entry->field(QStringLiteral("designer")), QStringLiteral("Thomas King")); 0112 QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Nils Bergslien")); 0113 QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Thomas King")); 0114 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Culture; History; History (Medieval); History (Vikings); Mythology / Folklore")); 0115 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("0")); 0116 auto genres = Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("genre"))); 0117 QVERIFY(genres.count() > 2); 0118 QVERIFY(genres.contains(QStringLiteral("Culture"))); 0119 auto mechs = Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("mechanism"))); 0120 QVERIFY(mechs.count() > 2); 0121 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0122 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0123 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0124 QCOMPARE(entry->field(QStringLiteral("rpggeek-link")), QStringLiteral("https://rpggeek.com/rpgitem/338762")); 0125 }