File indexing completed on 2024-05-12 05:10:06
0001 /*************************************************************************** 0002 Copyright (C) 2017 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 "videogamegeekfetchertest.h" 0028 0029 #include "../fetch/videogamegeekfetcher.h" 0030 #include "../collections/gamecollection.h" 0031 #include "../collectionfactory.h" 0032 #include "../entry.h" 0033 #include "../images/imagefactory.h" 0034 #include "../utils/datafileregistry.h" 0035 0036 #include <KConfigGroup> 0037 0038 #include <QTest> 0039 0040 QTEST_GUILESS_MAIN( VideoGameGeekFetcherTest ) 0041 0042 VideoGameGeekFetcherTest::VideoGameGeekFetcherTest() : AbstractFetcherTest() { 0043 } 0044 0045 void VideoGameGeekFetcherTest::initTestCase() { 0046 Tellico::RegisterCollection<Tellico::Data::GameCollection> registerVGG(Tellico::Data::Collection::Game, "game"); 0047 Tellico::ImageFactory::init(); 0048 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/boardgamegeek2tellico.xsl")); 0049 } 0050 0051 void VideoGameGeekFetcherTest::testKeyword() { 0052 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game, Tellico::Fetch::Keyword, 0053 QStringLiteral("Mass Effect 3 Citadel")); 0054 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::VideoGameGeekFetcher(this)); 0055 QVERIFY(fetcher->canSearch(request.key())); 0056 0057 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0058 0059 QCOMPARE(results.size(), 1); 0060 0061 Tellico::Data::EntryPtr entry = results.at(0); 0062 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Game); 0063 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Mass Effect 3 - Citadel")); 0064 QCOMPARE(entry->field(QStringLiteral("developer")), QStringLiteral("BioWare")); 0065 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Electronic Arts Inc. (EA)")); 0066 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2013")); 0067 // QCOMPARE(entry->field(QStringLiteral("platform")), QStringLiteral("PlayStation3")); 0068 QCOMPARE(set(entry, "genre"), set("Action RPG; Shooter")); 0069 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0070 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0071 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0072 QCOMPARE(entry->field(QStringLiteral("videogamegeek-link")), QStringLiteral("https://www.videogamegeek.com/videogame/139806")); 0073 } 0074 0075 void VideoGameGeekFetcherTest::testUpdate() { 0076 Tellico::Data::CollPtr coll(new Tellico::Data::GameCollection(true)); 0077 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("bggid"), QStringLiteral("bggid"))); 0078 coll->addField(field); 0079 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0080 coll->addEntries(entry); 0081 entry->setField(QStringLiteral("bggid"), QStringLiteral("139806")); 0082 0083 Tellico::Fetch::VideoGameGeekFetcher fetcher(this); 0084 auto request = fetcher.updateRequest(entry); 0085 request.setCollectionType(coll->type()); 0086 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0087 QCOMPARE(request.value(), QStringLiteral("139806")); 0088 0089 Tellico::Data::EntryList results = DO_FETCH1(&fetcher, request, 1); 0090 QCOMPARE(results.size(), 1); 0091 0092 entry = results.at(0); 0093 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Game); 0094 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Mass Effect 3 - Citadel")); 0095 QCOMPARE(entry->field(QStringLiteral("developer")), QStringLiteral("BioWare")); 0096 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Electronic Arts Inc. (EA)")); 0097 }