mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
Merge branch '2.6' into master
This commit is contained in:
commit
8fd5a5273d
23 changed files with 749 additions and 14 deletions
|
@ -23,6 +23,6 @@ class ImportControllerTest extends WallabagTestCase
|
|||
|
||||
$crawler = $client->request('GET', '/import/');
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertSame(13, $crawler->filter('.card-title')->count());
|
||||
$this->assertSame(14, $crawler->filter('.card-title')->count());
|
||||
}
|
||||
}
|
||||
|
|
168
tests/Controller/Import/PocketCsvControllerTest.php
Normal file
168
tests/Controller/Import/PocketCsvControllerTest.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Predis\Client;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Tests\Wallabag\WallabagTestCase;
|
||||
use Wallabag\Entity\Entry;
|
||||
|
||||
class PocketCsvControllerTest extends WallabagTestCase
|
||||
{
|
||||
public function testImportPocketCsv()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertSame(1, $crawler->filter('input[type=file]')->count());
|
||||
}
|
||||
|
||||
public function testImportPocketCsvWithRabbitEnabled()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('import_with_rabbitmq', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertSame(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('import_with_rabbitmq', 0);
|
||||
}
|
||||
|
||||
public function testImportPocketCsvBadFile()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
$form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
|
||||
|
||||
$data = [
|
||||
'upload_import_file[file]' => '',
|
||||
];
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testImportPocketCsvWithRedisEnabled()
|
||||
{
|
||||
$this->checkRedis();
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
$client->getContainer()->get(Config::class)->set('import_with_redis', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertSame(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
|
||||
|
||||
$file = new UploadedFile(__DIR__ . '/../../fixtures/Import/pocket.csv', 'Bookmarks');
|
||||
|
||||
$data = [
|
||||
'upload_import_file[file]' => $file,
|
||||
];
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
|
||||
$this->assertStringContainsString('flashes.import.notice.summary', $body[0]);
|
||||
|
||||
$this->assertNotEmpty($client->getContainer()->get(Client::class)->lpop('wallabag.import.pocket_csv'));
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('import_with_redis', 0);
|
||||
}
|
||||
|
||||
public function testImportWallabagWithPocketCsvFile()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
$form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
|
||||
|
||||
$file = new UploadedFile(__DIR__ . '/../../fixtures/Import/pocket.csv', 'Bookmarks');
|
||||
|
||||
$data = [
|
||||
'upload_import_file[file]' => $file,
|
||||
];
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
|
||||
$this->assertStringContainsString('flashes.import.notice.summary', $body[0]);
|
||||
|
||||
$entries = $client->getContainer()
|
||||
->get(EntityManagerInterface::class)
|
||||
->getRepository(Entry::class)
|
||||
->findBy(['user' => $this->getLoggedInUserId()]);
|
||||
|
||||
$expectedEntries = [
|
||||
'http://youmightnotneedjquery.com/,1600322788',
|
||||
'https://jp-lambert.me/est-ce-que-jai-besoin-d-un-scrum-master-604f5a471c73',
|
||||
'https://www.monde-diplomatique.fr/2020/09/HALIMI/62165',
|
||||
'https://www.reddit.com/r/DataHoarder/comments/ioupbk/archivebox_question_how_do_i_import_links_from_a/',
|
||||
'https://www.numerama.com/politique/646826-tu-vas-pleurer-les-premieres-fois-que-se-passe-t-il-au-sein-du-studio-dubisoft-derriere-trackmania.html#utm_medium=distibuted&utm_source=rss&utm_campaign=646826',
|
||||
'https://www.nouvelobs.com/rue89/20200911.OBS33165/comment-konbini-s-est-fait-pieger-par-un-pere-masculiniste.html',
|
||||
'https://reporterre.net/Des-abeilles-pour-resoudre-les-conflits-entre-les-humains-et-les-elephants',
|
||||
];
|
||||
|
||||
$matchedEntries = array_map(function ($expectedUrl) use ($entries) {
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry->getUrl() === $expectedUrl) {
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}, $expectedEntries);
|
||||
|
||||
$this->assertCount(\count($expectedEntries), $matchedEntries, 'Should have 7 entries imported from pocket.csv');
|
||||
}
|
||||
|
||||
public function testImportWallabagWithEmptyFile()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket_csv');
|
||||
$form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
|
||||
|
||||
$file = new UploadedFile(__DIR__ . '/../../fixtures/Import/test.csv', 'test.csv');
|
||||
|
||||
$data = [
|
||||
'upload_import_file[file]' => $file,
|
||||
];
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
|
||||
$this->assertStringContainsString('flashes.import.notice.failed', $body[0]);
|
||||
}
|
||||
}
|
252
tests/Import/PocketCsvImportTest.php
Normal file
252
tests/Import/PocketCsvImportTest.php
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\Import;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use M6Web\Component\RedisMock\RedisMockFactory;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Predis\Client;
|
||||
use Simpleue\Queue\RedisQueue;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Wallabag\Entity\Entry;
|
||||
use Wallabag\Entity\User;
|
||||
use Wallabag\Helper\ContentProxy;
|
||||
use Wallabag\Helper\TagsAssigner;
|
||||
use Wallabag\Import\PocketCsvImport;
|
||||
use Wallabag\Redis\Producer;
|
||||
use Wallabag\Repository\EntryRepository;
|
||||
|
||||
class PocketCsvImportTest extends TestCase
|
||||
{
|
||||
protected $user;
|
||||
protected $em;
|
||||
protected $logHandler;
|
||||
protected $contentProxy;
|
||||
protected $tagsAssigner;
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport();
|
||||
|
||||
$this->assertSame('Pocket CSV', $pocketCsvImport->getName());
|
||||
$this->assertNotEmpty($pocketCsvImport->getUrl());
|
||||
$this->assertSame('import.pocket_csv.description', $pocketCsvImport->getDescription());
|
||||
}
|
||||
|
||||
public function testImport()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport(false, 7);
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/pocket.csv');
|
||||
|
||||
$entryRepo = $this->getMockBuilder(EntryRepository::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->exactly(7))
|
||||
->method('findByUrlAndUserId')
|
||||
->willReturn(false);
|
||||
|
||||
$this->em
|
||||
->expects($this->any())
|
||||
->method('getRepository')
|
||||
->willReturn($entryRepo);
|
||||
|
||||
$entry = $this->getMockBuilder(Entry::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->exactly(7))
|
||||
->method('updateEntry')
|
||||
->willReturn($entry);
|
||||
|
||||
$res = $pocketCsvImport->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertSame(['skipped' => 0, 'imported' => 7, 'queued' => 0], $pocketCsvImport->getSummary());
|
||||
}
|
||||
|
||||
public function testImportAndMarkAllAsRead()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport(false, 1);
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/pocket.csv');
|
||||
|
||||
$entryRepo = $this->getMockBuilder(EntryRepository::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->exactly(7))
|
||||
->method('findByUrlAndUserId')
|
||||
->will($this->onConsecutiveCalls(false, true));
|
||||
|
||||
$this->em
|
||||
->expects($this->any())
|
||||
->method('getRepository')
|
||||
->willReturn($entryRepo);
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->exactly(1))
|
||||
->method('updateEntry')
|
||||
->willReturn(new Entry($this->user));
|
||||
|
||||
// check that every entry persisted are archived
|
||||
$this->em
|
||||
->expects($this->any())
|
||||
->method('persist')
|
||||
->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
|
||||
|
||||
$res = $pocketCsvImport
|
||||
->setMarkAsRead(true)
|
||||
->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
|
||||
$this->assertSame(['skipped' => 6, 'imported' => 1, 'queued' => 0], $pocketCsvImport->getSummary());
|
||||
}
|
||||
|
||||
public function testImportWithRabbit()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport();
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/pocket.csv');
|
||||
|
||||
$entryRepo = $this->getMockBuilder(EntryRepository::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$entry = $this->getMockBuilder(Entry::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$producer = $this->getMockBuilder(\OldSound\RabbitMqBundle\RabbitMq\Producer::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$producer
|
||||
->expects($this->exactly(7))
|
||||
->method('publish');
|
||||
|
||||
$pocketCsvImport->setProducer($producer);
|
||||
|
||||
$res = $pocketCsvImport->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 7], $pocketCsvImport->getSummary());
|
||||
}
|
||||
|
||||
public function testImportWithRedis()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport();
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/pocket.csv');
|
||||
|
||||
$entryRepo = $this->getMockBuilder(EntryRepository::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$entry = $this->getMockBuilder(Entry::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$factory = new RedisMockFactory();
|
||||
$redisMock = $factory->getAdapter(Client::class, true);
|
||||
|
||||
$queue = new RedisQueue($redisMock, 'pocket_csv');
|
||||
$producer = new Producer($queue);
|
||||
|
||||
$pocketCsvImport->setProducer($producer);
|
||||
|
||||
$res = $pocketCsvImport->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 7], $pocketCsvImport->getSummary());
|
||||
|
||||
$this->assertNotEmpty($redisMock->lpop('pocket_csv'));
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport();
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/wallabag-v1.jsonx');
|
||||
|
||||
$res = $pocketCsvImport->import();
|
||||
|
||||
$this->assertFalse($res);
|
||||
|
||||
$records = $this->logHandler->getRecords();
|
||||
$this->assertStringContainsString('Pocket CSV Import: unable to read file', $records[0]['message']);
|
||||
$this->assertSame('ERROR', $records[0]['level_name']);
|
||||
}
|
||||
|
||||
public function testImportUserNotDefined()
|
||||
{
|
||||
$pocketCsvImport = $this->getPocketCsvImport(true);
|
||||
$pocketCsvImport->setFilepath(__DIR__ . '/../fixtures/Import/pocket.csv');
|
||||
|
||||
$res = $pocketCsvImport->import();
|
||||
|
||||
$this->assertFalse($res);
|
||||
|
||||
$records = $this->logHandler->getRecords();
|
||||
$this->assertStringContainsString('Pocket CSV Import: user is not defined', $records[0]['message']);
|
||||
$this->assertSame('ERROR', $records[0]['level_name']);
|
||||
}
|
||||
|
||||
private function getPocketCsvImport($unsetUser = false, $dispatched = 0)
|
||||
{
|
||||
$this->user = new User();
|
||||
|
||||
$this->em = $this->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy = $this->getMockBuilder(ContentProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->tagsAssigner = $this->getMockBuilder(TagsAssigner::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dispatcher = $this->getMockBuilder(EventDispatcher::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dispatcher
|
||||
->expects($this->exactly($dispatched))
|
||||
->method('dispatch');
|
||||
|
||||
$this->logHandler = new TestHandler();
|
||||
$logger = new Logger('test', [$this->logHandler]);
|
||||
|
||||
$wallabag = new PocketCsvImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
|
||||
|
||||
if (false === $unsetUser) {
|
||||
$wallabag->setUser($this->user);
|
||||
}
|
||||
|
||||
return $wallabag;
|
||||
}
|
||||
}
|
10
tests/fixtures/Import/pocket.csv
vendored
Normal file
10
tests/fixtures/Import/pocket.csv
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
title,url,time_added,tags,status
|
||||
You Might Not Need jQuery,http://youmightnotneedjquery.com/,1600322788,,unread
|
||||
Est-ce que j’ai besoin d’un Scrum Master ? | by Jean-Pierre Lambert | Jean-,https://jp-lambert.me/est-ce-que-jai-besoin-d-un-scrum-master-604f5a471c73,1600172739,,unread
|
||||
"Avec les accusés d’El Halia, par Gisèle Halimi (Le Monde diplomatique, sept",https://www.monde-diplomatique.fr/2020/09/HALIMI/62165,1599806347,,unread
|
||||
ArchiveBox question: How do I import links from a RSS feed?,https://www.reddit.com/r/DataHoarder/comments/ioupbk/archivebox_question_how_do_i_import_links_from_a/,1600961496,,archive
|
||||
« Tu vas pleurer les premières fois » : que se passe-t-il au sein du studio,https://www.numerama.com/politique/646826-tu-vas-pleurer-les-premieres-fois-que-se-passe-t-il-au-sein-du-studio-dubisoft-derriere-trackmania.html#utm_medium=distibuted&utm_source=rss&utm_campaign=646826,1599809025,,unread
|
||||
Comment Konbini s’est fait piéger par un « père masculiniste »,https://www.nouvelobs.com/rue89/20200911.OBS33165/comment-konbini-s-est-fait-pieger-par-un-pere-masculiniste.html,1599819251,,archive
|
||||
"Des abeilles pour résoudre les « conflits » entre les humains
|
||||
|
||||
et les élépha",https://reporterre.net/Des-abeilles-pour-resoudre-les-conflits-entre-les-humains-et-les-elephants,1599890673,,unread
|
|
2
tests/fixtures/Import/ril_export.html
vendored
2
tests/fixtures/Import/ril_export.html
vendored
|
@ -9,7 +9,7 @@
|
|||
<h1>Unread</h1>
|
||||
<ul>
|
||||
<li><a href="https://www.20minutes.fr/sport/4002755-20220928-tarn-lapins-ravagent-terrain-match-rugby-doit-etre-annule" time_added="1688628695" tags="ifttt,new_entry_simple">Tarn : Des lapins ravagent le terrain, le match de rugby doit être annulé</a></li>
|
||||
<li><a href="https://www.20minutes.fr/paris/4100740-20240715-jo-paris-2024-courir-capitale-maintenant-quais-fermes" time_added="1688627412" tags="ifttt,new_entry_simple">JO Paris 2024 : Où courir dans la capitale maintenant que les quais sont fermés ?</a></li>
|
||||
<li><a href="https://www.20minutes.fr/paris/4100740-20240715-jo-paris-2024-courir-capitale-maintenant-quais-fermes" time_added="1688627412" tags="ifttt,new_entry_simple">JO Paris 2024 : Où courir dans la capitale maintenant que les quais sont fermés ?</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
|
2
tests/fixtures/Import/shaarli-bookmarks.html
vendored
2
tests/fixtures/Import/shaarli-bookmarks.html
vendored
|
@ -8,6 +8,6 @@
|
|||
<DL><p>
|
||||
<DT><A HREF="https://www.20minutes.fr/sport/4002755-20220928-tarn-lapins-ravagent-terrain-match-rugby-doit-etre-annule" ADD_DATE="1686813518" LAST_MODIFIED="1686813519" PRIVATE="0" TAGS="firefoxos">The Legacy of Firefox OS. In the two years or so since Mozilla… | by Ben Francis | Medium</A>
|
||||
<DD>In the two years or so since Mozilla announced the end of Firefox OS as a Mozilla-run project, the B2G source code has found its way into a surprising number of commercial products.
|
||||
<DT><A HREF="https://www.20minutes.fr/paris/4100740-20240715-jo-paris-2024-courir-capitale-maintenant-quais-fermes" ADD_DATE="1683376565" LAST_MODIFIED="1683376571" PRIVATE="0" TAGS="eleventy,this,javascript,filter,data">Template Filters — Eleventy</A>
|
||||
<DT><A HREF="https://www.20minutes.fr/paris/4100740-20240715-jo-paris-2024-courir-capitale-maintenant-quais-fermes" ADD_DATE="1683376565" LAST_MODIFIED="1686813519" PRIVATE="0" TAGS="firefoxos">JO Paris 2024 : Où courir dans la capitale maintenant que les quais sont fermés ?</A>
|
||||
</DL><p>
|
||||
<script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>
|
||||
|
|
0
tests/fixtures/Import/test.csv
vendored
Normal file
0
tests/fixtures/Import/test.csv
vendored
Normal file
|
Loading…
Add table
Add a link
Reference in a new issue