]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
Enable Redis async import
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV2ControllerTest.php
1 <?php
2
3 namespace Tests\Wallabag\ImportBundle\Controller;
4
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8 class WallabagV2ControllerTest extends WallabagCoreTestCase
9 {
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v2');
16
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());
20 }
21
22 public function testImportWallabagWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
28
29 $crawler = $client->request('GET', '/import/wallabag-v2');
30
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());
34
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportWallabagWithRedisEnabled()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
44
45 $crawler = $client->request('GET', '/import/wallabag-v2');
46
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());
50
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
52 }
53
54 public function testImportWallabagWithFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v2');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
63
64 $data = [
65 'upload_import_file[file]' => $file,
66 ];
67
68 $client->submit($form, $data);
69
70 $this->assertEquals(302, $client->getResponse()->getStatusCode());
71
72 $crawler = $client->followRedirect();
73
74 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
75 $this->assertContains('flashes.import.notice.summary', $body[0]);
76
77 $content = $client->getContainer()
78 ->get('doctrine.orm.entity_manager')
79 ->getRepository('WallabagCoreBundle:Entry')
80 ->findByUrlAndUserId(
81 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
82 $this->getLoggedInUserId()
83 );
84
85 $this->assertEmpty($content->getMimetype());
86 $this->assertEmpty($content->getPreviewPicture());
87 $this->assertEmpty($content->getLanguage());
88 $this->assertEquals(0, count($content->getTags()));
89
90 $content = $client->getContainer()
91 ->get('doctrine.orm.entity_manager')
92 ->getRepository('WallabagCoreBundle:Entry')
93 ->findByUrlAndUserId(
94 'https://www.mediapart.fr/',
95 $this->getLoggedInUserId()
96 );
97
98 $this->assertNotEmpty($content->getMimetype());
99 $this->assertNotEmpty($content->getPreviewPicture());
100 $this->assertNotEmpty($content->getLanguage());
101 $this->assertEquals(2, count($content->getTags()));
102 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
103 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
104 }
105
106 public function testImportWallabagWithEmptyFile()
107 {
108 $this->logInAs('admin');
109 $client = $this->getClient();
110
111 $crawler = $client->request('GET', '/import/wallabag-v2');
112 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
113
114 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
115
116 $data = [
117 'upload_import_file[file]' => $file,
118 ];
119
120 $client->submit($form, $data);
121
122 $this->assertEquals(302, $client->getResponse()->getStatusCode());
123
124 $crawler = $client->followRedirect();
125
126 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
127 $this->assertContains('flashes.import.notice.failed', $body[0]);
128 }
129 }