]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
Change flash message for queued articles
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV1ControllerTest.php
CommitLineData
7019c7cf
JB
1<?php
2
23634d5d 3namespace Tests\Wallabag\ImportBundle\Controller;
7019c7cf 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
7019c7cf
JB
6use Symfony\Component\HttpFoundation\File\UploadedFile;
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
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
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
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
b3437d58
JB
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-v1');
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);
13470c35
JB
52 }
53
015c7a83
JB
54 public function testImportWallabagBadFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v1');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $data = [
63 'upload_import_file[file]' => '',
64 ];
65
66 $client->submit($form, $data);
67
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
69 }
70
7019c7cf
JB
71 public function testImportWallabagWithFile()
72 {
73 $this->logInAs('admin');
74 $client = $this->getClient();
75
76 $crawler = $client->request('GET', '/import/wallabag-v1');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
78
79 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
80
4094ea47 81 $data = [
7019c7cf 82 'upload_import_file[file]' => $file,
4094ea47 83 ];
7019c7cf
JB
84
85 $client->submit($form, $data);
86
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
88
89 $crawler = $client->followRedirect();
90
fca2b052
TC
91 $content = $client->getContainer()
92 ->get('doctrine.orm.entity_manager')
93 ->getRepository('WallabagCoreBundle:Entry')
94 ->findByUrlAndUserId(
95 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
96 $this->getLoggedInUserId()
97 );
98
99 $tag = $client->getContainer()
100 ->get('doctrine.orm.entity_manager')
101 ->getRepository('WallabagCoreBundle:Tag')
102 ->findOneByLabel('Framabag');
103
104 $this->assertTrue($content->getTags()->contains($tag));
105
4094ea47 106 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 107 $this->assertContains('flashes.import.notice.summary', $body[0]);
6d65c0a8
JB
108
109 $this->assertEmpty($content->getMimetype());
110 $this->assertEmpty($content->getPreviewPicture());
111 $this->assertEmpty($content->getLanguage());
112 $this->assertEquals(1, count($content->getTags()));
113 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
7019c7cf
JB
114 }
115
c32ae320
TC
116 public function testImportWallabagWithFileAndMarkAllAsRead()
117 {
118 $this->logInAs('admin');
119 $client = $this->getClient();
120
121 $crawler = $client->request('GET', '/import/wallabag-v1');
122 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
123
124 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
125
4094ea47 126 $data = [
c32ae320
TC
127 'upload_import_file[file]' => $file,
128 'upload_import_file[mark_as_read]' => 1,
4094ea47 129 ];
c32ae320
TC
130
131 $client->submit($form, $data);
132
133 $this->assertEquals(302, $client->getResponse()->getStatusCode());
134
135 $crawler = $client->followRedirect();
136
137 $content1 = $client->getContainer()
138 ->get('doctrine.orm.entity_manager')
139 ->getRepository('WallabagCoreBundle:Entry')
140 ->findByUrlAndUserId(
141 'http://gilbert.pellegrom.me/recreating-the-square-slider',
142 $this->getLoggedInUserId()
143 );
144
145 $this->assertTrue($content1->isArchived());
146
147 $content2 = $client->getContainer()
148 ->get('doctrine.orm.entity_manager')
149 ->getRepository('WallabagCoreBundle:Entry')
150 ->findByUrlAndUserId(
151 'https://www.wallabag.org/features/',
152 $this->getLoggedInUserId()
153 );
154
155 $this->assertTrue($content2->isArchived());
156
4094ea47 157 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 158 $this->assertContains('flashes.import.notice.summary', $body[0]);
c32ae320
TC
159 }
160
7019c7cf
JB
161 public function testImportWallabagWithEmptyFile()
162 {
163 $this->logInAs('admin');
164 $client = $this->getClient();
165
166 $crawler = $client->request('GET', '/import/wallabag-v1');
167 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
168
169 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
170
4094ea47 171 $data = [
7019c7cf 172 'upload_import_file[file]' => $file,
4094ea47 173 ];
7019c7cf
JB
174
175 $client->submit($form, $data);
176
177 $this->assertEquals(302, $client->getResponse()->getStatusCode());
178
179 $crawler = $client->followRedirect();
180
4094ea47 181 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 182 $this->assertContains('flashes.import.notice.failed', $body[0]);
7019c7cf
JB
183 }
184}