File indexing completed on 2024-05-12 16:46:13
0001 /*************************************************************************** 0002 Copyright (C) 2016-2020 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 "bedethequefetchertest.h" 0028 0029 #include "../fetch/bedethequefetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/comicbookcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../images/imagefactory.h" 0034 #include "../fieldformat.h" 0035 #include "../fetch/fetcherjob.h" 0036 0037 #include <KSharedConfig> 0038 0039 #include <QTest> 0040 0041 QTEST_GUILESS_MAIN( BedethequeFetcherTest ) 0042 0043 BedethequeFetcherTest::BedethequeFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void BedethequeFetcherTest::initTestCase() { 0047 Tellico::ImageFactory::init(); 0048 Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerCB(Tellico::Data::Collection::ComicBook, "comic"); 0049 0050 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("bedetheque")); 0051 m_config.writeEntry("Custom Fields", QStringLiteral("isbn,lien-bel,colorist,comments")); 0052 } 0053 0054 void BedethequeFetcherTest::testTitle() { 0055 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title, QStringLiteral("Le Combat d'Odiri")); 0056 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0057 fetcher->readConfig(m_config); 0058 0059 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0060 0061 QCOMPARE(results.size(), 1); 0062 0063 // the first entry had better be the right one 0064 Tellico::Data::EntryPtr entry = results.at(0); 0065 0066 QCOMPARE(entry->field("title"), QStringLiteral("Le Combat d'Odiri")); 0067 QCOMPARE(entry->field("pub_year"), QStringLiteral("1991")); 0068 QCOMPARE(entry->field("series"), QStringLiteral("(AUT) Arno")); 0069 QCOMPARE(entry->field("writer"), QString::fromUtf8("Châteaureynaud, Georges-Olivier")); 0070 QCOMPARE(entry->field("publisher"), QStringLiteral("Bayard")); 0071 QCOMPARE(entry->field("artist"), QStringLiteral("Arno")); 0072 QCOMPARE(entry->field("colorist"), QStringLiteral("Arno")); 0073 QCOMPARE(entry->field("pages"), QStringLiteral("88")); 0074 QCOMPARE(entry->field("genre"), QStringLiteral("Tout sur un auteur (hors BD)")); 0075 QCOMPARE(entry->field("isbn"), QStringLiteral("2-227-72311-4")); 0076 QCOMPARE(entry->field("edition"), QString::fromUtf8("Je bouquine : à partir de 10 ans")); 0077 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-AUT-Arno-Le-Combat-d-Odiri-46179.html")); 0078 QVERIFY(!entry->field("cover").isEmpty()); 0079 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0080 } 0081 0082 void BedethequeFetcherTest::testSeries() { 0083 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Keyword, QStringLiteral("Arno")); 0084 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0085 fetcher->readConfig(m_config); 0086 0087 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0088 0089 QCOMPARE(results.size(), 1); 0090 0091 // the first entry had better be the right one 0092 Tellico::Data::EntryPtr entry = results.at(0); 0093 0094 QCOMPARE(entry->field("title"), QStringLiteral("Le Combat d'Odiri")); 0095 QCOMPARE(entry->field("pub_year"), QStringLiteral("1991")); 0096 QCOMPARE(entry->field("series"), QStringLiteral("(AUT) Arno")); 0097 QCOMPARE(entry->field("writer"), QString::fromUtf8("Châteaureynaud, Georges-Olivier")); 0098 QCOMPARE(entry->field("publisher"), QStringLiteral("Bayard")); 0099 QCOMPARE(entry->field("artist"), QStringLiteral("Arno")); 0100 QCOMPARE(entry->field("colorist"), QStringLiteral("Arno")); 0101 QCOMPARE(entry->field("pages"), QStringLiteral("88")); 0102 QCOMPARE(entry->field("genre"), QStringLiteral("Tout sur un auteur (hors BD)")); 0103 QCOMPARE(entry->field("isbn"), QStringLiteral("2-227-72311-4")); 0104 QCOMPARE(entry->field("edition"), QString::fromUtf8("Je bouquine : à partir de 10 ans")); 0105 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-AUT-Arno-Le-Combat-d-Odiri-46179.html")); 0106 QVERIFY(!entry->field("cover").isEmpty()); 0107 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0108 } 0109 0110 void BedethequeFetcherTest::testIsbn() { 0111 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::ISBN, QStringLiteral("2-205-05868-1")); 0112 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0113 fetcher->readConfig(m_config); 0114 0115 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0116 0117 QCOMPARE(results.size(), 1); 0118 Tellico::Data::EntryPtr entry = results.at(0); 0119 0120 QCOMPARE(entry->field("title"), QString::fromUtf8("Jérusalem d'Afrique")); 0121 QCOMPARE(entry->field("pub_year"), QStringLiteral("2006")); 0122 QCOMPARE(entry->field("series"), QStringLiteral("Chat du Rabbin (Le)")); 0123 QCOMPARE(entry->field("writer"), QStringLiteral("Sfar, Joann")); 0124 QCOMPARE(entry->field("artist"), QStringLiteral("Sfar, Joann")); 0125 QCOMPARE(entry->field("colorist"), QStringLiteral("Findakly, Brigitte")); 0126 QCOMPARE(entry->field("publisher"), QStringLiteral("Dargaud")); 0127 QCOMPARE(entry->field("pages"), QStringLiteral("80")); 0128 QCOMPARE(entry->field("issue"), QStringLiteral("5")); 0129 QCOMPARE(entry->field("edition"), QStringLiteral("Poisson Pilote")); 0130 QCOMPARE(entry->field("genre"), QStringLiteral("Aventure")); 0131 QCOMPARE(entry->field("isbn"), QStringLiteral("2-205-05868-1")); 0132 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-Chat-du-Rabbin-Tome-5-Jerusalem-d-Afrique-59668.html")); 0133 QVERIFY(!entry->field("comments").isEmpty()); 0134 QVERIFY(!entry->field("cover").isEmpty()); 0135 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0136 } 0137 0138 void BedethequeFetcherTest::testDonjon() { 0139 // this one has multiple writers 0140 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Raw, QStringLiteral("http://m.bedetheque.com/BD-Donjon-Zenith-Tome-5-Un-mariage-a-part-56495.html")); 0141 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0142 fetcher->readConfig(m_config); 0143 0144 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0145 0146 QCOMPARE(results.size(), 1); 0147 Tellico::Data::EntryPtr entry = results.at(0); 0148 0149 QCOMPARE(entry->field("title"), QString::fromUtf8("Un mariage à part")); 0150 QCOMPARE(set(entry, "writer"), set("Sfar, Joann; Boulet; Trondheim, Lewis")); 0151 QCOMPARE(entry->field("artist"), QStringLiteral("Boulet")); 0152 QCOMPARE(entry->field("colorist"), QStringLiteral("Albon, Lucie")); 0153 QCOMPARE(entry->field("isbn"), QStringLiteral("2-84055-734-7")); 0154 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-Donjon-Zenith-Tome-5-Un-mariage-a-part-56495.html")); 0155 QVERIFY(!entry->field("cover").isEmpty()); 0156 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0157 }