File indexing completed on 2024-05-12 05:10:01
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 "igdbfetchertest.h" 0028 0029 #include "../fetch/igdbfetcher.h" 0030 #include "../collections/gamecollection.h" 0031 #include "../entry.h" 0032 #include "../images/imagefactory.h" 0033 0034 #include <KConfigGroup> 0035 0036 #include <QTest> 0037 0038 QTEST_GUILESS_MAIN( IGDBFetcherTest ) 0039 0040 IGDBFetcherTest::IGDBFetcherTest() : AbstractFetcherTest() 0041 , m_config(QFINDTESTDATA("tellicotest.config"), KConfig::SimpleConfig) { 0042 } 0043 0044 void IGDBFetcherTest::initTestCase() { 0045 Tellico::ImageFactory::init(); 0046 m_hasConfigFile = QFile::exists(QFINDTESTDATA("tellicotest.config")); 0047 } 0048 0049 void IGDBFetcherTest::testKeyword() { 0050 const QString groupName = QStringLiteral("IGDB"); 0051 if(!m_hasConfigFile || !m_config.hasGroup(groupName)) { 0052 QSKIP("This test requires a config file with IGDB settings.", SkipAll); 0053 } 0054 KConfigGroup cg(&m_config, groupName); 0055 0056 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game, Tellico::Fetch::Keyword, 0057 QStringLiteral("Zelda Twilight Princess")); 0058 QScopedPointer<Tellico::Fetch::Fetcher> fetcher(new Tellico::Fetch::IGDBFetcher(this)); 0059 fetcher->readConfig(cg); 0060 0061 Tellico::Data::EntryList results = DO_FETCH1(fetcher.data(), request, 5); 0062 fetcher->saveConfig(); // to save the access token 0063 0064 QVERIFY(!results.isEmpty()); 0065 // want the Wii version 0066 Tellico::Data::EntryPtr entry; 0067 foreach(Tellico::Data::EntryPtr e, results) { 0068 if(e->field("platform") == QStringLiteral("Nintendo Wii")) { 0069 entry = e; 0070 break; 0071 } 0072 } 0073 0074 QVERIFY(entry); 0075 QCOMPARE(entry->field("title"), QStringLiteral("The Legend of Zelda: Twilight Princess")); 0076 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0077 QCOMPARE(entry->field("platform"), QStringLiteral("Nintendo Wii")); 0078 QCOMPARE(entry->field("certification"), QStringLiteral("Teen")); 0079 QCOMPARE(entry->field("pegi"), QStringLiteral("PEGI 12")); 0080 QCOMPARE(entry->field("genre"), QStringLiteral("Role-playing (RPG); Adventure")); 0081 QCOMPARE(entry->field("publisher"), QStringLiteral("Nintendo")); 0082 QCOMPARE(entry->field("developer"), QStringLiteral("Nintendo EAD Software Development Group No.3")); 0083 QCOMPARE(entry->field("igdb"), QStringLiteral("https://www.igdb.com/games/the-legend-of-zelda-twilight-princess--1")); 0084 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0085 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0086 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0087 QVERIFY(!entry->field(QStringLiteral("screenshot")).isEmpty()); 0088 QVERIFY(!entry->field(QStringLiteral("screenshot")).contains(QLatin1Char('/'))); 0089 }