File indexing completed on 2024-05-12 05:09:54
0001 /*************************************************************************** 0002 Copyright (C) 2010-2011 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 "boardgamegeekfetchertest.h" 0028 0029 #include "../fetch/boardgamegeekfetcher.h" 0030 #include "../collections/boardgamecollection.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( BoardGameGeekFetcherTest ) 0041 0042 BoardGameGeekFetcherTest::BoardGameGeekFetcherTest() : AbstractFetcherTest() { 0043 } 0044 0045 void BoardGameGeekFetcherTest::initTestCase() { 0046 Tellico::RegisterCollection<Tellico::Data::BoardGameCollection> registerBoard(Tellico::Data::Collection::BoardGame, "boardgame"); 0047 Tellico::ImageFactory::init(); 0048 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/boardgamegeek2tellico.xsl")); 0049 } 0050 0051 void BoardGameGeekFetcherTest::testTitle() { 0052 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::BoardGame, Tellico::Fetch::Title, 0053 QStringLiteral("Catan")); 0054 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BoardGameGeekFetcher(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::BoardGame); 0063 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("CATAN")); 0064 QCOMPARE(entry->field(QStringLiteral("designer")), QStringLiteral("Klaus Teuber")); 0065 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("publisher"))).at(0), QStringLiteral("KOSMOS")); 0066 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1995")); 0067 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("genre"))).at(0), QStringLiteral("Economic")); 0068 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("mechanism"))).at(0), QStringLiteral("Chaining")); 0069 QCOMPARE(entry->field(QStringLiteral("num-player")), QStringLiteral("3; 4")); 0070 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0071 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0072 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0073 QCOMPARE(entry->field(QStringLiteral("boardgamegeek-link")), QStringLiteral("https://www.boardgamegeek.com/boardgame/13")); 0074 } 0075 0076 void BoardGameGeekFetcherTest::testKeyword() { 0077 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::BoardGame, Tellico::Fetch::Keyword, 0078 QStringLiteral("The Settlers of Catan")); 0079 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BoardGameGeekFetcher(this)); 0080 QVERIFY(fetcher->canSearch(request.key())); 0081 0082 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0083 0084 QCOMPARE(results.size(), 10); 0085 } 0086 0087 void BoardGameGeekFetcherTest::testUpdate() { 0088 Tellico::Data::CollPtr coll(new Tellico::Data::BoardGameCollection(true)); 0089 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("bggid"), QStringLiteral("bggid"))); 0090 coll->addField(field); 0091 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0092 coll->addEntries(entry); 0093 entry->setField(QStringLiteral("bggid"), QStringLiteral("13")); 0094 0095 Tellico::Fetch::BoardGameGeekFetcher fetcher(this); 0096 auto request = fetcher.updateRequest(entry); 0097 request.setCollectionType(coll->type()); 0098 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0099 QCOMPARE(request.value(), QStringLiteral("13")); 0100 0101 Tellico::Data::EntryList results = DO_FETCH1(&fetcher, request, 1); 0102 QCOMPARE(results.size(), 1); 0103 0104 entry = results.at(0); 0105 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::BoardGame); 0106 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("CATAN")); 0107 QCOMPARE(entry->field(QStringLiteral("designer")), QStringLiteral("Klaus Teuber")); 0108 }