File indexing completed on 2024-05-12 05:09:54
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 0035 #include <KSharedConfig> 0036 0037 #include <QTest> 0038 0039 QTEST_GUILESS_MAIN( BedethequeFetcherTest ) 0040 0041 BedethequeFetcherTest::BedethequeFetcherTest() : AbstractFetcherTest() { 0042 } 0043 0044 void BedethequeFetcherTest::initTestCase() { 0045 Tellico::ImageFactory::init(); 0046 Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerCB(Tellico::Data::Collection::ComicBook, "comic"); 0047 0048 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("bedetheque")); 0049 m_config.writeEntry("Custom Fields", QStringLiteral("isbn,lien-bel,colorist,comments")); 0050 } 0051 0052 void BedethequeFetcherTest::testTitle() { 0053 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title, 0054 QStringLiteral("Le Combat d'Odiri")); 0055 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0056 fetcher->readConfig(m_config); 0057 QVERIFY(fetcher->canSearch(request.key())); 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, 0084 QStringLiteral("Arno")); 0085 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0086 fetcher->readConfig(m_config); 0087 QVERIFY(fetcher->canSearch(request.key())); 0088 0089 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0090 0091 QCOMPARE(results.size(), 1); 0092 0093 // the first entry had better be the right one 0094 Tellico::Data::EntryPtr entry = results.at(0); 0095 0096 QCOMPARE(entry->field("title"), QStringLiteral("Le Combat d'Odiri")); 0097 QCOMPARE(entry->field("pub_year"), QStringLiteral("1991")); 0098 QCOMPARE(entry->field("series"), QStringLiteral("(AUT) Arno")); 0099 QCOMPARE(entry->field("writer"), QString::fromUtf8("Châteaureynaud, Georges-Olivier")); 0100 QCOMPARE(entry->field("publisher"), QStringLiteral("Bayard")); 0101 QCOMPARE(entry->field("artist"), QStringLiteral("Arno")); 0102 QCOMPARE(entry->field("colorist"), QStringLiteral("Arno")); 0103 QCOMPARE(entry->field("pages"), QStringLiteral("88")); 0104 QCOMPARE(entry->field("genre"), QStringLiteral("Tout sur un auteur (hors BD)")); 0105 QCOMPARE(entry->field("isbn"), QStringLiteral("2-227-72311-4")); 0106 QCOMPARE(entry->field("edition"), QString::fromUtf8("Je bouquine : à partir de 10 ans")); 0107 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-AUT-Arno-Le-Combat-d-Odiri-46179.html")); 0108 QVERIFY(!entry->field("cover").isEmpty()); 0109 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0110 } 0111 0112 void BedethequeFetcherTest::testIsbn() { 0113 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::ISBN, 0114 QStringLiteral("2-205-05868-1")); 0115 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0116 fetcher->readConfig(m_config); 0117 QVERIFY(fetcher->canSearch(request.key())); 0118 0119 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0120 0121 QCOMPARE(results.size(), 1); 0122 Tellico::Data::EntryPtr entry = results.at(0); 0123 0124 QCOMPARE(entry->field("title"), QString::fromUtf8("Jérusalem d'Afrique")); 0125 QCOMPARE(entry->field("pub_year"), QStringLiteral("2006")); 0126 QCOMPARE(entry->field("series"), QStringLiteral("Chat du Rabbin (Le)")); 0127 QCOMPARE(entry->field("writer"), QStringLiteral("Sfar, Joann")); 0128 QCOMPARE(entry->field("artist"), QStringLiteral("Sfar, Joann")); 0129 QCOMPARE(entry->field("colorist"), QStringLiteral("Findakly, Brigitte")); 0130 QCOMPARE(entry->field("publisher"), QStringLiteral("Dargaud")); 0131 QCOMPARE(entry->field("pages"), QStringLiteral("80")); 0132 QCOMPARE(entry->field("issue"), QStringLiteral("5")); 0133 QCOMPARE(entry->field("edition"), QStringLiteral("Poisson Pilote")); 0134 QCOMPARE(entry->field("genre"), QStringLiteral("Aventure")); 0135 QCOMPARE(entry->field("isbn"), QStringLiteral("2-205-05868-1")); 0136 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-Chat-du-Rabbin-Tome-5-Jerusalem-d-Afrique-59668.html")); 0137 QVERIFY(!entry->field("comments").isEmpty()); 0138 QVERIFY(!entry->field("cover").isEmpty()); 0139 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0140 } 0141 0142 void BedethequeFetcherTest::testDonjon() { 0143 // this one has multiple writers 0144 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Raw, 0145 QStringLiteral("http://m.bedetheque.com/BD-Donjon-Zenith-Tome-5-Un-mariage-a-part-56495.html")); 0146 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0147 fetcher->readConfig(m_config); 0148 0149 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0150 0151 QCOMPARE(results.size(), 1); 0152 Tellico::Data::EntryPtr entry = results.at(0); 0153 0154 QCOMPARE(entry->field("title"), QString::fromUtf8("Un mariage à part")); 0155 QCOMPARE(set(entry, "writer"), set("Sfar, Joann; Boulet; Trondheim, Lewis")); 0156 QCOMPARE(entry->field("artist"), QStringLiteral("Boulet")); 0157 QCOMPARE(entry->field("colorist"), QStringLiteral("Albon, Lucie")); 0158 QCOMPARE(entry->field("isbn"), QStringLiteral("2-84055-734-7")); 0159 QCOMPARE(entry->field("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-Donjon-Zenith-Tome-5-Un-mariage-a-part-56495.html")); 0160 QVERIFY(!entry->field("cover").isEmpty()); 0161 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0162 } 0163 0164 void BedethequeFetcherTest::testUpdate() { 0165 Tellico::Data::CollPtr coll(new Tellico::Data::ComicBookCollection(true)); 0166 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("lien-bel"), 0167 QLatin1String("Link"), 0168 Tellico::Data::Field::URL)); 0169 coll->addField(field); 0170 Tellico::Data::EntryPtr oldEntry(new Tellico::Data::Entry(coll)); 0171 coll->addEntries(oldEntry); 0172 0173 oldEntry->setField(QStringLiteral("lien-bel"), QStringLiteral("https://www.bedetheque.com/BD-Donjon-Zenith-Tome-5-Un-mariage-a-part-56495.html")); 0174 0175 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::BedethequeFetcher(this)); 0176 auto f = static_cast<Tellico::Fetch::BedethequeFetcher*>(fetcher.data()); 0177 0178 auto request = f->updateRequest(oldEntry); 0179 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0180 }