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

0001 /***************************************************************************
0002     Copyright (C) 2017-2021 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 "kinopoiskfetchertest.h"
0028 
0029 #include "../fetch/kinopoiskfetcher.h"
0030 #include "../entry.h"
0031 #include "../collections/videocollection.h"
0032 #include "../collectionfactory.h"
0033 #include "../images/imagefactory.h"
0034 #include "../fieldformat.h"
0035 
0036 #include <KSharedConfig>
0037 
0038 #include <QTest>
0039 
0040 QTEST_GUILESS_MAIN( KinoPoiskFetcherTest )
0041 
0042 KinoPoiskFetcherTest::KinoPoiskFetcherTest() : AbstractFetcherTest() {
0043 }
0044 
0045 void KinoPoiskFetcherTest::initTestCase() {
0046   Tellico::ImageFactory::init();
0047   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0048 
0049   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("kinopoisk"));
0050   m_config.writeEntry("Custom Fields", QStringLiteral("origtitle,kinopoisk,imdb"));
0051 }
0052 
0053 void KinoPoiskFetcherTest::testSuperman() {
0054   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Superman Returns"));
0055   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::KinoPoiskFetcher(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"), QString::fromUtf8("Возвращение Супермена"));
0067   QCOMPARE(entry->field("origtitle"), QStringLiteral("Superman Returns"));
0068   QCOMPARE(entry->field("year"), QStringLiteral("2006"));
0069   QVERIFY(entry->field("nationality").contains(QString::fromUtf8("США"))); // USA
0070   QCOMPARE(entry->field("director"), QString::fromUtf8("Брайан Сингер"));
0071   QVERIFY(entry->field("writer").contains(QString::fromUtf8("Майкл Догерти")));
0072   QVERIFY(entry->field("writer").contains(QString::fromUtf8("Дэн Харрис")));
0073   QVERIFY(entry->field("producer").contains(QString::fromUtf8("Гилберт Адлер")));
0074   QCOMPARE(entry->field("composer"), QString::fromUtf8("Джон Оттмен"));
0075   QCOMPARE(set(entry->field("genre")), set(QString::fromUtf8("фантастика; боевик; приключения")));
0076   QCOMPARE(entry->field("certification"), QStringLiteral("PG-13 (USA)"));
0077   QCOMPARE(entry->field("running-time"), QStringLiteral("154"));
0078   QCOMPARE(entry->field("kinopoisk"), QStringLiteral("https://www.kinopoisk.ru/film/38472"));
0079   QCOMPARE(entry->field("imdb"), QStringLiteral("https://www.imdb.com/title/tt0348150"));
0080   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0081   QVERIFY(!castList.isEmpty());
0082   QVERIFY(castList.at(0).startsWith(QString::fromUtf8("Брэндон Рут")));
0083   QVERIFY(!entry->field("plot").isEmpty());
0084   QVERIFY(!entry->field("cover").isEmpty());
0085   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0086 }
0087 
0088 // Ликвидация is a TV series
0089 void KinoPoiskFetcherTest::testBug403185() {
0090   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Ликвидация"));
0091   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::KinoPoiskFetcher(this));
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"), QString::fromUtf8("Ликвидация"));
0101   QCOMPARE(entry->field("year"), QStringLiteral("2007"));
0102   QCOMPARE(entry->field("nationality"), QString::fromUtf8("Россия"));
0103   QCOMPARE(entry->field("director"), QString::fromUtf8("Сергей Урсуляк"));
0104   QVERIFY(entry->field("producer").startsWith(QString::fromUtf8("Сергей Даниелян; Рубен Дишдишян")));
0105   QCOMPARE(set(entry->field("genre")), set(QString::fromUtf8("детектив; криминал; триллер; драма")));
0106   QVERIFY(!entry->field("cast").isEmpty());
0107   QVERIFY(!entry->field("plot").isEmpty());
0108   QVERIFY(!entry->field("cover").isEmpty());
0109   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0110 }