]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV1ControllerTest.php
CommitLineData
7019c7cf
JB
1<?php
2
23634d5d 3namespace Tests\Wallabag\ImportBundle\Controller;
7019c7cf 4
7019c7cf 5use Symfony\Component\HttpFoundation\File\UploadedFile;
f808b016 6use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
7019c7cf
JB
7
8class WallabagV1ControllerTest extends WallabagCoreTestCase
9{
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v1');
16
f808b016
JB
17 $this->assertSame(200, $client->getResponse()->getStatusCode());
18 $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertSame(1, $crawler->filter('input[type=file]')->count());
7019c7cf
JB
20 }
21
13470c35
JB
22 public function testImportWallabagWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
b3437d58 27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
13470c35
JB
28
29 $crawler = $client->request('GET', '/import/wallabag-v1');
30
f808b016
JB
31 $this->assertSame(200, $client->getResponse()->getStatusCode());
32 $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertSame(1, $crawler->filter('input[type=file]')->count());
13470c35 34
b3437d58
JB
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
47d7c682 38 public function testImportWallabagBadFile()
b3437d58
JB
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
b3437d58 43 $crawler = $client->request('GET', '/import/wallabag-v1');
47d7c682 44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
b3437d58 45
47d7c682
JB
46 $data = [
47 'upload_import_file[file]' => '',
48 ];
b3437d58 49
47d7c682
JB
50 $client->submit($form, $data);
51
f808b016 52 $this->assertSame(200, $client->getResponse()->getStatusCode());
13470c35
JB
53 }
54
47d7c682 55 public function testImportWallabagWithRedisEnabled()
015c7a83 56 {
0e0102b6 57 $this->checkRedis();
015c7a83
JB
58 $this->logInAs('admin');
59 $client = $this->getClient();
60
47d7c682
JB
61 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
62
015c7a83 63 $crawler = $client->request('GET', '/import/wallabag-v1');
47d7c682 64
f808b016
JB
65 $this->assertSame(200, $client->getResponse()->getStatusCode());
66 $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
67 $this->assertSame(1, $crawler->filter('input[type=file]')->count());
47d7c682 68
015c7a83
JB
69 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
70
f808b016 71 $file = new UploadedFile(__DIR__ . '/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
47d7c682 72
015c7a83 73 $data = [
47d7c682 74 'upload_import_file[file]' => $file,
015c7a83
JB
75 ];
76
77 $client->submit($form, $data);
78
f808b016 79 $this->assertSame(302, $client->getResponse()->getStatusCode());
47d7c682
JB
80
81 $crawler = $client->followRedirect();
82
83 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
84 $this->assertContains('flashes.import.notice.summary', $body[0]);
85
86 $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.wallabag_v1'));
87
88 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
015c7a83
JB
89 }
90
7019c7cf
JB
91 public function testImportWallabagWithFile()
92 {
93 $this->logInAs('admin');
94 $client = $this->getClient();
95
96 $crawler = $client->request('GET', '/import/wallabag-v1');
97 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
98
f808b016 99 $file = new UploadedFile(__DIR__ . '/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
7019c7cf 100
4094ea47 101 $data = [
7019c7cf 102 'upload_import_file[file]' => $file,
4094ea47 103 ];
7019c7cf
JB
104
105 $client->submit($form, $data);
106
f808b016 107 $this->assertSame(302, $client->getResponse()->getStatusCode());
7019c7cf
JB
108
109 $crawler = $client->followRedirect();
110
fca2b052
TC
111 $content = $client->getContainer()
112 ->get('doctrine.orm.entity_manager')
113 ->getRepository('WallabagCoreBundle:Entry')
114 ->findByUrlAndUserId(
e668a812 115 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
fca2b052
TC
116 $this->getLoggedInUserId()
117 );
118
4094ea47 119 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 120 $this->assertContains('flashes.import.notice.summary', $body[0]);
6d65c0a8 121
e668a812
JB
122 $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is empty');
123 $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is empty');
124 $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is empty');
bad7df8c
JB
125
126 $tags = $content->getTags();
127 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
128 $this->assertContains('Framabag', $tags, 'It includes the "Framabag" tag');
f808b016 129 $this->assertSame(2, count($tags));
bad7df8c 130
6d65c0a8 131 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
7019c7cf
JB
132 }
133
c32ae320
TC
134 public function testImportWallabagWithFileAndMarkAllAsRead()
135 {
136 $this->logInAs('admin');
137 $client = $this->getClient();
138
139 $crawler = $client->request('GET', '/import/wallabag-v1');
140 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
141
f808b016 142 $file = new UploadedFile(__DIR__ . '/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
c32ae320 143
4094ea47 144 $data = [
c32ae320
TC
145 'upload_import_file[file]' => $file,
146 'upload_import_file[mark_as_read]' => 1,
4094ea47 147 ];
c32ae320
TC
148
149 $client->submit($form, $data);
150
f808b016 151 $this->assertSame(302, $client->getResponse()->getStatusCode());
c32ae320
TC
152
153 $crawler = $client->followRedirect();
154
155 $content1 = $client->getContainer()
156 ->get('doctrine.orm.entity_manager')
157 ->getRepository('WallabagCoreBundle:Entry')
158 ->findByUrlAndUserId(
159 'http://gilbert.pellegrom.me/recreating-the-square-slider',
160 $this->getLoggedInUserId()
161 );
162
163 $this->assertTrue($content1->isArchived());
164
165 $content2 = $client->getContainer()
166 ->get('doctrine.orm.entity_manager')
167 ->getRepository('WallabagCoreBundle:Entry')
168 ->findByUrlAndUserId(
169 'https://www.wallabag.org/features/',
170 $this->getLoggedInUserId()
171 );
172
173 $this->assertTrue($content2->isArchived());
174
4094ea47 175 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 176 $this->assertContains('flashes.import.notice.summary', $body[0]);
c32ae320
TC
177 }
178
7019c7cf
JB
179 public function testImportWallabagWithEmptyFile()
180 {
181 $this->logInAs('admin');
182 $client = $this->getClient();
183
184 $crawler = $client->request('GET', '/import/wallabag-v1');
185 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
186
f808b016 187 $file = new UploadedFile(__DIR__ . '/../fixtures/test.txt', 'test.txt');
7019c7cf 188
4094ea47 189 $data = [
7019c7cf 190 'upload_import_file[file]' => $file,
4094ea47 191 ];
7019c7cf
JB
192
193 $client->submit($form, $data);
194
f808b016 195 $this->assertSame(302, $client->getResponse()->getStatusCode());
7019c7cf
JB
196
197 $crawler = $client->followRedirect();
198
4094ea47 199 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 200 $this->assertContains('flashes.import.notice.failed', $body[0]);
7019c7cf
JB
201 }
202}