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