]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
Add more tests
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV1ControllerTest.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 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
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-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
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);
52 }
53
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
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
81 $data = [
82 'upload_import_file[file]' => $file,
83 ];
84
85 $client->submit($form, $data);
86
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
88
89 $crawler = $client->followRedirect();
90
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
106 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
107 $this->assertContains('flashes.import.notice.summary', $body[0]);
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());
114 }
115
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
126 $data = [
127 'upload_import_file[file]' => $file,
128 'upload_import_file[mark_as_read]' => 1,
129 ];
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
157 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
158 $this->assertContains('flashes.import.notice.summary', $body[0]);
159 }
160
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
171 $data = [
172 'upload_import_file[file]' => $file,
173 ];
174
175 $client->submit($form, $data);
176
177 $this->assertEquals(302, $client->getResponse()->getStatusCode());
178
179 $crawler = $client->followRedirect();
180
181 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
182 $this->assertContains('flashes.import.notice.failed', $body[0]);
183 }
184 }