File indexing completed on 2024-05-12 05:09:57

0001 /***************************************************************************
0002     Copyright (C) 2010-2011 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 "dvdfrfetchertest.h"
0028 
0029 #include "../fetch/dvdfrfetcher.h"
0030 #include "../collections/videocollection.h"
0031 #include "../collectionfactory.h"
0032 #include "../entry.h"
0033 #include "../images/imagefactory.h"
0034 #include "../utils/datafileregistry.h"
0035 
0036 #include <KSharedConfig>
0037 #include <KConfigGroup>
0038 
0039 #include <QTest>
0040 
0041 QTEST_GUILESS_MAIN( DVDFrFetcherTest )
0042 
0043 DVDFrFetcherTest::DVDFrFetcherTest() : AbstractFetcherTest() {
0044 }
0045 
0046 void DVDFrFetcherTest::initTestCase() {
0047   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0048   // since we use the importer
0049   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/dvdfr2tellico.xsl"));
0050   Tellico::ImageFactory::init();
0051 
0052   m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Le Pacte des loups"));
0053   m_fieldValues.insert(QStringLiteral("studio"), QStringLiteral("StudioCanal"));
0054   m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2001"));
0055   m_fieldValues.insert(QStringLiteral("format"), QStringLiteral("PAL"));
0056   m_fieldValues.insert(QStringLiteral("aspect-ratio"), QStringLiteral("2.35"));
0057   m_fieldValues.insert(QStringLiteral("writer"), QStringLiteral("Stéphane Cabel; Christophe Gans"));
0058   m_fieldValues.insert(QStringLiteral("director"), QStringLiteral("Christophe Gans"));
0059   m_fieldValues.insert(QStringLiteral("genre"), QStringLiteral("Aventure; Fantastique"));
0060   m_fieldValues.insert(QStringLiteral("widescreen"), QStringLiteral("true"));
0061 }
0062 
0063 void DVDFrFetcherTest::testTitle() {
0064   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0065                                        QStringLiteral("Le Pacte des loups"));
0066   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DVDFrFetcher(this));
0067 
0068   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0069 
0070   QCOMPARE(results.size(), 1);
0071 
0072   Tellico::Data::EntryPtr entry = results.at(0);
0073   QHashIterator<QString, QString> i(m_fieldValues);
0074   while(i.hasNext()) {
0075     i.next();
0076     QString result = entry->field(i.key()).toLower();
0077     QCOMPARE(result, i.value().toLower());
0078   }
0079   QVERIFY(!entry->field(QStringLiteral("cast")).isEmpty());
0080   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0081   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0082   QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0083   QVERIFY(!entry->field(QStringLiteral("comments")).isEmpty());
0084 }
0085 
0086 void DVDFrFetcherTest::testTitleAccented() {
0087   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0088                                        QStringLiteral("La Communauté de l'Anneau"));
0089   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DVDFrFetcher(this));
0090 
0091   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0092 
0093   QCOMPARE(results.size(), 1);
0094 }
0095 
0096 void DVDFrFetcherTest::testUPC() {
0097   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("upcitemdb"));
0098   cg.writeEntry("Custom Fields", QStringLiteral("dvdfr,barcode"));
0099   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::UPC,
0100                                        QStringLiteral("3259119636120"));
0101   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DVDFrFetcher(this));
0102   fetcher->readConfig(cg);
0103 
0104   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0105 
0106   QCOMPARE(results.size(), 1);
0107 
0108   Tellico::Data::EntryPtr entry = results.at(0);
0109   QHashIterator<QString, QString> i(m_fieldValues);
0110   while(i.hasNext()) {
0111     i.next();
0112     QString result = entry->field(i.key()).toLower();
0113     QCOMPARE(result, i.value().toLower());
0114   }
0115   QCOMPARE(entry->field(QStringLiteral("dvdfr")), QStringLiteral("https://www.dvdfr.com/dvd/f4329-pacte-des-loups.html"));
0116   QCOMPARE(entry->field(QStringLiteral("barcode")), QStringLiteral("3259119636120"));
0117   QCOMPARE(entry->field(QStringLiteral("medium")), QStringLiteral("DVD"));
0118   QVERIFY(!entry->field(QStringLiteral("cast")).isEmpty());
0119   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0120   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0121   QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0122   QVERIFY(!entry->field(QStringLiteral("comments")).isEmpty());
0123 }