File indexing completed on 2024-05-12 05:09:59
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 "filmaffinityfetchertest.h" 0028 0029 #include "../fetch/filmaffinityfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/videocollection.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( FilmAffinityFetcherTest ) 0042 0043 FilmAffinityFetcherTest::FilmAffinityFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void FilmAffinityFetcherTest::initTestCase() { 0047 Tellico::ImageFactory::init(); 0048 Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video"); 0049 0050 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("filmaffinity")); 0051 m_config.writeEntry("Custom Fields", QStringLiteral("origtitle,filmaffinity")); 0052 } 0053 0054 void FilmAffinityFetcherTest::testSuperman() { 0055 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Superman Returns")); 0056 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmAffinityFetcher(this)); 0057 m_config.writeEntry("Locale", int(Tellico::Fetch::FilmAffinityFetcher::US)); 0058 fetcher->readConfig(m_config); 0059 0060 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0061 0062 QCOMPARE(results.size(), 1); 0063 0064 // the first entry had better be the right one 0065 Tellico::Data::EntryPtr entry = results.at(0); 0066 0067 QCOMPARE(entry->field("title"), QStringLiteral("Superman Returns")); 0068 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0069 QCOMPARE(entry->field("nationality"), QStringLiteral("United States")); 0070 QCOMPARE(entry->field("director"), QStringLiteral("Bryan Singer")); 0071 QCOMPARE(set(entry->field("writer")), set(QStringLiteral("Bryan Singer; Michael Dougherty; Dan Harris"))); 0072 QCOMPARE(entry->field("composer"), QStringLiteral("John Ottman")); 0073 QCOMPARE(entry->field("studio"), QStringLiteral("Warner Bros.")); 0074 QCOMPARE(set(entry, "genre"), set(QStringLiteral("Sci-Fi; Fantasy; Action; Romance"))); 0075 QCOMPARE(entry->field("running-time"), QStringLiteral("153")); 0076 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0077 QVERIFY(castList.count() > 2); 0078 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh")); 0079 QCOMPARE(castList.at(1), QStringLiteral("Kevin Spacey")); 0080 QVERIFY(entry->field("plot").startsWith(QStringLiteral("Following a mysterious absence"))); 0081 QVERIFY(!entry->field("cover").isEmpty()); 0082 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0083 QCOMPARE(entry->field("filmaffinity"), QStringLiteral("https://www.filmaffinity.com/us/film300630.html")); 0084 } 0085 0086 0087 void FilmAffinityFetcherTest::testSupermanES() { 0088 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Superman Returns")); 0089 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmAffinityFetcher(this)); 0090 m_config.writeEntry("Locale", int(Tellico::Fetch::FilmAffinityFetcher::ES)); 0091 fetcher->readConfig(m_config); 0092 0093 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0094 0095 QCOMPARE(results.size(), 1); 0096 0097 // the first entry had better be the right one 0098 Tellico::Data::EntryPtr entry = results.at(0); 0099 0100 QCOMPARE(entry->field("title"), QStringLiteral("Superman Returns: El regreso")); 0101 QCOMPARE(entry->field("origtitle"), QStringLiteral("Superman Returns")); 0102 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0103 QCOMPARE(entry->field("nationality"), QStringLiteral("Estados Unidos")); 0104 QCOMPARE(entry->field("director"), QStringLiteral("Bryan Singer")); 0105 QCOMPARE(set(entry->field("writer")), set(QStringLiteral("Bryan Singer; Michael Dougherty; Dan Harris"))); 0106 QCOMPARE(entry->field("composer"), QStringLiteral("John Ottman")); 0107 QCOMPARE(entry->field("studio"), QStringLiteral("Warner Bros.")); 0108 QCOMPARE(set(entry, "genre"), set(QString::fromUtf8("Ciencia ficción; Fantástico; Acción; Romance"))); 0109 QCOMPARE(entry->field("running-time"), QStringLiteral("153")); 0110 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0111 QVERIFY(castList.count() > 2); 0112 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh")); 0113 QCOMPARE(castList.at(1), QStringLiteral("Kevin Spacey")); 0114 QVERIFY(entry->field("plot").startsWith(QString::fromUtf8("Tras varios años"))); 0115 QVERIFY(!entry->field("cover").isEmpty()); 0116 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0117 QCOMPARE(entry->field("filmaffinity"), QStringLiteral("https://www.filmaffinity.com/es/film300630.html")); 0118 } 0119 0120 void FilmAffinityFetcherTest::testFirefly() { 0121 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Firefly 2002")); 0122 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmAffinityFetcher(this)); 0123 m_config.writeEntry("Locale", int(Tellico::Fetch::FilmAffinityFetcher::US)); 0124 fetcher->readConfig(m_config); 0125 0126 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0127 0128 QCOMPARE(results.size(), 1); 0129 0130 // the first entry had better be the right one 0131 Tellico::Data::EntryPtr entry = results.at(0); 0132 0133 QCOMPARE(entry->field("title"), QStringLiteral("Firefly")); 0134 QCOMPARE(entry->field("year"), QStringLiteral("2002")); 0135 QCOMPARE(entry->field("nationality"), QStringLiteral("United States")); 0136 QCOMPARE(entry->field("studio"), QStringLiteral("FOX")); 0137 QVERIFY(!entry->field("plot").isEmpty()); 0138 QVERIFY(!entry->field("cover").isEmpty()); 0139 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0140 QCOMPARE(entry->field("filmaffinity"), QStringLiteral("https://www.filmaffinity.com/us/film929343.html")); 0141 } 0142 0143 void FilmAffinityFetcherTest::testAlcarras() { 0144 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QString::fromUtf8("Alcarràs")); 0145 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmAffinityFetcher(this)); 0146 m_config.writeEntry("Locale", int(Tellico::Fetch::FilmAffinityFetcher::ES)); 0147 fetcher->readConfig(m_config); 0148 0149 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0150 0151 QCOMPARE(results.size(), 1); 0152 0153 // the first entry had better be the right one 0154 Tellico::Data::EntryPtr entry = results.at(0); 0155 0156 QCOMPARE(entry->field("title"), QString::fromUtf8("Alcarràs")); 0157 QCOMPARE(entry->field("year"), QStringLiteral("2022")); 0158 QCOMPARE(entry->field("nationality"), QString::fromUtf8("España")); 0159 QCOMPARE(entry->field("director"), QString::fromUtf8("Carla Simón")); 0160 QCOMPARE(entry->field("writer"), QString::fromUtf8("Carla Simón; Arnau Vilaró")); 0161 QCOMPARE(entry->field("composer"), QStringLiteral("Andrea Koch")); 0162 QCOMPARE(entry->field("studio"), QString::fromUtf8("Avalon P.C; Elastica Films; Vilaüt Films; Kino Produzioni; Movistar Plus+; RTVE; TV3")); 0163 QCOMPARE(set(entry, "genre"), set(QStringLiteral("Drama"))); 0164 QCOMPARE(entry->field("running-time"), QStringLiteral("120")); 0165 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0166 QVERIFY(castList.count() > 2); 0167 QCOMPARE(castList.at(0), QStringLiteral("Jordi Pujol Dolcet")); 0168 QCOMPARE(castList.at(1), QStringLiteral("Anna Otín")); 0169 QVERIFY(entry->field("plot").startsWith(QStringLiteral("La familia Solé"))); 0170 QVERIFY(!entry->field("cover").isEmpty()); 0171 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0172 QCOMPARE(entry->field("filmaffinity"), QStringLiteral("https://www.filmaffinity.com/es/film457848.html")); 0173 }