]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
93fd4692 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
65cd8a4a | 6 | use Wallabag\CoreBundle\Entity\Config; |
2863bf2a | 7 | use Wallabag\CoreBundle\Entity\Entry; |
93fd4692 | 8 | |
769e19dc | 9 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 10 | { |
be085c3d | 11 | public $downloadImagesEnabled = false; |
02d17813 JB |
12 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
13 | ||
be085c3d JB |
14 | /** |
15 | * @after | |
16 | * | |
17 | * Ensure download_images_enabled is disabled after each script | |
18 | */ | |
19 | public function tearDownImagesEnabled() | |
20 | { | |
21 | if ($this->downloadImagesEnabled) { | |
22 | $client = static::createClient(); | |
23 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
24 | ||
25 | $this->downloadImagesEnabled = false; | |
26 | } | |
27 | } | |
28 | ||
3b815d2d J |
29 | public function testLogin() |
30 | { | |
31 | $client = $this->getClient(); | |
32 | ||
eb3bd7ef | 33 | $client->request('GET', '/new'); |
3b815d2d J |
34 | |
35 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
36 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
37 | } | |
38 | ||
5c072d2b NL |
39 | public function testQuickstart() |
40 | { | |
41 | $this->logInAs('empty'); | |
42 | $client = $this->getClient(); | |
43 | ||
44 | $client->request('GET', '/unread/list'); | |
4f9cf232 | 45 | $crawler = $client->followRedirect(); |
5c072d2b NL |
46 | |
47 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 48 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
24ad330b | 49 | $this->assertContains('quickstart.intro.title', $body[0]); |
5c072d2b NL |
50 | |
51 | // Test if quickstart is disabled when user has 1 entry | |
52 | $crawler = $client->request('GET', '/new'); | |
53 | ||
54 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
55 | ||
0d42217e | 56 | $form = $crawler->filter('form[name=entry]')->form(); |
5c072d2b | 57 | |
4094ea47 | 58 | $data = [ |
78833672 | 59 | 'entry[url]' => $this->url, |
4094ea47 | 60 | ]; |
5c072d2b NL |
61 | |
62 | $client->submit($form, $data); | |
63 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
64 | $client->followRedirect(); | |
65 | ||
4f9cf232 | 66 | $crawler = $client->request('GET', '/unread/list'); |
4094ea47 | 67 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 68 | $this->assertContains('entry.list.number_on_the_page', $body[0]); |
5c072d2b NL |
69 | } |
70 | ||
9c0c8820 | 71 | public function testGetNew() |
93fd4692 | 72 | { |
eb3bd7ef | 73 | $this->logInAs('admin'); |
7ab5eb95 | 74 | $this->useTheme('baggy'); |
3b815d2d | 75 | $client = $this->getClient(); |
93fd4692 | 76 | |
aa6e27cf | 77 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
78 | |
79 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
80 | |
81 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
0d42217e | 82 | $this->assertCount(1, $crawler->filter('form[name=entry]')); |
9c0c8820 J |
83 | } |
84 | ||
880a0e1c NL |
85 | public function testPostNewViaBookmarklet() |
86 | { | |
87 | $this->logInAs('admin'); | |
7ab5eb95 | 88 | $this->useTheme('baggy'); |
880a0e1c NL |
89 | $client = $this->getClient(); |
90 | ||
91 | $crawler = $client->request('GET', '/'); | |
92 | ||
93 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
94 | ||
95 | // Good URL | |
4094ea47 | 96 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); |
880a0e1c | 97 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
5c072d2b | 98 | $client->followRedirect(); |
880a0e1c NL |
99 | $crawler = $client->request('GET', '/'); |
100 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
101 | ||
102 | $em = $client->getContainer() | |
103 | ->get('doctrine.orm.entity_manager'); | |
104 | $entry = $em | |
105 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 106 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
880a0e1c NL |
107 | $em->remove($entry); |
108 | $em->flush(); | |
109 | } | |
110 | ||
9c0c8820 J |
111 | public function testPostNewEmpty() |
112 | { | |
eb3bd7ef | 113 | $this->logInAs('admin'); |
3b815d2d | 114 | $client = $this->getClient(); |
9c0c8820 J |
115 | |
116 | $crawler = $client->request('GET', '/new'); | |
117 | ||
118 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
119 | ||
0d42217e | 120 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 J |
121 | |
122 | $crawler = $client->submit($form); | |
123 | ||
124 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 125 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); |
9c0c8820 J |
126 | $this->assertEquals('This value should not be blank.', $alert[0]); |
127 | } | |
128 | ||
8a493541 | 129 | /** |
75c48e3a | 130 | * This test will require an internet connection. |
8a493541 | 131 | */ |
9c0c8820 J |
132 | public function testPostNewOk() |
133 | { | |
eb3bd7ef | 134 | $this->logInAs('admin'); |
3b815d2d | 135 | $client = $this->getClient(); |
9c0c8820 J |
136 | |
137 | $crawler = $client->request('GET', '/new'); | |
138 | ||
139 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
140 | ||
0d42217e | 141 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 | 142 | |
4094ea47 | 143 | $data = [ |
02d17813 | 144 | 'entry[url]' => $this->url, |
4094ea47 | 145 | ]; |
9c0c8820 J |
146 | |
147 | $client->submit($form, $data); | |
148 | ||
149 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
150 | ||
a0d6ccc5 JB |
151 | $content = $client->getContainer() |
152 | ->get('doctrine.orm.entity_manager') | |
153 | ->getRepository('WallabagCoreBundle:Entry') | |
154 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
155 | ||
7b0b3622 NL |
156 | $author = $content->getPublishedBy(); |
157 | ||
a0d6ccc5 JB |
158 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
159 | $this->assertEquals($this->url, $content->getUrl()); | |
160 | $this->assertContains('Google', $content->getTitle()); | |
42f3bb2c | 161 | $this->assertEquals('fr', $content->getLanguage()); |
7b0b3622 NL |
162 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); |
163 | $this->assertEquals('Morgane Tual', $author[0]); | |
dda6a6ad | 164 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); |
a0d6ccc5 | 165 | } |
9c0c8820 | 166 | |
e9c80c99 NL |
167 | public function testPostWithMultipleAuthors() |
168 | { | |
169 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | |
170 | $this->logInAs('admin'); | |
171 | $client = $this->getClient(); | |
172 | ||
173 | $crawler = $client->request('GET', '/new'); | |
174 | ||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
176 | ||
177 | $form = $crawler->filter('form[name=entry]')->form(); | |
178 | ||
179 | $data = [ | |
180 | 'entry[url]' => $url, | |
181 | ]; | |
182 | ||
183 | $client->submit($form, $data); | |
184 | ||
185 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
186 | ||
187 | $content = $client->getContainer() | |
188 | ->get('doctrine.orm.entity_manager') | |
189 | ->getRepository('WallabagCoreBundle:Entry') | |
190 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
191 | ||
192 | $authors = $content->getPublishedBy(); | |
193 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | |
42f3bb2c | 194 | $this->assertEquals('fr', $content->getLanguage()); |
e9c80c99 NL |
195 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); |
196 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | |
197 | } | |
198 | ||
a0d6ccc5 JB |
199 | public function testPostNewOkUrlExist() |
200 | { | |
201 | $this->logInAs('admin'); | |
7ab5eb95 | 202 | |
203 | $entry = new Entry($this->getLoggedInUser()); | |
204 | $entry->setUrl($this->url); | |
205 | $this->getEntityManager()->persist($entry); | |
206 | $this->getEntityManager()->flush(); | |
207 | ||
a0d6ccc5 JB |
208 | $client = $this->getClient(); |
209 | ||
210 | $crawler = $client->request('GET', '/new'); | |
211 | ||
212 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
213 | ||
0d42217e | 214 | $form = $crawler->filter('form[name=entry]')->form(); |
a0d6ccc5 | 215 | |
4094ea47 | 216 | $data = [ |
a0d6ccc5 | 217 | 'entry[url]' => $this->url, |
4094ea47 | 218 | ]; |
a0d6ccc5 JB |
219 | |
220 | $client->submit($form, $data); | |
221 | ||
222 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
223 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
9c0c8820 J |
224 | } |
225 | ||
19ca0b2f JB |
226 | public function testPostNewOkUrlExistWithAccent() |
227 | { | |
228 | $this->logInAs('admin'); | |
229 | $client = $this->getClient(); | |
230 | ||
231 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
232 | ||
233 | $crawler = $client->request('GET', '/new'); | |
234 | ||
235 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
236 | ||
237 | $form = $crawler->filter('form[name=entry]')->form(); | |
238 | ||
239 | $data = [ | |
240 | 'entry[url]' => $url, | |
241 | ]; | |
242 | ||
243 | $client->submit($form, $data); | |
244 | ||
245 | $crawler = $client->request('GET', '/new'); | |
246 | ||
247 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
248 | ||
249 | $form = $crawler->filter('form[name=entry]')->form(); | |
250 | ||
251 | $data = [ | |
252 | 'entry[url]' => $url, | |
253 | ]; | |
a0d6ccc5 JB |
254 | |
255 | $client->submit($form, $data); | |
256 | ||
257 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
258 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
9c0c8820 J |
259 | } |
260 | ||
958671a7 KG |
261 | /** |
262 | * This test will require an internet connection. | |
263 | */ | |
3be04745 | 264 | public function testPostNewThatWillBeTagged() |
958671a7 KG |
265 | { |
266 | $this->logInAs('admin'); | |
267 | $client = $this->getClient(); | |
268 | ||
269 | $crawler = $client->request('GET', '/new'); | |
270 | ||
271 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
272 | ||
0d42217e | 273 | $form = $crawler->filter('form[name=entry]')->form(); |
958671a7 | 274 | |
4094ea47 | 275 | $data = [ |
958671a7 | 276 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', |
4094ea47 | 277 | ]; |
958671a7 KG |
278 | |
279 | $client->submit($form, $data); | |
280 | ||
281 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
3be04745 | 282 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
958671a7 KG |
283 | |
284 | $em = $client->getContainer() | |
285 | ->get('doctrine.orm.entity_manager'); | |
286 | $entry = $em | |
287 | ->getRepository('WallabagCoreBundle:Entry') | |
288 | ->findOneByUrl($url); | |
69edb774 KG |
289 | $tags = $entry->getTags(); |
290 | ||
fdd725f5 | 291 | $this->assertCount(2, $tags); |
7ab5eb95 | 292 | $this->assertContains('wallabag', $tags); |
42f3bb2c | 293 | $this->assertEquals('en', $entry->getLanguage()); |
958671a7 KG |
294 | |
295 | $em->remove($entry); | |
296 | $em->flush(); | |
3be04745 JB |
297 | |
298 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
299 | // related https://github.com/wallabag/wallabag/issues/2121 | |
300 | $crawler = $client->request('GET', '/new'); | |
301 | ||
302 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
303 | ||
304 | $form = $crawler->filter('form[name=entry]')->form(); | |
305 | ||
306 | $data = [ | |
307 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
308 | ]; | |
309 | ||
310 | $client->submit($form, $data); | |
311 | ||
312 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
313 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
314 | ||
315 | $entry = $em | |
316 | ->getRepository('WallabagCoreBundle:Entry') | |
317 | ->findOneByUrl($url); | |
318 | ||
319 | $tags = $entry->getTags(); | |
320 | ||
fdd725f5 | 321 | $this->assertCount(2, $tags); |
7ab5eb95 | 322 | $this->assertContains('wallabag', $tags); |
3be04745 JB |
323 | |
324 | $em->remove($entry); | |
325 | $em->flush(); | |
958671a7 KG |
326 | } |
327 | ||
9c0c8820 J |
328 | public function testArchive() |
329 | { | |
eb3bd7ef | 330 | $this->logInAs('admin'); |
3b815d2d | 331 | $client = $this->getClient(); |
9c0c8820 | 332 | |
9fb6ac83 | 333 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
334 | |
335 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
336 | } | |
337 | ||
d5d16121 NL |
338 | public function testUntagged() |
339 | { | |
340 | $this->logInAs('admin'); | |
341 | $client = $this->getClient(); | |
342 | ||
343 | $client->request('GET', '/untagged/list'); | |
344 | ||
345 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
346 | } | |
347 | ||
9c0c8820 J |
348 | public function testStarred() |
349 | { | |
eb3bd7ef | 350 | $this->logInAs('admin'); |
3b815d2d | 351 | $client = $this->getClient(); |
9c0c8820 | 352 | |
9fb6ac83 | 353 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
354 | |
355 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
356 | } | |
357 | ||
671a2b88 ML |
358 | public function testRangeException() |
359 | { | |
360 | $this->logInAs('admin'); | |
361 | $client = $this->getClient(); | |
362 | ||
363 | $client->request('GET', '/all/list/900'); | |
364 | ||
1880da74 NL |
365 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
366 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
671a2b88 ML |
367 | } |
368 | ||
9c0c8820 J |
369 | public function testView() |
370 | { | |
eb3bd7ef | 371 | $this->logInAs('admin'); |
3b815d2d | 372 | $client = $this->getClient(); |
9c0c8820 | 373 | |
7ab5eb95 | 374 | $entry = new Entry($this->getLoggedInUser()); |
375 | $entry->setUrl('http://example.com/foo'); | |
376 | $entry->setTitle('title foo'); | |
377 | $entry->setContent('foo bar baz'); | |
378 | $this->getEntityManager()->persist($entry); | |
379 | $this->getEntityManager()->flush(); | |
9c0c8820 | 380 | |
7ab5eb95 | 381 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
9c0c8820 J |
382 | |
383 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 384 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
7ab5eb95 | 385 | $this->assertContains($entry->getTitle(), $body[0]); |
93fd4692 | 386 | } |
eb3bd7ef | 387 | |
831b02aa | 388 | /** |
831b02aa JB |
389 | * This test will require an internet connection. |
390 | */ | |
391 | public function testReload() | |
392 | { | |
393 | $this->logInAs('admin'); | |
394 | $client = $this->getClient(); | |
395 | ||
7ab5eb95 | 396 | $entry = new Entry($this->getLoggedInUser()); |
397 | $entry->setUrl($this->url); | |
398 | $entry->setTitle('title foo'); | |
399 | $entry->setContent(''); | |
400 | $this->getEntityManager()->persist($entry); | |
401 | $this->getEntityManager()->flush(); | |
402 | $this->getEntityManager()->clear(); | |
ac8cf632 | 403 | |
7ab5eb95 | 404 | $client->request('GET', '/reload/'.$entry->getId()); |
831b02aa JB |
405 | |
406 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
407 | ||
7ab5eb95 | 408 | $entry = $this->getEntityManager() |
831b02aa | 409 | ->getRepository('WallabagCoreBundle:Entry') |
7ab5eb95 | 410 | ->find($entry->getId()); |
831b02aa | 411 | |
7ab5eb95 | 412 | $this->assertNotEmpty($entry->getContent()); |
831b02aa JB |
413 | } |
414 | ||
2297d60f JB |
415 | public function testReloadWithFetchingFailed() |
416 | { | |
417 | $this->logInAs('admin'); | |
418 | $client = $this->getClient(); | |
419 | ||
7ab5eb95 | 420 | $entry = new Entry($this->getLoggedInUser()); |
421 | $entry->setUrl('http://0.0.0.0/failed.html'); | |
422 | $this->getEntityManager()->persist($entry); | |
423 | $this->getEntityManager()->flush(); | |
2297d60f | 424 | |
7ab5eb95 | 425 | $client->request('GET', '/reload/'.$entry->getId()); |
2297d60f JB |
426 | |
427 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
428 | ||
429 | // force EntityManager to clear previous entity | |
430 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
7ab5eb95 | 431 | $this->getEntityManager()->clear(); |
432 | $newContent = $this->getEntityManager() | |
2297d60f | 433 | ->getRepository('WallabagCoreBundle:Entry') |
7ab5eb95 | 434 | ->find($entry->getId()); |
2297d60f JB |
435 | |
436 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | |
437 | } | |
438 | ||
82d6d9cb JB |
439 | public function testEdit() |
440 | { | |
441 | $this->logInAs('admin'); | |
442 | $client = $this->getClient(); | |
443 | ||
7ab5eb95 | 444 | $entry = new Entry($this->getLoggedInUser()); |
445 | $entry->setUrl($this->url); | |
446 | $this->getEntityManager()->persist($entry); | |
447 | $this->getEntityManager()->flush(); | |
82d6d9cb | 448 | |
7ab5eb95 | 449 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
82d6d9cb JB |
450 | |
451 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
452 | ||
453 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
454 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
455 | } | |
456 | ||
457 | public function testEditUpdate() | |
458 | { | |
459 | $this->logInAs('admin'); | |
460 | $client = $this->getClient(); | |
461 | ||
7ab5eb95 | 462 | $entry = new Entry($this->getLoggedInUser()); |
463 | $entry->setUrl($this->url); | |
464 | $this->getEntityManager()->persist($entry); | |
465 | $this->getEntityManager()->flush(); | |
82d6d9cb | 466 | |
7ab5eb95 | 467 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
82d6d9cb JB |
468 | |
469 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
470 | ||
471 | $form = $crawler->filter('button[type=submit]')->form(); | |
472 | ||
4094ea47 | 473 | $data = [ |
82d6d9cb | 474 | 'entry[title]' => 'My updated title hehe :)', |
4094ea47 | 475 | ]; |
82d6d9cb JB |
476 | |
477 | $client->submit($form, $data); | |
478 | ||
479 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
480 | ||
481 | $crawler = $client->followRedirect(); | |
482 | ||
4094ea47 | 483 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); |
82d6d9cb JB |
484 | $this->assertContains('My updated title hehe :)', $alert[0]); |
485 | } | |
486 | ||
eb3bd7ef J |
487 | public function testToggleArchive() |
488 | { | |
489 | $this->logInAs('admin'); | |
490 | $client = $this->getClient(); | |
491 | ||
7ab5eb95 | 492 | $entry = new Entry($this->getLoggedInUser()); |
493 | $entry->setUrl($this->url); | |
494 | $this->getEntityManager()->persist($entry); | |
495 | $this->getEntityManager()->flush(); | |
496 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 497 | |
7ab5eb95 | 498 | $client->request('GET', '/archive/'.$entry->getId()); |
eb3bd7ef J |
499 | |
500 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
501 | ||
502 | $res = $client->getContainer() | |
503 | ->get('doctrine.orm.entity_manager') | |
504 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 505 | ->find($entry->getId()); |
eb3bd7ef J |
506 | |
507 | $this->assertEquals($res->isArchived(), true); | |
508 | } | |
509 | ||
510 | public function testToggleStar() | |
511 | { | |
512 | $this->logInAs('admin'); | |
513 | $client = $this->getClient(); | |
514 | ||
7ab5eb95 | 515 | $entry = new Entry($this->getLoggedInUser()); |
516 | $entry->setUrl($this->url); | |
517 | $this->getEntityManager()->persist($entry); | |
518 | $this->getEntityManager()->flush(); | |
519 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 520 | |
7ab5eb95 | 521 | $client->request('GET', '/star/'.$entry->getId()); |
eb3bd7ef J |
522 | |
523 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
524 | ||
525 | $res = $client->getContainer() | |
526 | ->get('doctrine.orm.entity_manager') | |
527 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 528 | ->findOneById($entry->getId()); |
eb3bd7ef J |
529 | |
530 | $this->assertEquals($res->isStarred(), true); | |
531 | } | |
532 | ||
533 | public function testDelete() | |
534 | { | |
535 | $this->logInAs('admin'); | |
536 | $client = $this->getClient(); | |
537 | ||
7ab5eb95 | 538 | $entry = new Entry($this->getLoggedInUser()); |
539 | $entry->setUrl($this->url); | |
540 | $this->getEntityManager()->persist($entry); | |
541 | $this->getEntityManager()->flush(); | |
eb3bd7ef | 542 | |
7ab5eb95 | 543 | $client->request('GET', '/delete/'.$entry->getId()); |
eb3bd7ef J |
544 | |
545 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
546 | ||
7ab5eb95 | 547 | $client->request('GET', '/delete/'.$entry->getId()); |
eb3bd7ef | 548 | |
1d147791 | 549 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 550 | } |
3d2b2d62 | 551 | |
2863bf2a JB |
552 | /** |
553 | * It will create a new entry. | |
554 | * Browse to it. | |
555 | * Then remove it. | |
556 | * | |
557 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
558 | */ | |
559 | public function testViewAndDelete() | |
560 | { | |
561 | $this->logInAs('admin'); | |
562 | $client = $this->getClient(); | |
563 | ||
ac8cf632 JB |
564 | $em = $client->getContainer() |
565 | ->get('doctrine.orm.entity_manager'); | |
566 | ||
2863bf2a | 567 | // add a new content to be removed later |
ac8cf632 | 568 | $user = $em |
2863bf2a JB |
569 | ->getRepository('WallabagUserBundle:User') |
570 | ->findOneByUserName('admin'); | |
571 | ||
572 | $content = new Entry($user); | |
573 | $content->setUrl('http://1.1.1.1/entry'); | |
574 | $content->setReadingTime(12); | |
575 | $content->setDomainName('domain.io'); | |
576 | $content->setMimetype('text/html'); | |
577 | $content->setTitle('test title entry'); | |
578 | $content->setContent('This is my content /o/'); | |
579 | $content->setArchived(true); | |
580 | $content->setLanguage('fr'); | |
581 | ||
ac8cf632 JB |
582 | $em->persist($content); |
583 | $em->flush(); | |
2863bf2a JB |
584 | |
585 | $client->request('GET', '/view/'.$content->getId()); | |
586 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
587 | ||
588 | $client->request('GET', '/delete/'.$content->getId()); | |
589 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
590 | ||
591 | $client->followRedirect(); | |
592 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
593 | } | |
594 | ||
3d2b2d62 J |
595 | public function testViewOtherUserEntry() |
596 | { | |
159986c4 | 597 | $this->logInAs('admin'); |
3d2b2d62 J |
598 | $client = $this->getClient(); |
599 | ||
600 | $content = $client->getContainer() | |
601 | ->get('doctrine.orm.entity_manager') | |
602 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 603 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 604 | |
159986c4 | 605 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
606 | |
607 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
608 | } | |
26864574 | 609 | |
3f357ee2 | 610 | public function testFilterOnReadingTime() |
26864574 NL |
611 | { |
612 | $this->logInAs('admin'); | |
7ab5eb95 | 613 | $this->useTheme('baggy'); |
26864574 | 614 | $client = $this->getClient(); |
7ab5eb95 | 615 | $entry = new Entry($this->getLoggedInUser()); |
616 | $entry->setUrl($this->url); | |
617 | $entry->setReadingTime(22); | |
618 | $this->getEntityManager()->persist($entry); | |
619 | $this->getEntityManager()->flush(); | |
26864574 NL |
620 | |
621 | $crawler = $client->request('GET', '/unread/list'); | |
622 | ||
623 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
624 | ||
4094ea47 | 625 | $data = [ |
d6a9e139 NL |
626 | 'entry_filter[readingTime][right_number]' => 22, |
627 | 'entry_filter[readingTime][left_number]' => 22, | |
4094ea47 | 628 | ]; |
26864574 NL |
629 | |
630 | $crawler = $client->submit($form, $data); | |
631 | ||
632 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
633 | } | |
ab2c93c7 | 634 | |
1b164717 JB |
635 | public function testFilterOnReadingTimeWithNegativeValue() |
636 | { | |
637 | $this->logInAs('admin'); | |
638 | $client = $this->getClient(); | |
639 | ||
640 | $crawler = $client->request('GET', '/unread/list'); | |
641 | ||
642 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
643 | ||
644 | $data = [ | |
645 | 'entry_filter[readingTime][right_number]' => -22, | |
646 | 'entry_filter[readingTime][left_number]' => -22, | |
647 | ]; | |
648 | ||
649 | $crawler = $client->submit($form, $data); | |
650 | ||
651 | // forcing negative value results in no entry displayed | |
652 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
653 | } | |
654 | ||
95859e54 JB |
655 | public function testFilterOnReadingTimeOnlyUpper() |
656 | { | |
657 | $this->logInAs('admin'); | |
7ab5eb95 | 658 | $this->useTheme('baggy'); |
95859e54 JB |
659 | $client = $this->getClient(); |
660 | ||
7ab5eb95 | 661 | $crawler = $client->request('GET', '/all/list'); |
662 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
663 | ||
664 | $entry = new Entry($this->getLoggedInUser()); | |
665 | $entry->setUrl($this->url); | |
666 | $entry->setReadingTime(23); | |
667 | $this->getEntityManager()->persist($entry); | |
668 | $this->getEntityManager()->flush(); | |
669 | ||
670 | $crawler = $client->request('GET', '/all/list'); | |
671 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | |
95859e54 JB |
672 | |
673 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
674 | ||
675 | $data = [ | |
676 | 'entry_filter[readingTime][right_number]' => 22, | |
677 | ]; | |
678 | ||
679 | $crawler = $client->submit($form, $data); | |
680 | ||
7ab5eb95 | 681 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
95859e54 JB |
682 | } |
683 | ||
684 | public function testFilterOnReadingTimeOnlyLower() | |
685 | { | |
686 | $this->logInAs('admin'); | |
7ab5eb95 | 687 | $this->useTheme('baggy'); |
95859e54 JB |
688 | $client = $this->getClient(); |
689 | ||
690 | $crawler = $client->request('GET', '/unread/list'); | |
691 | ||
692 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
693 | ||
694 | $data = [ | |
695 | 'entry_filter[readingTime][left_number]' => 22, | |
696 | ]; | |
697 | ||
698 | $crawler = $client->submit($form, $data); | |
699 | ||
7ab5eb95 | 700 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
701 | ||
702 | $entry = new Entry($this->getLoggedInUser()); | |
703 | $entry->setUrl($this->url); | |
704 | $entry->setReadingTime(23); | |
705 | $this->getEntityManager()->persist($entry); | |
706 | $this->getEntityManager()->flush(); | |
707 | ||
708 | $crawler = $client->submit($form, $data); | |
709 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
95859e54 JB |
710 | } |
711 | ||
30334567 DB |
712 | public function testFilterOnUnreadStatus() |
713 | { | |
714 | $this->logInAs('admin'); | |
7ab5eb95 | 715 | $this->useTheme('baggy'); |
30334567 DB |
716 | $client = $this->getClient(); |
717 | ||
718 | $crawler = $client->request('GET', '/all/list'); | |
719 | ||
720 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
721 | ||
722 | $data = [ | |
723 | 'entry_filter[isUnread]' => true, | |
724 | ]; | |
725 | ||
726 | $crawler = $client->submit($form, $data); | |
727 | ||
7ab5eb95 | 728 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
729 | ||
730 | $entry = new Entry($this->getLoggedInUser()); | |
731 | $entry->setUrl($this->url); | |
732 | $entry->setArchived(false); | |
733 | $this->getEntityManager()->persist($entry); | |
734 | $this->getEntityManager()->flush(); | |
735 | ||
736 | $crawler = $client->submit($form, $data); | |
737 | ||
e9c80c99 | 738 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
30334567 DB |
739 | } |
740 | ||
3f357ee2 NL |
741 | public function testFilterOnCreationDate() |
742 | { | |
743 | $this->logInAs('admin'); | |
7ab5eb95 | 744 | $this->useTheme('baggy'); |
3f357ee2 NL |
745 | $client = $this->getClient(); |
746 | ||
747 | $crawler = $client->request('GET', '/unread/list'); | |
748 | ||
749 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
750 | ||
4094ea47 | 751 | $data = [ |
3f357ee2 | 752 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
8ce32af6 | 753 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
4094ea47 | 754 | ]; |
3f357ee2 NL |
755 | |
756 | $crawler = $client->submit($form, $data); | |
757 | ||
7ab5eb95 | 758 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 759 | |
4094ea47 | 760 | $data = [ |
f90af145 JB |
761 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
762 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
4094ea47 | 763 | ]; |
f90af145 JB |
764 | |
765 | $crawler = $client->submit($form, $data); | |
766 | ||
7ab5eb95 | 767 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
f90af145 | 768 | |
4094ea47 | 769 | $data = [ |
3f357ee2 | 770 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
8ce32af6 | 771 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
4094ea47 | 772 | ]; |
3f357ee2 NL |
773 | |
774 | $crawler = $client->submit($form, $data); | |
775 | ||
776 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
777 | } |
778 | ||
ab2c93c7 NL |
779 | public function testPaginationWithFilter() |
780 | { | |
781 | $this->logInAs('admin'); | |
782 | $client = $this->getClient(); | |
ab2c93c7 NL |
783 | $crawler = $client->request('GET', '/config'); |
784 | ||
785 | $form = $crawler->filter('button[id=config_save]')->form(); | |
786 | ||
4094ea47 | 787 | $data = [ |
ab2c93c7 | 788 | 'config[items_per_page]' => '1', |
4094ea47 | 789 | ]; |
ab2c93c7 NL |
790 | |
791 | $client->submit($form, $data); | |
792 | ||
76cd8dbb | 793 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
ab2c93c7 | 794 | |
5c072d2b | 795 | $client->request('GET', 'unread/list'.$parameters); |
ab2c93c7 NL |
796 | |
797 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
798 | |
799 | // reset pagination | |
800 | $crawler = $client->request('GET', '/config'); | |
801 | $form = $crawler->filter('button[id=config_save]')->form(); | |
4094ea47 | 802 | $data = [ |
e1779760 | 803 | 'config[items_per_page]' => '12', |
4094ea47 | 804 | ]; |
e1779760 | 805 | $client->submit($form, $data); |
ab2c93c7 | 806 | } |
443cecd2 NL |
807 | |
808 | public function testFilterOnDomainName() | |
809 | { | |
810 | $this->logInAs('admin'); | |
7ab5eb95 | 811 | $this->useTheme('baggy'); |
443cecd2 NL |
812 | $client = $this->getClient(); |
813 | ||
814 | $crawler = $client->request('GET', '/unread/list'); | |
815 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 816 | $data = [ |
02d17813 | 817 | 'entry_filter[domainName]' => 'domain', |
4094ea47 | 818 | ]; |
443cecd2 NL |
819 | |
820 | $crawler = $client->submit($form, $data); | |
02d17813 | 821 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 | 822 | |
00fc2b44 KD |
823 | $crawler = $client->request('GET', '/unread/list'); |
824 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
825 | $data = [ | |
826 | 'entry_filter[domainName]' => 'dOmain', | |
827 | ]; | |
828 | ||
829 | $crawler = $client->submit($form, $data); | |
830 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
831 | ||
443cecd2 | 832 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
4094ea47 | 833 | $data = [ |
8ce32af6 | 834 | 'entry_filter[domainName]' => 'wallabag', |
4094ea47 | 835 | ]; |
443cecd2 NL |
836 | |
837 | $crawler = $client->submit($form, $data); | |
838 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
839 | } | |
e1779760 NL |
840 | |
841 | public function testFilterOnStatus() | |
842 | { | |
843 | $this->logInAs('admin'); | |
7ab5eb95 | 844 | $this->useTheme('baggy'); |
e1779760 NL |
845 | $client = $this->getClient(); |
846 | ||
847 | $crawler = $client->request('GET', '/unread/list'); | |
848 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
849 | $form['entry_filter[isArchived]']->tick(); | |
850 | $form['entry_filter[isStarred]']->untick(); | |
851 | ||
852 | $crawler = $client->submit($form); | |
159986c4 | 853 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
854 | |
855 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
856 | $form['entry_filter[isArchived]']->untick(); | |
857 | $form['entry_filter[isStarred]']->tick(); | |
858 | ||
859 | $crawler = $client->submit($form); | |
02d17813 | 860 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 861 | } |
497e0cad NL |
862 | |
863 | public function testPreviewPictureFilter() | |
864 | { | |
865 | $this->logInAs('admin'); | |
7ab5eb95 | 866 | $this->useTheme('baggy'); |
497e0cad NL |
867 | $client = $this->getClient(); |
868 | ||
869 | $crawler = $client->request('GET', '/unread/list'); | |
870 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
871 | $form['entry_filter[previewPicture]']->tick(); | |
872 | ||
873 | $crawler = $client->submit($form); | |
7ab5eb95 | 874 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
497e0cad | 875 | } |
d4ebe5c5 JB |
876 | |
877 | public function testFilterOnLanguage() | |
878 | { | |
879 | $this->logInAs('admin'); | |
7ab5eb95 | 880 | $this->useTheme('baggy'); |
d4ebe5c5 JB |
881 | $client = $this->getClient(); |
882 | ||
7ab5eb95 | 883 | $entry = new Entry($this->getLoggedInUser()); |
884 | $entry->setUrl($this->url); | |
885 | $entry->setLanguage('fr'); | |
886 | $this->getEntityManager()->persist($entry); | |
887 | $this->getEntityManager()->flush(); | |
888 | ||
d4ebe5c5 JB |
889 | $crawler = $client->request('GET', '/unread/list'); |
890 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 891 | $data = [ |
159986c4 | 892 | 'entry_filter[language]' => 'fr', |
4094ea47 | 893 | ]; |
d4ebe5c5 JB |
894 | |
895 | $crawler = $client->submit($form, $data); | |
e9c80c99 | 896 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
897 | |
898 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 899 | $data = [ |
d4ebe5c5 | 900 | 'entry_filter[language]' => 'en', |
4094ea47 | 901 | ]; |
d4ebe5c5 JB |
902 | |
903 | $crawler = $client->submit($form, $data); | |
904 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
905 | } | |
a7e2218e | 906 | |
21d82c3c | 907 | public function testShareEntryPublicly() |
a7e2218e NL |
908 | { |
909 | $this->logInAs('admin'); | |
910 | $client = $this->getClient(); | |
911 | ||
7ab5eb95 | 912 | // sharing is enabled |
913 | $client->getContainer()->get('craue_config')->set('share_public', 1); | |
914 | ||
915 | $content = new Entry($this->getLoggedInUser()); | |
916 | $content->setUrl($this->url); | |
917 | $this->getEntityManager()->persist($content); | |
918 | $this->getEntityManager()->flush(); | |
919 | $this->getEntityManager()->clear(); | |
a7e2218e | 920 | |
7239082a NL |
921 | // no uid |
922 | $client->request('GET', '/share/'.$content->getUid()); | |
eddda878 JB |
923 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
924 | ||
7239082a | 925 | // generating the uid |
eddda878 JB |
926 | $client->request('GET', '/share/'.$content->getId()); |
927 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
928 | ||
7239082a | 929 | // follow link with uid |
eddda878 JB |
930 | $crawler = $client->followRedirect(); |
931 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
932 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
933 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
934 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
a7e2218e | 935 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
21d82c3c NL |
936 | $this->assertContains('og:title', $client->getResponse()->getContent()); |
937 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
938 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
d5c45d52 | 939 | $this->assertContains('og:image', $client->getResponse()->getContent()); |
a7e2218e | 940 | |
eddda878 JB |
941 | // sharing is now disabled |
942 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
7239082a | 943 | $client->request('GET', '/share/'.$content->getUid()); |
eddda878 JB |
944 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
945 | ||
a7e2218e NL |
946 | $client->request('GET', '/view/'.$content->getId()); |
947 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
eddda878 JB |
948 | |
949 | // removing the share | |
950 | $client->request('GET', '/share/delete/'.$content->getId()); | |
951 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
952 | ||
953 | // share is now disable | |
7239082a | 954 | $client->request('GET', '/share/'.$content->getUid()); |
eddda878 | 955 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
a7e2218e | 956 | } |
d1495dd0 JB |
957 | |
958 | public function testNewEntryWithDownloadImagesEnabled() | |
959 | { | |
be085c3d | 960 | $this->downloadImagesEnabled = true; |
d1495dd0 JB |
961 | $this->logInAs('admin'); |
962 | $client = $this->getClient(); | |
963 | ||
964 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
965 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
966 | ||
967 | $crawler = $client->request('GET', '/new'); | |
968 | ||
969 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
970 | ||
971 | $form = $crawler->filter('form[name=entry]')->form(); | |
972 | ||
973 | $data = [ | |
974 | 'entry[url]' => $url, | |
975 | ]; | |
976 | ||
977 | $client->submit($form, $data); | |
978 | ||
979 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
980 | ||
981 | $em = $client->getContainer() | |
982 | ->get('doctrine.orm.entity_manager'); | |
983 | ||
984 | $entry = $em | |
985 | ->getRepository('WallabagCoreBundle:Entry') | |
986 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
987 | ||
988 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
989 | $this->assertEquals($url, $entry->getUrl()); | |
990 | $this->assertContains('Perpignan', $entry->getTitle()); | |
be085c3d | 991 | // instead of checking for the filename (which might change) check that the image is now local |
1a942528 | 992 | $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); |
d1495dd0 | 993 | |
e0597476 JB |
994 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
995 | } | |
996 | ||
997 | /** | |
998 | * @depends testNewEntryWithDownloadImagesEnabled | |
999 | */ | |
1000 | public function testRemoveEntryWithDownloadImagesEnabled() | |
1001 | { | |
be085c3d | 1002 | $this->downloadImagesEnabled = true; |
e0597476 JB |
1003 | $this->logInAs('admin'); |
1004 | $client = $this->getClient(); | |
1005 | ||
1006 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
1007 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
1008 | ||
7ab5eb95 | 1009 | $crawler = $client->request('GET', '/new'); |
1010 | ||
1011 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
1012 | ||
1013 | $form = $crawler->filter('form[name=entry]')->form(); | |
1014 | ||
1015 | $data = [ | |
1016 | 'entry[url]' => $url, | |
1017 | ]; | |
1018 | ||
1019 | $client->submit($form, $data); | |
1020 | ||
1021 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
1022 | ||
e0597476 JB |
1023 | $content = $client->getContainer() |
1024 | ->get('doctrine.orm.entity_manager') | |
1025 | ->getRepository('WallabagCoreBundle:Entry') | |
1026 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1027 | ||
1028 | $client->request('GET', '/delete/'.$content->getId()); | |
1029 | ||
1030 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
d1495dd0 JB |
1031 | |
1032 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
1033 | } | |
65cd8a4a NL |
1034 | |
1035 | public function testRedirectToHomepage() | |
1036 | { | |
1037 | $this->logInAs('empty'); | |
1038 | $client = $this->getClient(); | |
1039 | ||
65cd8a4a | 1040 | // Redirect to homepage |
7ab5eb95 | 1041 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1042 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
7ab5eb95 | 1043 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1044 | |
7ab5eb95 | 1045 | $entry = new Entry($this->getLoggedInUser()); |
1046 | $entry->setUrl($this->url); | |
1047 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1048 | |
7ab5eb95 | 1049 | $this->getEntityManager()->flush(); |
1050 | ||
1051 | $client->request('GET', '/view/'.$entry->getId()); | |
1052 | $client->request('GET', '/archive/'.$entry->getId()); | |
65cd8a4a NL |
1053 | |
1054 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
1055 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | |
1056 | } | |
1057 | ||
1058 | public function testRedirectToCurrentPage() | |
1059 | { | |
1060 | $this->logInAs('empty'); | |
1061 | $client = $this->getClient(); | |
1062 | ||
65cd8a4a | 1063 | // Redirect to current page |
7ab5eb95 | 1064 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1065 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
7ab5eb95 | 1066 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1067 | |
7ab5eb95 | 1068 | $entry = new Entry($this->getLoggedInUser()); |
1069 | $entry->setUrl($this->url); | |
1070 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1071 | |
7ab5eb95 | 1072 | $this->getEntityManager()->flush(); |
1073 | ||
1074 | $client->request('GET', '/view/'.$entry->getId()); | |
1075 | $client->request('GET', '/archive/'.$entry->getId()); | |
65cd8a4a NL |
1076 | |
1077 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
7ab5eb95 | 1078 | $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); |
65cd8a4a | 1079 | } |
10b35097 NL |
1080 | |
1081 | public function testFilterOnHttpStatus() | |
1082 | { | |
1083 | $this->logInAs('admin'); | |
7ab5eb95 | 1084 | $this->useTheme('baggy'); |
10b35097 NL |
1085 | $client = $this->getClient(); |
1086 | ||
7ab5eb95 | 1087 | $entry = new Entry($this->getLoggedInUser()); |
1088 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); | |
1089 | $entry->setHttpStatus(404); | |
1090 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1091 | |
7ab5eb95 | 1092 | $this->getEntityManager()->flush(); |
10b35097 NL |
1093 | |
1094 | $crawler = $client->request('GET', '/all/list'); | |
1095 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1096 | ||
1097 | $data = [ | |
1098 | 'entry_filter[httpStatus]' => 404, | |
1099 | ]; | |
1100 | ||
1101 | $crawler = $client->submit($form, $data); | |
1102 | ||
1103 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1104 | ||
7ab5eb95 | 1105 | $entry = new Entry($this->getLoggedInUser()); |
1106 | $entry->setUrl($this->url); | |
1107 | $entry->setHttpStatus(200); | |
1108 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1109 | |
7ab5eb95 | 1110 | $entry = new Entry($this->getLoggedInUser()); |
1111 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); | |
1112 | $entry->setHttpStatus(200); | |
1113 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1114 | |
7ab5eb95 | 1115 | $this->getEntityManager()->flush(); |
10b35097 NL |
1116 | |
1117 | $crawler = $client->request('GET', '/all/list'); | |
1118 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1119 | ||
1120 | $data = [ | |
1121 | 'entry_filter[httpStatus]' => 200, | |
1122 | ]; | |
1123 | ||
1124 | $crawler = $client->submit($form, $data); | |
1125 | ||
e9c80c99 | 1126 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d215273c NL |
1127 | |
1128 | $crawler = $client->request('GET', '/all/list'); | |
1129 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1130 | ||
1131 | $data = [ | |
1132 | 'entry_filter[httpStatus]' => 1024, | |
1133 | ]; | |
1134 | ||
1135 | $crawler = $client->submit($form, $data); | |
1136 | ||
e9c80c99 | 1137 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
10b35097 | 1138 | } |
32f455c1 NL |
1139 | |
1140 | public function testSearch() | |
1141 | { | |
1142 | $this->logInAs('admin'); | |
7ab5eb95 | 1143 | $this->useTheme('baggy'); |
32f455c1 NL |
1144 | $client = $this->getClient(); |
1145 | ||
7ab5eb95 | 1146 | $entry = new Entry($this->getLoggedInUser()); |
1147 | $entry->setUrl($this->url); | |
1148 | $entry->setTitle('test'); | |
1149 | $this->getEntityManager()->persist($entry); | |
1150 | $this->getEntityManager()->flush(); | |
1151 | ||
32f455c1 NL |
1152 | // Search on unread list |
1153 | $crawler = $client->request('GET', '/unread/list'); | |
1154 | ||
1155 | $form = $crawler->filter('form[name=search]')->form(); | |
1156 | $data = [ | |
1157 | 'search_entry[term]' => 'title', | |
1158 | ]; | |
1159 | ||
1160 | $crawler = $client->submit($form, $data); | |
1161 | ||
7ab5eb95 | 1162 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
32f455c1 NL |
1163 | |
1164 | // Search on starred list | |
1165 | $crawler = $client->request('GET', '/starred/list'); | |
1166 | ||
7ab5eb95 | 1167 | $entry = new Entry($this->getLoggedInUser()); |
1168 | $entry->setUrl('http://localhost/foo/bar'); | |
1169 | $entry->setTitle('testeur'); | |
1170 | $entry->setStarred(true); | |
1171 | $this->getEntityManager()->persist($entry); | |
1172 | $this->getEntityManager()->flush(); | |
1173 | ||
32f455c1 NL |
1174 | $form = $crawler->filter('form[name=search]')->form(); |
1175 | $data = [ | |
7ab5eb95 | 1176 | 'search_entry[term]' => 'testeur', |
32f455c1 NL |
1177 | ]; |
1178 | ||
1179 | $crawler = $client->submit($form, $data); | |
1180 | ||
1181 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1182 | ||
32f455c1 NL |
1183 | $crawler = $client->request('GET', '/archive/list'); |
1184 | ||
7ab5eb95 | 1185 | // Added new article to test on archive list |
1186 | $entry = new Entry($this->getLoggedInUser()); | |
1187 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | |
1188 | $entry->setTitle('Le manège'); | |
1189 | $entry->setArchived(true); | |
1190 | $this->getEntityManager()->persist($entry); | |
1191 | $this->getEntityManager()->flush(); | |
1192 | ||
32f455c1 NL |
1193 | $form = $crawler->filter('form[name=search]')->form(); |
1194 | $data = [ | |
1195 | 'search_entry[term]' => 'manège', | |
1196 | ]; | |
1197 | ||
1198 | $crawler = $client->submit($form, $data); | |
1199 | ||
1200 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
7ab5eb95 | 1201 | $client->request('GET', '/delete/'.$entry->getId()); |
32f455c1 NL |
1202 | |
1203 | // test on list of all articles | |
1204 | $crawler = $client->request('GET', '/all/list'); | |
1205 | ||
1206 | $form = $crawler->filter('form[name=search]')->form(); | |
1207 | $data = [ | |
995c2044 | 1208 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database |
32f455c1 NL |
1209 | ]; |
1210 | ||
1211 | $crawler = $client->submit($form, $data); | |
1212 | ||
1213 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
eac09b48 KD |
1214 | |
1215 | // test url search on list of all articles | |
7ab5eb95 | 1216 | $entry = new Entry($this->getLoggedInUser()); |
1217 | $entry->setUrl('http://domain/qux'); | |
1218 | $entry->setTitle('Le manège'); | |
1219 | $entry->setArchived(true); | |
1220 | $this->getEntityManager()->persist($entry); | |
1221 | $this->getEntityManager()->flush(); | |
1222 | ||
eac09b48 KD |
1223 | $crawler = $client->request('GET', '/all/list'); |
1224 | ||
1225 | $form = $crawler->filter('form[name=search]')->form(); | |
1226 | $data = [ | |
1227 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1228 | ]; | |
1229 | ||
1230 | $crawler = $client->submit($form, $data); | |
1231 | ||
1232 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1233 | ||
1234 | // same as previous test but for case-sensitivity | |
1235 | $crawler = $client->request('GET', '/all/list'); | |
1236 | ||
1237 | $form = $crawler->filter('form[name=search]')->form(); | |
1238 | $data = [ | |
1239 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1240 | ]; | |
1241 | ||
1242 | $crawler = $client->submit($form, $data); | |
1243 | ||
1244 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
32f455c1 | 1245 | } |
42f3bb2c JB |
1246 | |
1247 | public function dataForLanguage() | |
1248 | { | |
1249 | return [ | |
1250 | 'ru' => [ | |
1251 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | |
1252 | 'ru', | |
1253 | ], | |
80e49ba7 JB |
1254 | 'fr-FR' => [ |
1255 | 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', | |
1256 | 'fr_FR', | |
42f3bb2c JB |
1257 | ], |
1258 | 'de' => [ | |
1259 | 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | |
1260 | 'de', | |
1261 | ], | |
1262 | 'it' => [ | |
1263 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | |
1264 | 'it', | |
1265 | ], | |
1266 | 'zh_CN' => [ | |
1267 | 'http://www.hao123.com/shequ?__noscript__-=1', | |
1268 | 'zh_CN', | |
1269 | ], | |
1270 | 'de_AT' => [ | |
1271 | 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', | |
1272 | 'de_AT', | |
1273 | ], | |
1274 | 'ru_RU' => [ | |
1275 | 'http://netler.ru/ikt/windows-error-reporting.htm', | |
1276 | 'ru_RU', | |
1277 | ], | |
1278 | 'pt_BR' => [ | |
1279 | 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', | |
1280 | 'pt_BR', | |
1281 | ], | |
80e49ba7 | 1282 | 'fucked_list_of_languages' => [ |
42f3bb2c JB |
1283 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', |
1284 | '', | |
1285 | ], | |
80e49ba7 JB |
1286 | 'es-ES' => [ |
1287 | 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', | |
1288 | 'es_ES', | |
1289 | ], | |
42f3bb2c JB |
1290 | ]; |
1291 | } | |
1292 | ||
1293 | /** | |
1294 | * @dataProvider dataForLanguage | |
1295 | */ | |
1296 | public function testLanguageValidation($url, $expectedLanguage) | |
1297 | { | |
1298 | $this->logInAs('admin'); | |
1299 | $client = $this->getClient(); | |
1300 | ||
1301 | $crawler = $client->request('GET', '/new'); | |
1302 | ||
1303 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
1304 | ||
1305 | $form = $crawler->filter('form[name=entry]')->form(); | |
1306 | ||
1307 | $data = [ | |
1308 | 'entry[url]' => $url, | |
1309 | ]; | |
1310 | ||
1311 | $client->submit($form, $data); | |
1312 | ||
1313 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
1314 | ||
1315 | $content = $client->getContainer() | |
1316 | ->get('doctrine.orm.entity_manager') | |
1317 | ->getRepository('WallabagCoreBundle:Entry') | |
1318 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1319 | ||
1320 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
1321 | $this->assertEquals($url, $content->getUrl()); | |
1322 | $this->assertEquals($expectedLanguage, $content->getLanguage()); | |
1323 | } | |
93fd4692 | 1324 | } |