File indexing completed on 2024-05-12 05:10:06

0001 /***************************************************************************
0002     Copyright (C) 2023 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 "vgcollectfetchertest.h"
0028 
0029 #include "../fetch/vgcollectfetcher.h"
0030 #include "../collections/gamecollection.h"
0031 #include "../entry.h"
0032 #include "../images/imagefactory.h"
0033 
0034 #include <KSharedConfig>
0035 
0036 #include <QTest>
0037 
0038 QTEST_GUILESS_MAIN( VGCollectFetcherTest )
0039 
0040 VGCollectFetcherTest::VGCollectFetcherTest() : AbstractFetcherTest() {
0041 }
0042 
0043 void VGCollectFetcherTest::initTestCase() {
0044   Tellico::ImageFactory::init();
0045 }
0046 
0047 void VGCollectFetcherTest::testKeyword() {
0048   auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("vgcollect"));
0049   config.writeEntry("Custom Fields", QStringLiteral("vgcollect,pegi,barcode"));
0050 
0051   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game, Tellico::Fetch::Keyword,
0052                                        QStringLiteral("Sunset Overdrive - Day One Edition"));
0053   QScopedPointer<Tellico::Fetch::Fetcher> fetcher(new Tellico::Fetch::VGCollectFetcher(this));
0054   fetcher->readConfig(config);
0055 
0056   Tellico::Data::EntryList results = DO_FETCH1(fetcher.data(), request, 5);
0057 
0058   QVERIFY(!results.isEmpty());
0059   // want the Wii version
0060   Tellico::Data::EntryPtr entry;
0061   foreach(Tellico::Data::EntryPtr tryEntry, results) {
0062     if(tryEntry->field("platform") == QLatin1String("Xbox One") &&
0063        tryEntry->field("publisher") == QLatin1String("Microsoft")) {
0064       entry = tryEntry;
0065       break;
0066     }
0067   }
0068 
0069   QVERIFY(entry);
0070   QCOMPARE(entry->field("title"), QStringLiteral("Sunset Overdrive - Day One Edition"));
0071   QCOMPARE(entry->field("year"), QStringLiteral("2014"));
0072   QCOMPARE(entry->field("platform"), QStringLiteral("Xbox One"));
0073   QCOMPARE(entry->field("certification"), QStringLiteral("Mature"));
0074   QCOMPARE(entry->field("genre"), QStringLiteral("Action"));
0075   QCOMPARE(entry->field("publisher"), QStringLiteral("Microsoft"));
0076   QCOMPARE(entry->field("developer"), QStringLiteral("Insomniac Games"));
0077   QCOMPARE(entry->field("barcode"), QStringLiteral("885370848847"));
0078   QCOMPARE(entry->field("vgcollect"), QStringLiteral("https://vgcollect.com/item/68543"));
0079   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0080   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0081   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0082 }