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

0001 /***************************************************************************
0002     Copyright (C) 2017 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 "kinoteatrfetchertest.h"
0028 
0029 #include "../fetch/kinoteatrfetcher.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( KinoTeatrFetcherTest )
0041 
0042 KinoTeatrFetcherTest::KinoTeatrFetcherTest() : AbstractFetcherTest() {
0043 }
0044 
0045 void KinoTeatrFetcherTest::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("kinoteatr"));
0050   m_config.writeEntry("Custom Fields", QStringLiteral("origtitle,kinoteatr"));
0051 }
0052 
0053 void KinoTeatrFetcherTest::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::KinoTeatrFetcher(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   QCOMPARE(entry->field("nationality"), QString::fromUtf8("США"));
0070   QCOMPARE(entry->field("director"), QString::fromUtf8("Брайан Сінґер"));
0071   QCOMPARE(entry->field("writer"), QString::fromUtf8("Брайан Сінґер; Майкл Доґерті"));
0072   QCOMPARE(entry->field("producer"), QString::fromUtf8("Гілберт Адлер"));
0073   QCOMPARE(entry->field("composer"), QString::fromUtf8("Джон Оттмен"));
0074   QCOMPARE(set(entry, "genre"), set(QString::fromUtf8("бойовик; пригоди; фантастика; фентезі")));
0075   QCOMPARE(entry->field("running-time"), QStringLiteral("154"));
0076   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0077   QVERIFY(!castList.isEmpty());
0078   QCOMPARE(castList.at(0), QString::fromUtf8("Джеймс Марсден::Річард Вайт"));
0079   QVERIFY(entry->field("plot").startsWith(QString::fromUtf8("Легендарний супер-герой")));
0080   QVERIFY(!entry->field("cover").isEmpty());
0081   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0082   QCOMPARE(entry->field("kinoteatr"), QStringLiteral("https://kino-teatr.ua/uk/film/superman-returns-3475.phtml"));
0083 }