3 namespace Tests\Wallabag\ImportBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class WallabagV2ControllerTest
extends WallabagCoreTestCase
10 public function testImportWallabag()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/wallabag-v2');
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
22 public function testImportWallabagWithRabbitEnabled()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $client->getContainer()->get('craue_config')->set('rabbitmq', 1);
29 $crawler = $client->request('GET', '/import/wallabag-v2');
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
35 $client->getContainer()->get('craue_config')->set('rabbitmq', 0);
38 public function testImportWallabagWithFile()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $crawler = $client->request('GET', '/import/wallabag-v2');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
46 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
49 'upload_import_file[file]' => $file,
52 $client->submit($form, $data);
54 $this->assertEquals(302, $client->getResponse()->getStatusCode());
56 $crawler = $client->followRedirect();
58 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
59 $this->assertContains('flashes.import.notice.summary', $body[0]);
61 $content = $client->getContainer()
62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry')
65 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
66 $this->getLoggedInUserId()
69 $this->assertEmpty($content->getMimetype());
70 $this->assertEmpty($content->getPreviewPicture());
71 $this->assertEmpty($content->getLanguage());
72 $this->assertEquals(0, count($content->getTags()));
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
78 'https://www.mediapart.fr/',
79 $this->getLoggedInUserId()
82 $this->assertNotEmpty($content->getMimetype());
83 $this->assertNotEmpty($content->getPreviewPicture());
84 $this->assertNotEmpty($content->getLanguage());
85 $this->assertEquals(2, count($content->getTags()));
86 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
87 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
90 public function testImportWallabagWithEmptyFile()
92 $this->logInAs('admin');
93 $client = $this->getClient();
95 $crawler = $client->request('GET', '/import/wallabag-v2');
96 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
98 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
101 'upload_import_file[file]' => $file,
104 $client->submit($form, $data);
106 $this->assertEquals(302, $client->getResponse()->getStatusCode());
108 $crawler = $client->followRedirect();
110 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
111 $this->assertContains('flashes.import.notice.failed', $body[0]);