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('import_with_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('import_with_rabbitmq', 0);
38 public function testImportWallabagWithRedisEnabled()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
45 $crawler = $client->request('GET', '/import/wallabag-v2');
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
49 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
54 public function testImportWallabagBadFile()
56 $this->logInAs('admin');
57 $client = $this->getClient();
59 $crawler = $client->request('GET', '/import/wallabag-v2');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
63 'upload_import_file[file]' => '',
66 $client->submit($form, $data);
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
71 public function testImportWallabagWithFile()
73 $this->logInAs('admin');
74 $client = $this->getClient();
76 $crawler = $client->request('GET', '/import/wallabag-v2');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
79 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
82 'upload_import_file[file]' => $file,
85 $client->submit($form, $data);
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
89 $crawler = $client->followRedirect();
91 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
92 $this->assertContains('flashes.import.notice.summary', $body[0]);
94 $content = $client->getContainer()
95 ->get('doctrine.orm.entity_manager')
96 ->getRepository('WallabagCoreBundle:Entry')
98 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
99 $this->getLoggedInUserId()
102 $this->assertNotEmpty($content->getMimetype());
103 $this->assertNotEmpty($content->getPreviewPicture());
104 $this->assertNotEmpty($content->getLanguage());
105 $this->assertEquals(0, count($content->getTags()));
107 $content = $client->getContainer()
108 ->get('doctrine.orm.entity_manager')
109 ->getRepository('WallabagCoreBundle:Entry')
110 ->findByUrlAndUserId(
111 'https://www.mediapart.fr/',
112 $this->getLoggedInUserId()
115 $this->assertNotEmpty($content->getMimetype());
116 $this->assertNotEmpty($content->getPreviewPicture());
117 $this->assertNotEmpty($content->getLanguage());
118 $this->assertEquals(2, count($content->getTags()));
119 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
120 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
123 public function testImportWallabagWithEmptyFile()
125 $this->logInAs('admin');
126 $client = $this->getClient();
128 $crawler = $client->request('GET', '/import/wallabag-v2');
129 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
131 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
134 'upload_import_file[file]' => $file,
137 $client->submit($form, $data);
139 $this->assertEquals(302, $client->getResponse()->getStatusCode());
141 $crawler = $client->followRedirect();
143 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
144 $this->assertContains('flashes.import.notice.failed', $body[0]);