]>
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; |
b8568662 | 9 | use Wallabag\CoreBundle\Entity\Tag; |
300f293c | 10 | use Wallabag\CoreBundle\Helper\ContentProxy; |
93fd4692 | 11 | |
769e19dc | 12 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 13 | { |
77854331 | 14 | const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; |
be085c3d | 15 | public $downloadImagesEnabled = false; |
4552f1c1 | 16 | public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html'; |
02d17813 | 17 | |
be085c3d JB |
18 | /** |
19 | * @after | |
20 | * | |
21 | * Ensure download_images_enabled is disabled after each script | |
22 | */ | |
23 | public function tearDownImagesEnabled() | |
24 | { | |
25 | if ($this->downloadImagesEnabled) { | |
26 | $client = static::createClient(); | |
27 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
28 | ||
29 | $this->downloadImagesEnabled = false; | |
30 | } | |
31 | } | |
32 | ||
3b815d2d J |
33 | public function testLogin() |
34 | { | |
35 | $client = $this->getClient(); | |
36 | ||
eb3bd7ef | 37 | $client->request('GET', '/new'); |
3b815d2d | 38 | |
f808b016 | 39 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
3b815d2d J |
40 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
41 | } | |
42 | ||
71f7e58f KD |
43 | /** |
44 | * @group NetworkCalls | |
45 | */ | |
5c072d2b NL |
46 | public function testQuickstart() |
47 | { | |
48 | $this->logInAs('empty'); | |
49 | $client = $this->getClient(); | |
50 | ||
51 | $client->request('GET', '/unread/list'); | |
38520658 | 52 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4f9cf232 | 53 | $crawler = $client->followRedirect(); |
5c072d2b | 54 | |
f808b016 | 55 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4094ea47 | 56 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
24ad330b | 57 | $this->assertContains('quickstart.intro.title', $body[0]); |
5c072d2b NL |
58 | |
59 | // Test if quickstart is disabled when user has 1 entry | |
60 | $crawler = $client->request('GET', '/new'); | |
61 | ||
f808b016 | 62 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5c072d2b | 63 | |
0d42217e | 64 | $form = $crawler->filter('form[name=entry]')->form(); |
5c072d2b | 65 | |
4094ea47 | 66 | $data = [ |
78833672 | 67 | 'entry[url]' => $this->url, |
4094ea47 | 68 | ]; |
5c072d2b NL |
69 | |
70 | $client->submit($form, $data); | |
f808b016 | 71 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
5c072d2b NL |
72 | $client->followRedirect(); |
73 | ||
4f9cf232 | 74 | $crawler = $client->request('GET', '/unread/list'); |
4094ea47 | 75 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 76 | $this->assertContains('entry.list.number_on_the_page', $body[0]); |
5c072d2b NL |
77 | } |
78 | ||
9c0c8820 | 79 | public function testGetNew() |
93fd4692 | 80 | { |
eb3bd7ef | 81 | $this->logInAs('admin'); |
7ab5eb95 | 82 | $this->useTheme('baggy'); |
3b815d2d | 83 | $client = $this->getClient(); |
93fd4692 | 84 | |
aa6e27cf | 85 | $crawler = $client->request('GET', '/new'); |
93fd4692 | 86 | |
f808b016 | 87 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9c0c8820 J |
88 | |
89 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
0d42217e | 90 | $this->assertCount(1, $crawler->filter('form[name=entry]')); |
9c0c8820 J |
91 | } |
92 | ||
71f7e58f KD |
93 | /** |
94 | * @group NetworkCalls | |
95 | */ | |
880a0e1c NL |
96 | public function testPostNewViaBookmarklet() |
97 | { | |
98 | $this->logInAs('admin'); | |
99 | $client = $this->getClient(); | |
100 | ||
101 | $crawler = $client->request('GET', '/'); | |
102 | ||
ef81e3c8 | 103 | $this->assertCount(4, $crawler->filter('li.entry')); |
880a0e1c NL |
104 | |
105 | // Good URL | |
4094ea47 | 106 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); |
f808b016 | 107 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
5c072d2b | 108 | $client->followRedirect(); |
880a0e1c | 109 | $crawler = $client->request('GET', '/'); |
ef81e3c8 | 110 | $this->assertCount(5, $crawler->filter('li.entry')); |
880a0e1c NL |
111 | |
112 | $em = $client->getContainer() | |
113 | ->get('doctrine.orm.entity_manager'); | |
114 | $entry = $em | |
115 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 116 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
880a0e1c NL |
117 | $em->remove($entry); |
118 | $em->flush(); | |
119 | } | |
120 | ||
9c0c8820 J |
121 | public function testPostNewEmpty() |
122 | { | |
eb3bd7ef | 123 | $this->logInAs('admin'); |
3b815d2d | 124 | $client = $this->getClient(); |
9c0c8820 J |
125 | |
126 | $crawler = $client->request('GET', '/new'); | |
127 | ||
f808b016 | 128 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9c0c8820 | 129 | |
0d42217e | 130 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 J |
131 | |
132 | $crawler = $client->submit($form); | |
133 | ||
f808b016 | 134 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4094ea47 | 135 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); |
f808b016 | 136 | $this->assertSame('This value should not be blank.', $alert[0]); |
9c0c8820 J |
137 | } |
138 | ||
8a493541 | 139 | /** |
71f7e58f | 140 | * @group NetworkCalls |
8a493541 | 141 | */ |
9c0c8820 J |
142 | public function testPostNewOk() |
143 | { | |
eb3bd7ef | 144 | $this->logInAs('admin'); |
3b815d2d | 145 | $client = $this->getClient(); |
9c0c8820 | 146 | |
8a219854 NL |
147 | $client->getContainer()->get('craue_config')->set('store_article_headers', 1); |
148 | ||
9c0c8820 J |
149 | $crawler = $client->request('GET', '/new'); |
150 | ||
f808b016 | 151 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9c0c8820 | 152 | |
0d42217e | 153 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 | 154 | |
4094ea47 | 155 | $data = [ |
02d17813 | 156 | 'entry[url]' => $this->url, |
4094ea47 | 157 | ]; |
9c0c8820 J |
158 | |
159 | $client->submit($form, $data); | |
160 | ||
f808b016 | 161 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
9c0c8820 | 162 | |
a0d6ccc5 JB |
163 | $content = $client->getContainer() |
164 | ->get('doctrine.orm.entity_manager') | |
165 | ->getRepository('WallabagCoreBundle:Entry') | |
166 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
167 | ||
7b0b3622 NL |
168 | $author = $content->getPublishedBy(); |
169 | ||
a0d6ccc5 | 170 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
f808b016 | 171 | $this->assertSame($this->url, $content->getUrl()); |
4552f1c1 | 172 | $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle()); |
f808b016 | 173 | $this->assertSame('fr', $content->getLanguage()); |
dc90eab3 | 174 | $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); |
8a219854 | 175 | $client->getContainer()->get('craue_config')->set('store_article_headers', 0); |
a0d6ccc5 | 176 | } |
9c0c8820 | 177 | |
71f7e58f KD |
178 | /** |
179 | * @group NetworkCalls | |
180 | */ | |
e9c80c99 NL |
181 | public function testPostWithMultipleAuthors() |
182 | { | |
84b3bdaa | 183 | $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; |
e9c80c99 NL |
184 | $this->logInAs('admin'); |
185 | $client = $this->getClient(); | |
186 | ||
187 | $crawler = $client->request('GET', '/new'); | |
188 | ||
f808b016 | 189 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
e9c80c99 NL |
190 | |
191 | $form = $crawler->filter('form[name=entry]')->form(); | |
192 | ||
193 | $data = [ | |
194 | 'entry[url]' => $url, | |
195 | ]; | |
196 | ||
197 | $client->submit($form, $data); | |
198 | ||
f808b016 | 199 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
e9c80c99 NL |
200 | |
201 | $content = $client->getContainer() | |
202 | ->get('doctrine.orm.entity_manager') | |
203 | ->getRepository('WallabagCoreBundle:Entry') | |
204 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
205 | ||
84b3bdaa | 206 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
e9c80c99 | 207 | $authors = $content->getPublishedBy(); |
f808b016 JB |
208 | $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); |
209 | $this->assertSame('fr', $content->getLanguage()); | |
4a31f3b6 JB |
210 | $this->assertSame('Raphaël Balenieri', $authors[0]); |
211 | $this->assertSame('Frédéric Autran', $authors[1]); | |
e9c80c99 NL |
212 | } |
213 | ||
a0d6ccc5 JB |
214 | public function testPostNewOkUrlExist() |
215 | { | |
216 | $this->logInAs('admin'); | |
7ab5eb95 | 217 | |
218 | $entry = new Entry($this->getLoggedInUser()); | |
219 | $entry->setUrl($this->url); | |
220 | $this->getEntityManager()->persist($entry); | |
221 | $this->getEntityManager()->flush(); | |
222 | ||
a0d6ccc5 JB |
223 | $client = $this->getClient(); |
224 | ||
225 | $crawler = $client->request('GET', '/new'); | |
226 | ||
f808b016 | 227 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a0d6ccc5 | 228 | |
0d42217e | 229 | $form = $crawler->filter('form[name=entry]')->form(); |
a0d6ccc5 | 230 | |
4094ea47 | 231 | $data = [ |
a0d6ccc5 | 232 | 'entry[url]' => $this->url, |
4094ea47 | 233 | ]; |
a0d6ccc5 JB |
234 | |
235 | $client->submit($form, $data); | |
236 | ||
f808b016 | 237 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
a0d6ccc5 | 238 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
9c0c8820 J |
239 | } |
240 | ||
71f7e58f KD |
241 | /** |
242 | * @group NetworkCalls | |
243 | */ | |
19ca0b2f JB |
244 | public function testPostNewOkUrlExistWithAccent() |
245 | { | |
246 | $this->logInAs('admin'); | |
247 | $client = $this->getClient(); | |
248 | ||
d6cc0b24 | 249 | $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; |
19ca0b2f JB |
250 | |
251 | $crawler = $client->request('GET', '/new'); | |
252 | ||
f808b016 | 253 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
19ca0b2f JB |
254 | |
255 | $form = $crawler->filter('form[name=entry]')->form(); | |
256 | ||
257 | $data = [ | |
258 | 'entry[url]' => $url, | |
259 | ]; | |
260 | ||
261 | $client->submit($form, $data); | |
262 | ||
263 | $crawler = $client->request('GET', '/new'); | |
264 | ||
f808b016 | 265 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
19ca0b2f JB |
266 | |
267 | $form = $crawler->filter('form[name=entry]')->form(); | |
268 | ||
269 | $data = [ | |
270 | 'entry[url]' => $url, | |
271 | ]; | |
a0d6ccc5 JB |
272 | |
273 | $client->submit($form, $data); | |
274 | ||
b7fa51ae NL |
275 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
276 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
277 | } | |
278 | ||
70df4c33 | 279 | /** |
71f7e58f | 280 | * @group NetworkCalls |
70df4c33 | 281 | */ |
b7fa51ae NL |
282 | public function testPostNewOkUrlExistWithRedirection() |
283 | { | |
284 | $this->logInAs('admin'); | |
285 | $client = $this->getClient(); | |
286 | ||
287 | $url = 'https://wllbg.org/test-redirect/c51c'; | |
288 | ||
289 | $crawler = $client->request('GET', '/new'); | |
290 | ||
291 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
292 | ||
293 | $form = $crawler->filter('form[name=entry]')->form(); | |
294 | ||
295 | $data = [ | |
296 | 'entry[url]' => $url, | |
297 | ]; | |
298 | ||
299 | $client->submit($form, $data); | |
300 | ||
301 | $crawler = $client->request('GET', '/new'); | |
302 | ||
303 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
304 | ||
305 | $form = $crawler->filter('form[name=entry]')->form(); | |
306 | ||
307 | $data = [ | |
308 | 'entry[url]' => $url, | |
309 | ]; | |
310 | ||
311 | $client->submit($form, $data); | |
312 | ||
f808b016 | 313 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
a0d6ccc5 | 314 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
9c0c8820 J |
315 | } |
316 | ||
958671a7 | 317 | /** |
71f7e58f | 318 | * @group NetworkCalls |
958671a7 | 319 | */ |
3be04745 | 320 | public function testPostNewThatWillBeTagged() |
958671a7 KG |
321 | { |
322 | $this->logInAs('admin'); | |
323 | $client = $this->getClient(); | |
324 | ||
325 | $crawler = $client->request('GET', '/new'); | |
326 | ||
f808b016 | 327 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
958671a7 | 328 | |
0d42217e | 329 | $form = $crawler->filter('form[name=entry]')->form(); |
958671a7 | 330 | |
4094ea47 | 331 | $data = [ |
958671a7 | 332 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', |
4094ea47 | 333 | ]; |
958671a7 KG |
334 | |
335 | $client->submit($form, $data); | |
336 | ||
f808b016 | 337 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
3be04745 | 338 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
958671a7 KG |
339 | |
340 | $em = $client->getContainer() | |
341 | ->get('doctrine.orm.entity_manager'); | |
342 | $entry = $em | |
343 | ->getRepository('WallabagCoreBundle:Entry') | |
344 | ->findOneByUrl($url); | |
69edb774 KG |
345 | $tags = $entry->getTags(); |
346 | ||
fdd725f5 | 347 | $this->assertCount(2, $tags); |
7ab5eb95 | 348 | $this->assertContains('wallabag', $tags); |
f808b016 | 349 | $this->assertSame('en', $entry->getLanguage()); |
958671a7 KG |
350 | |
351 | $em->remove($entry); | |
352 | $em->flush(); | |
3be04745 JB |
353 | |
354 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
355 | // related https://github.com/wallabag/wallabag/issues/2121 | |
356 | $crawler = $client->request('GET', '/new'); | |
357 | ||
f808b016 | 358 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
3be04745 JB |
359 | |
360 | $form = $crawler->filter('form[name=entry]')->form(); | |
361 | ||
362 | $data = [ | |
363 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
364 | ]; | |
365 | ||
366 | $client->submit($form, $data); | |
367 | ||
f808b016 | 368 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
3be04745 JB |
369 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
370 | ||
371 | $entry = $em | |
372 | ->getRepository('WallabagCoreBundle:Entry') | |
373 | ->findOneByUrl($url); | |
374 | ||
375 | $tags = $entry->getTags(); | |
376 | ||
fdd725f5 | 377 | $this->assertCount(2, $tags); |
7ab5eb95 | 378 | $this->assertContains('wallabag', $tags); |
3be04745 JB |
379 | |
380 | $em->remove($entry); | |
381 | $em->flush(); | |
958671a7 KG |
382 | } |
383 | ||
9c0c8820 J |
384 | public function testArchive() |
385 | { | |
eb3bd7ef | 386 | $this->logInAs('admin'); |
3b815d2d | 387 | $client = $this->getClient(); |
9c0c8820 | 388 | |
9fb6ac83 | 389 | $client->request('GET', '/archive/list'); |
9c0c8820 | 390 | |
f808b016 | 391 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9c0c8820 J |
392 | } |
393 | ||
d5d16121 NL |
394 | public function testUntagged() |
395 | { | |
396 | $this->logInAs('admin'); | |
397 | $client = $this->getClient(); | |
398 | ||
399 | $client->request('GET', '/untagged/list'); | |
400 | ||
f808b016 | 401 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d5d16121 NL |
402 | } |
403 | ||
9c0c8820 J |
404 | public function testStarred() |
405 | { | |
eb3bd7ef | 406 | $this->logInAs('admin'); |
3b815d2d | 407 | $client = $this->getClient(); |
9c0c8820 | 408 | |
9fb6ac83 | 409 | $client->request('GET', '/starred/list'); |
9c0c8820 | 410 | |
f808b016 | 411 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9c0c8820 J |
412 | } |
413 | ||
671a2b88 ML |
414 | public function testRangeException() |
415 | { | |
416 | $this->logInAs('admin'); | |
417 | $client = $this->getClient(); | |
418 | ||
419 | $client->request('GET', '/all/list/900'); | |
420 | ||
f808b016 JB |
421 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
422 | $this->assertSame('/all/list', $client->getResponse()->getTargetUrl()); | |
671a2b88 ML |
423 | } |
424 | ||
9c0c8820 J |
425 | public function testView() |
426 | { | |
eb3bd7ef | 427 | $this->logInAs('admin'); |
3b815d2d | 428 | $client = $this->getClient(); |
9c0c8820 | 429 | |
7ab5eb95 | 430 | $entry = new Entry($this->getLoggedInUser()); |
431 | $entry->setUrl('http://example.com/foo'); | |
432 | $entry->setTitle('title foo'); | |
433 | $entry->setContent('foo bar baz'); | |
434 | $this->getEntityManager()->persist($entry); | |
435 | $this->getEntityManager()->flush(); | |
9c0c8820 | 436 | |
f808b016 | 437 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
9c0c8820 | 438 | |
f808b016 | 439 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4094ea47 | 440 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
7ab5eb95 | 441 | $this->assertContains($entry->getTitle(), $body[0]); |
93fd4692 | 442 | } |
eb3bd7ef | 443 | |
831b02aa | 444 | /** |
71f7e58f | 445 | * @group NetworkCalls |
831b02aa JB |
446 | */ |
447 | public function testReload() | |
448 | { | |
449 | $this->logInAs('admin'); | |
450 | $client = $this->getClient(); | |
451 | ||
7ab5eb95 | 452 | $entry = new Entry($this->getLoggedInUser()); |
453 | $entry->setUrl($this->url); | |
454 | $entry->setTitle('title foo'); | |
455 | $entry->setContent(''); | |
456 | $this->getEntityManager()->persist($entry); | |
457 | $this->getEntityManager()->flush(); | |
458 | $this->getEntityManager()->clear(); | |
ac8cf632 | 459 | |
f808b016 | 460 | $client->request('GET', '/reload/' . $entry->getId()); |
831b02aa | 461 | |
f808b016 | 462 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
831b02aa | 463 | |
7ab5eb95 | 464 | $entry = $this->getEntityManager() |
831b02aa | 465 | ->getRepository('WallabagCoreBundle:Entry') |
7ab5eb95 | 466 | ->find($entry->getId()); |
831b02aa | 467 | |
7ab5eb95 | 468 | $this->assertNotEmpty($entry->getContent()); |
831b02aa JB |
469 | } |
470 | ||
2297d60f JB |
471 | public function testReloadWithFetchingFailed() |
472 | { | |
473 | $this->logInAs('admin'); | |
474 | $client = $this->getClient(); | |
475 | ||
7ab5eb95 | 476 | $entry = new Entry($this->getLoggedInUser()); |
477 | $entry->setUrl('http://0.0.0.0/failed.html'); | |
478 | $this->getEntityManager()->persist($entry); | |
479 | $this->getEntityManager()->flush(); | |
2297d60f | 480 | |
f808b016 | 481 | $client->request('GET', '/reload/' . $entry->getId()); |
2297d60f | 482 | |
f808b016 | 483 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
2297d60f JB |
484 | |
485 | // force EntityManager to clear previous entity | |
486 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
7ab5eb95 | 487 | $this->getEntityManager()->clear(); |
488 | $newContent = $this->getEntityManager() | |
2297d60f | 489 | ->getRepository('WallabagCoreBundle:Entry') |
7ab5eb95 | 490 | ->find($entry->getId()); |
2297d60f | 491 | |
f808b016 | 492 | $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
2297d60f JB |
493 | } |
494 | ||
82d6d9cb JB |
495 | public function testEdit() |
496 | { | |
497 | $this->logInAs('admin'); | |
498 | $client = $this->getClient(); | |
499 | ||
7ab5eb95 | 500 | $entry = new Entry($this->getLoggedInUser()); |
501 | $entry->setUrl($this->url); | |
502 | $this->getEntityManager()->persist($entry); | |
503 | $this->getEntityManager()->flush(); | |
82d6d9cb | 504 | |
f808b016 | 505 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); |
82d6d9cb | 506 | |
f808b016 | 507 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
82d6d9cb JB |
508 | |
509 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
510 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
511 | } | |
512 | ||
513 | public function testEditUpdate() | |
514 | { | |
515 | $this->logInAs('admin'); | |
516 | $client = $this->getClient(); | |
517 | ||
7ab5eb95 | 518 | $entry = new Entry($this->getLoggedInUser()); |
519 | $entry->setUrl($this->url); | |
520 | $this->getEntityManager()->persist($entry); | |
521 | $this->getEntityManager()->flush(); | |
82d6d9cb | 522 | |
f808b016 | 523 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); |
82d6d9cb | 524 | |
f808b016 | 525 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
82d6d9cb | 526 | |
5614df19 | 527 | $form = $crawler->filter('button[id=entry_save]')->form(); |
82d6d9cb | 528 | |
4094ea47 | 529 | $data = [ |
82d6d9cb | 530 | 'entry[title]' => 'My updated title hehe :)', |
97444566 | 531 | 'entry[origin_url]' => 'https://example.io', |
4094ea47 | 532 | ]; |
82d6d9cb JB |
533 | |
534 | $client->submit($form, $data); | |
535 | ||
f808b016 | 536 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
82d6d9cb JB |
537 | |
538 | $crawler = $client->followRedirect(); | |
539 | ||
97444566 KD |
540 | $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); |
541 | $this->assertContains('My updated title hehe :)', $title[0]); | |
01f8a776 | 542 | $this->assertGreaterThan(1, $stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text'])); |
97444566 KD |
543 | $this->assertContains('example.io', trim($stats[1])); |
544 | } | |
545 | ||
546 | public function testEditRemoveOriginUrl() | |
547 | { | |
548 | $this->logInAs('admin'); | |
549 | $client = $this->getClient(); | |
550 | ||
551 | $entry = new Entry($this->getLoggedInUser()); | |
552 | $entry->setUrl($this->url); | |
553 | $this->getEntityManager()->persist($entry); | |
554 | $this->getEntityManager()->flush(); | |
555 | ||
556 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); | |
557 | ||
558 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
559 | ||
5614df19 | 560 | $form = $crawler->filter('button[id=entry_save]')->form(); |
97444566 KD |
561 | |
562 | $data = [ | |
563 | 'entry[title]' => 'My updated title hehe :)', | |
564 | 'entry[origin_url]' => '', | |
565 | ]; | |
566 | ||
567 | $client->submit($form, $data); | |
568 | ||
569 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
570 | ||
571 | $crawler = $client->followRedirect(); | |
572 | ||
1e0d8ad7 JB |
573 | $title = $crawler->filter('div[id=article] h1')->extract(['_text']); |
574 | $this->assertGreaterThan(1, $title); | |
97444566 | 575 | $this->assertContains('My updated title hehe :)', $title[0]); |
1e0d8ad7 | 576 | |
01f8a776 | 577 | $stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text']); |
1e0d8ad7 | 578 | $this->assertCount(1, $stats); |
97444566 | 579 | $this->assertNotContains('example.io', trim($stats[0])); |
82d6d9cb JB |
580 | } |
581 | ||
eb3bd7ef J |
582 | public function testToggleArchive() |
583 | { | |
584 | $this->logInAs('admin'); | |
585 | $client = $this->getClient(); | |
586 | ||
7ab5eb95 | 587 | $entry = new Entry($this->getLoggedInUser()); |
588 | $entry->setUrl($this->url); | |
589 | $this->getEntityManager()->persist($entry); | |
590 | $this->getEntityManager()->flush(); | |
591 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 592 | |
f808b016 | 593 | $client->request('GET', '/archive/' . $entry->getId()); |
eb3bd7ef | 594 | |
f808b016 | 595 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef J |
596 | |
597 | $res = $client->getContainer() | |
598 | ->get('doctrine.orm.entity_manager') | |
599 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 600 | ->find($entry->getId()); |
eb3bd7ef | 601 | |
38520658 | 602 | $this->assertSame(1, $res->isArchived()); |
eb3bd7ef J |
603 | } |
604 | ||
605 | public function testToggleStar() | |
606 | { | |
607 | $this->logInAs('admin'); | |
608 | $client = $this->getClient(); | |
609 | ||
7ab5eb95 | 610 | $entry = new Entry($this->getLoggedInUser()); |
611 | $entry->setUrl($this->url); | |
612 | $this->getEntityManager()->persist($entry); | |
613 | $this->getEntityManager()->flush(); | |
614 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 615 | |
f808b016 | 616 | $client->request('GET', '/star/' . $entry->getId()); |
eb3bd7ef | 617 | |
f808b016 | 618 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef J |
619 | |
620 | $res = $client->getContainer() | |
621 | ->get('doctrine.orm.entity_manager') | |
622 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 623 | ->findOneById($entry->getId()); |
eb3bd7ef | 624 | |
38520658 | 625 | $this->assertSame(1, $res->isStarred()); |
eb3bd7ef J |
626 | } |
627 | ||
628 | public function testDelete() | |
629 | { | |
630 | $this->logInAs('admin'); | |
631 | $client = $this->getClient(); | |
632 | ||
7ab5eb95 | 633 | $entry = new Entry($this->getLoggedInUser()); |
634 | $entry->setUrl($this->url); | |
635 | $this->getEntityManager()->persist($entry); | |
636 | $this->getEntityManager()->flush(); | |
eb3bd7ef | 637 | |
f808b016 | 638 | $client->request('GET', '/delete/' . $entry->getId()); |
eb3bd7ef | 639 | |
f808b016 | 640 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 641 | |
f808b016 | 642 | $client->request('GET', '/delete/' . $entry->getId()); |
eb3bd7ef | 643 | |
f808b016 | 644 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 645 | } |
3d2b2d62 | 646 | |
2863bf2a JB |
647 | /** |
648 | * It will create a new entry. | |
649 | * Browse to it. | |
650 | * Then remove it. | |
651 | * | |
652 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
653 | */ | |
654 | public function testViewAndDelete() | |
655 | { | |
656 | $this->logInAs('admin'); | |
657 | $client = $this->getClient(); | |
658 | ||
ac8cf632 JB |
659 | $em = $client->getContainer() |
660 | ->get('doctrine.orm.entity_manager'); | |
661 | ||
2863bf2a | 662 | // add a new content to be removed later |
ac8cf632 | 663 | $user = $em |
2863bf2a JB |
664 | ->getRepository('WallabagUserBundle:User') |
665 | ->findOneByUserName('admin'); | |
666 | ||
667 | $content = new Entry($user); | |
668 | $content->setUrl('http://1.1.1.1/entry'); | |
669 | $content->setReadingTime(12); | |
670 | $content->setDomainName('domain.io'); | |
671 | $content->setMimetype('text/html'); | |
672 | $content->setTitle('test title entry'); | |
673 | $content->setContent('This is my content /o/'); | |
7975395d | 674 | $content->updateArchived(true); |
2863bf2a JB |
675 | $content->setLanguage('fr'); |
676 | ||
ac8cf632 JB |
677 | $em->persist($content); |
678 | $em->flush(); | |
2863bf2a | 679 | |
f808b016 JB |
680 | $client->request('GET', '/view/' . $content->getId()); |
681 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
2863bf2a | 682 | |
f808b016 JB |
683 | $client->request('GET', '/delete/' . $content->getId()); |
684 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
2863bf2a JB |
685 | |
686 | $client->followRedirect(); | |
f808b016 | 687 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
2863bf2a JB |
688 | } |
689 | ||
3d2b2d62 J |
690 | public function testViewOtherUserEntry() |
691 | { | |
159986c4 | 692 | $this->logInAs('admin'); |
3d2b2d62 J |
693 | $client = $this->getClient(); |
694 | ||
695 | $content = $client->getContainer() | |
696 | ->get('doctrine.orm.entity_manager') | |
697 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 698 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 699 | |
f808b016 | 700 | $client->request('GET', '/view/' . $content->getId()); |
3d2b2d62 | 701 | |
f808b016 | 702 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
3d2b2d62 | 703 | } |
26864574 | 704 | |
3f357ee2 | 705 | public function testFilterOnReadingTime() |
26864574 NL |
706 | { |
707 | $this->logInAs('admin'); | |
708 | $client = $this->getClient(); | |
7ab5eb95 | 709 | $entry = new Entry($this->getLoggedInUser()); |
710 | $entry->setUrl($this->url); | |
711 | $entry->setReadingTime(22); | |
712 | $this->getEntityManager()->persist($entry); | |
713 | $this->getEntityManager()->flush(); | |
26864574 NL |
714 | |
715 | $crawler = $client->request('GET', '/unread/list'); | |
716 | ||
717 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
718 | ||
4094ea47 | 719 | $data = [ |
d6a9e139 NL |
720 | 'entry_filter[readingTime][right_number]' => 22, |
721 | 'entry_filter[readingTime][left_number]' => 22, | |
4094ea47 | 722 | ]; |
26864574 NL |
723 | |
724 | $crawler = $client->submit($form, $data); | |
725 | ||
ef81e3c8 | 726 | $this->assertCount(1, $crawler->filter('li.entry')); |
26864574 | 727 | } |
ab2c93c7 | 728 | |
1b164717 JB |
729 | public function testFilterOnReadingTimeWithNegativeValue() |
730 | { | |
731 | $this->logInAs('admin'); | |
732 | $client = $this->getClient(); | |
733 | ||
734 | $crawler = $client->request('GET', '/unread/list'); | |
735 | ||
736 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
737 | ||
738 | $data = [ | |
739 | 'entry_filter[readingTime][right_number]' => -22, | |
740 | 'entry_filter[readingTime][left_number]' => -22, | |
741 | ]; | |
742 | ||
743 | $crawler = $client->submit($form, $data); | |
744 | ||
745 | // forcing negative value results in no entry displayed | |
ef81e3c8 | 746 | $this->assertCount(0, $crawler->filter('li.entry')); |
1b164717 JB |
747 | } |
748 | ||
95859e54 JB |
749 | public function testFilterOnReadingTimeOnlyUpper() |
750 | { | |
751 | $this->logInAs('admin'); | |
752 | $client = $this->getClient(); | |
753 | ||
7ab5eb95 | 754 | $crawler = $client->request('GET', '/all/list'); |
ef81e3c8 | 755 | $this->assertCount(5, $crawler->filter('li.entry')); |
7ab5eb95 | 756 | |
757 | $entry = new Entry($this->getLoggedInUser()); | |
758 | $entry->setUrl($this->url); | |
759 | $entry->setReadingTime(23); | |
760 | $this->getEntityManager()->persist($entry); | |
761 | $this->getEntityManager()->flush(); | |
762 | ||
763 | $crawler = $client->request('GET', '/all/list'); | |
ef81e3c8 | 764 | $this->assertCount(6, $crawler->filter('li.entry')); |
95859e54 JB |
765 | |
766 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
767 | ||
768 | $data = [ | |
769 | 'entry_filter[readingTime][right_number]' => 22, | |
770 | ]; | |
771 | ||
772 | $crawler = $client->submit($form, $data); | |
773 | ||
ef81e3c8 | 774 | $this->assertCount(5, $crawler->filter('li.entry')); |
95859e54 JB |
775 | } |
776 | ||
777 | public function testFilterOnReadingTimeOnlyLower() | |
778 | { | |
779 | $this->logInAs('admin'); | |
780 | $client = $this->getClient(); | |
781 | ||
782 | $crawler = $client->request('GET', '/unread/list'); | |
783 | ||
784 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
785 | ||
786 | $data = [ | |
787 | 'entry_filter[readingTime][left_number]' => 22, | |
788 | ]; | |
789 | ||
790 | $crawler = $client->submit($form, $data); | |
791 | ||
ef81e3c8 | 792 | $this->assertCount(0, $crawler->filter('li.entry')); |
7ab5eb95 | 793 | |
794 | $entry = new Entry($this->getLoggedInUser()); | |
795 | $entry->setUrl($this->url); | |
796 | $entry->setReadingTime(23); | |
797 | $this->getEntityManager()->persist($entry); | |
798 | $this->getEntityManager()->flush(); | |
799 | ||
800 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 801 | $this->assertCount(1, $crawler->filter('li.entry')); |
95859e54 JB |
802 | } |
803 | ||
30334567 DB |
804 | public function testFilterOnUnreadStatus() |
805 | { | |
806 | $this->logInAs('admin'); | |
807 | $client = $this->getClient(); | |
808 | ||
809 | $crawler = $client->request('GET', '/all/list'); | |
810 | ||
811 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
812 | ||
813 | $data = [ | |
814 | 'entry_filter[isUnread]' => true, | |
815 | ]; | |
816 | ||
817 | $crawler = $client->submit($form, $data); | |
818 | ||
ef81e3c8 | 819 | $this->assertCount(4, $crawler->filter('li.entry')); |
7ab5eb95 | 820 | |
821 | $entry = new Entry($this->getLoggedInUser()); | |
822 | $entry->setUrl($this->url); | |
7975395d | 823 | $entry->updateArchived(false); |
7ab5eb95 | 824 | $this->getEntityManager()->persist($entry); |
825 | $this->getEntityManager()->flush(); | |
826 | ||
827 | $crawler = $client->submit($form, $data); | |
828 | ||
ef81e3c8 | 829 | $this->assertCount(5, $crawler->filter('li.entry')); |
30334567 DB |
830 | } |
831 | ||
3f357ee2 NL |
832 | public function testFilterOnCreationDate() |
833 | { | |
834 | $this->logInAs('admin'); | |
835 | $client = $this->getClient(); | |
836 | ||
8ee7b160 KD |
837 | $em = $this->getEntityManager(); |
838 | ||
839 | $today = new \DateTimeImmutable(); | |
840 | $tomorrow = $today->add(new \DateInterval('P1D')); | |
841 | $yesterday = $today->sub(new \DateInterval('P1D')); | |
842 | ||
843 | $entry = new Entry($this->getLoggedInUser()); | |
844 | $entry->setUrl('http://0.0.0.0/testFilterOnCreationDate'); | |
845 | $entry->setCreatedAt($yesterday); | |
846 | $em->persist($entry); | |
847 | $em->flush(); | |
848 | ||
3f357ee2 NL |
849 | $crawler = $client->request('GET', '/unread/list'); |
850 | ||
851 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
852 | ||
4094ea47 | 853 | $data = [ |
8ee7b160 KD |
854 | 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), |
855 | 'entry_filter[createdAt][right_date]' => $tomorrow->format('Y-m-d'), | |
4094ea47 | 856 | ]; |
3f357ee2 NL |
857 | |
858 | $crawler = $client->submit($form, $data); | |
859 | ||
ef81e3c8 | 860 | $this->assertCount(5, $crawler->filter('li.entry')); |
3f357ee2 | 861 | |
4094ea47 | 862 | $data = [ |
8ee7b160 KD |
863 | 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), |
864 | 'entry_filter[createdAt][right_date]' => $today->format('Y-m-d'), | |
4094ea47 | 865 | ]; |
f90af145 JB |
866 | |
867 | $crawler = $client->submit($form, $data); | |
868 | ||
ef81e3c8 | 869 | $this->assertCount(5, $crawler->filter('li.entry')); |
f90af145 | 870 | |
4094ea47 | 871 | $data = [ |
8ee7b160 KD |
872 | 'entry_filter[createdAt][left_date]' => '1970-01-01', |
873 | 'entry_filter[createdAt][right_date]' => '1970-01-01', | |
4094ea47 | 874 | ]; |
3f357ee2 NL |
875 | |
876 | $crawler = $client->submit($form, $data); | |
877 | ||
ef81e3c8 | 878 | $this->assertCount(0, $crawler->filter('li.entry')); |
3f357ee2 NL |
879 | } |
880 | ||
ab2c93c7 NL |
881 | public function testPaginationWithFilter() |
882 | { | |
883 | $this->logInAs('admin'); | |
884 | $client = $this->getClient(); | |
ab2c93c7 NL |
885 | $crawler = $client->request('GET', '/config'); |
886 | ||
887 | $form = $crawler->filter('button[id=config_save]')->form(); | |
888 | ||
4094ea47 | 889 | $data = [ |
ab2c93c7 | 890 | 'config[items_per_page]' => '1', |
4094ea47 | 891 | ]; |
ab2c93c7 NL |
892 | |
893 | $client->submit($form, $data); | |
894 | ||
76cd8dbb | 895 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
ab2c93c7 | 896 | |
f808b016 | 897 | $client->request('GET', 'unread/list' . $parameters); |
ab2c93c7 NL |
898 | |
899 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
900 | |
901 | // reset pagination | |
902 | $crawler = $client->request('GET', '/config'); | |
903 | $form = $crawler->filter('button[id=config_save]')->form(); | |
4094ea47 | 904 | $data = [ |
e1779760 | 905 | 'config[items_per_page]' => '12', |
4094ea47 | 906 | ]; |
e1779760 | 907 | $client->submit($form, $data); |
ab2c93c7 | 908 | } |
443cecd2 NL |
909 | |
910 | public function testFilterOnDomainName() | |
911 | { | |
912 | $this->logInAs('admin'); | |
913 | $client = $this->getClient(); | |
914 | ||
915 | $crawler = $client->request('GET', '/unread/list'); | |
916 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 917 | $data = [ |
02d17813 | 918 | 'entry_filter[domainName]' => 'domain', |
4094ea47 | 919 | ]; |
443cecd2 NL |
920 | |
921 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 922 | $this->assertCount(5, $crawler->filter('li.entry')); |
443cecd2 | 923 | |
00fc2b44 KD |
924 | $crawler = $client->request('GET', '/unread/list'); |
925 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
926 | $data = [ | |
927 | 'entry_filter[domainName]' => 'dOmain', | |
928 | ]; | |
929 | ||
930 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 931 | $this->assertCount(5, $crawler->filter('li.entry')); |
00fc2b44 | 932 | |
443cecd2 | 933 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
4094ea47 | 934 | $data = [ |
8ce32af6 | 935 | 'entry_filter[domainName]' => 'wallabag', |
4094ea47 | 936 | ]; |
443cecd2 NL |
937 | |
938 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 939 | $this->assertCount(0, $crawler->filter('li.entry')); |
443cecd2 | 940 | } |
e1779760 NL |
941 | |
942 | public function testFilterOnStatus() | |
943 | { | |
944 | $this->logInAs('admin'); | |
945 | $client = $this->getClient(); | |
946 | ||
947 | $crawler = $client->request('GET', '/unread/list'); | |
948 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
949 | $form['entry_filter[isArchived]']->tick(); | |
950 | $form['entry_filter[isStarred]']->untick(); | |
951 | ||
952 | $crawler = $client->submit($form); | |
ef81e3c8 | 953 | $this->assertCount(1, $crawler->filter('li.entry')); |
e1779760 NL |
954 | |
955 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
956 | $form['entry_filter[isArchived]']->untick(); | |
957 | $form['entry_filter[isStarred]']->tick(); | |
958 | ||
959 | $crawler = $client->submit($form); | |
ef81e3c8 | 960 | $this->assertCount(1, $crawler->filter('li.entry')); |
e1779760 | 961 | } |
497e0cad | 962 | |
e8911f7c JB |
963 | public function testFilterOnIsPublic() |
964 | { | |
965 | $this->logInAs('admin'); | |
e8911f7c JB |
966 | $client = $this->getClient(); |
967 | ||
968 | $crawler = $client->request('GET', '/unread/list'); | |
969 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
970 | $form['entry_filter[isPublic]']->tick(); | |
971 | ||
972 | $crawler = $client->submit($form); | |
ef81e3c8 | 973 | $this->assertCount(0, $crawler->filter('li.entry')); |
e8911f7c JB |
974 | } |
975 | ||
497e0cad NL |
976 | public function testPreviewPictureFilter() |
977 | { | |
978 | $this->logInAs('admin'); | |
979 | $client = $this->getClient(); | |
980 | ||
981 | $crawler = $client->request('GET', '/unread/list'); | |
982 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
983 | $form['entry_filter[previewPicture]']->tick(); | |
984 | ||
985 | $crawler = $client->submit($form); | |
ef81e3c8 | 986 | $this->assertCount(1, $crawler->filter('li.entry')); |
497e0cad | 987 | } |
d4ebe5c5 JB |
988 | |
989 | public function testFilterOnLanguage() | |
990 | { | |
991 | $this->logInAs('admin'); | |
992 | $client = $this->getClient(); | |
993 | ||
7ab5eb95 | 994 | $entry = new Entry($this->getLoggedInUser()); |
995 | $entry->setUrl($this->url); | |
996 | $entry->setLanguage('fr'); | |
997 | $this->getEntityManager()->persist($entry); | |
998 | $this->getEntityManager()->flush(); | |
999 | ||
d4ebe5c5 JB |
1000 | $crawler = $client->request('GET', '/unread/list'); |
1001 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 1002 | $data = [ |
159986c4 | 1003 | 'entry_filter[language]' => 'fr', |
4094ea47 | 1004 | ]; |
d4ebe5c5 JB |
1005 | |
1006 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 1007 | $this->assertCount(3, $crawler->filter('li.entry')); |
d4ebe5c5 JB |
1008 | |
1009 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 1010 | $data = [ |
d4ebe5c5 | 1011 | 'entry_filter[language]' => 'en', |
4094ea47 | 1012 | ]; |
d4ebe5c5 JB |
1013 | |
1014 | $crawler = $client->submit($form, $data); | |
ef81e3c8 | 1015 | $this->assertCount(2, $crawler->filter('li.entry')); |
d4ebe5c5 | 1016 | } |
a7e2218e | 1017 | |
074110ca NL |
1018 | public function testSortOnTitle() |
1019 | { | |
1020 | $this->logInAs('admin'); | |
1021 | $client = $this->getClient(); | |
1022 | ||
1023 | $crawler = $client->request('GET', '/unread/list'); | |
1024 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1025 | $data = [ | |
1026 | 'entry_sort[sortType]' => 'title', | |
1027 | 'entry_sort[sortOrder]' => 'asc', | |
1028 | ]; | |
1029 | $crawler = $client->submit($form, $data); | |
1030 | ||
1031 | $this->assertCount(4, $crawler->filter('li.entry')); | |
1032 | ||
1033 | $matches = []; | |
1034 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1035 | ||
1036 | $results = array_values(array_unique($matches[0])); | |
1037 | ||
1038 | $ids = [1, 2, 4, 5]; | |
1039 | ||
1040 | foreach ($results as $key => $result) { | |
1041 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1042 | } | |
1043 | ||
76459e56 | 1044 | $ids = array_reverse($ids); |
074110ca NL |
1045 | |
1046 | $crawler = $client->request('GET', '/unread/list'); | |
1047 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1048 | $data = [ | |
1049 | 'entry_sort[sortType]' => 'title', | |
1050 | 'entry_sort[sortOrder]' => 'desc', | |
1051 | ]; | |
1052 | $crawler = $client->submit($form, $data); | |
1053 | ||
1054 | $matches = []; | |
1055 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1056 | ||
1057 | $results = array_values(array_unique($matches[0])); | |
1058 | ||
1059 | foreach ($results as $key => $result) { | |
1060 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1061 | } | |
1062 | } | |
1063 | ||
76459e56 NL |
1064 | public function testSortOnCreationDate() |
1065 | { | |
1066 | $this->logInAs('admin'); | |
1067 | $client = $this->getClient(); | |
1068 | ||
1069 | $entry1 = new Entry($this->getLoggedInUser()); | |
1070 | $entry1->setTitle('test title entry7'); | |
1071 | $entry1->setCreatedAt(new \DateTime('2013-04-03T13:37:00')); | |
1072 | $this->getEntityManager()->persist($entry1); | |
1073 | ||
1074 | $entry2 = new Entry($this->getLoggedInUser()); | |
1075 | $entry2->setTitle('test title entry8'); | |
1076 | $entry2->setCreatedAt(new \DateTime('2012-04-03T13:37:00')); | |
1077 | $this->getEntityManager()->persist($entry2); | |
1078 | ||
1079 | $entry3 = new Entry($this->getLoggedInUser()); | |
1080 | $entry3->setTitle('test title entry9'); | |
1081 | $entry3->setCreatedAt(new \DateTime('2014-04-03T13:37:00')); | |
1082 | $this->getEntityManager()->persist($entry3); | |
1083 | ||
1084 | $this->getEntityManager()->flush(); | |
1085 | ||
1086 | $crawler = $client->request('GET', '/unread/list'); | |
1087 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1088 | $data = [ | |
1089 | 'entry_sort[sortType]' => 'createdAt', | |
1090 | 'entry_sort[sortOrder]' => 'asc', | |
1091 | ]; | |
1092 | $crawler = $client->submit($form, $data); | |
1093 | ||
1094 | $this->assertCount(7, $crawler->filter('li.entry')); | |
1095 | ||
1096 | $matches = []; | |
1097 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1098 | ||
1099 | $results = array_values(array_unique($matches[0])); | |
1100 | ||
1101 | $ids = [8, 7, 9, 1, 2, 4, 5]; | |
1102 | ||
1103 | foreach ($results as $key => $result) { | |
1104 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1105 | } | |
1106 | ||
1107 | $ids = array_reverse($ids); | |
1108 | ||
1109 | $crawler = $client->request('GET', '/unread/list'); | |
1110 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1111 | $data = [ | |
1112 | 'entry_sort[sortType]' => 'createdAt', | |
1113 | 'entry_sort[sortOrder]' => 'desc', | |
1114 | ]; | |
1115 | $crawler = $client->submit($form, $data); | |
1116 | ||
1117 | $matches = []; | |
1118 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1119 | ||
1120 | $results = array_values(array_unique($matches[0])); | |
1121 | ||
1122 | foreach ($results as $key => $result) { | |
1123 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | public function testSortOnStarredDate() | |
1128 | { | |
1129 | $this->logInAs('admin'); | |
1130 | $client = $this->getClient(); | |
1131 | ||
1132 | $entry1 = new Entry($this->getLoggedInUser()); | |
1133 | $entry1->setTitle('test title entry7'); | |
1134 | $entry1->setStarred(true); | |
1135 | $entry1->setStarredAt(new \DateTime('2013-04-03T13:37:00')); | |
1136 | $this->getEntityManager()->persist($entry1); | |
1137 | ||
1138 | $entry2 = new Entry($this->getLoggedInUser()); | |
1139 | $entry2->setTitle('test title entry8'); | |
1140 | $entry2->setStarred(true); | |
1141 | $entry2->setStarredAt(new \DateTime('2012-04-03T13:37:00')); | |
1142 | $this->getEntityManager()->persist($entry2); | |
1143 | ||
1144 | $entry3 = new Entry($this->getLoggedInUser()); | |
1145 | $entry3->setTitle('test title entry9'); | |
1146 | $entry3->setStarred(true); | |
1147 | $entry3->setStarredAt(new \DateTime('2014-04-03T13:37:00')); | |
1148 | $this->getEntityManager()->persist($entry3); | |
1149 | ||
1150 | $this->getEntityManager()->flush(); | |
1151 | ||
1152 | $crawler = $client->request('GET', '/starred/list'); | |
1153 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1154 | $data = [ | |
1155 | 'entry_sort[sortType]' => 'starredAt', | |
1156 | 'entry_sort[sortOrder]' => 'asc', | |
1157 | ]; | |
1158 | $crawler = $client->submit($form, $data); | |
1159 | ||
1160 | $this->assertCount(4, $crawler->filter('li.entry')); | |
1161 | ||
1162 | $matches = []; | |
1163 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1164 | ||
1165 | $results = array_values(array_unique($matches[0])); | |
1166 | ||
82cee42b | 1167 | $ids = [8, 7, 9, 5]; |
76459e56 NL |
1168 | |
1169 | foreach ($results as $key => $result) { | |
1170 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1171 | } | |
1172 | ||
1173 | $ids = array_reverse($ids); | |
1174 | ||
1175 | $crawler = $client->request('GET', '/starred/list'); | |
1176 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1177 | $data = [ | |
1178 | 'entry_sort[sortType]' => 'starredAt', | |
1179 | 'entry_sort[sortOrder]' => 'desc', | |
1180 | ]; | |
1181 | $crawler = $client->submit($form, $data); | |
1182 | ||
1183 | $matches = []; | |
1184 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1185 | ||
1186 | $results = array_values(array_unique($matches[0])); | |
1187 | ||
1188 | foreach ($results as $key => $result) { | |
1189 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1190 | } | |
1191 | } | |
1192 | ||
1193 | public function testSortOnArchivedDate() | |
1194 | { | |
1195 | $this->logInAs('admin'); | |
1196 | $client = $this->getClient(); | |
1197 | ||
1198 | $entry1 = new Entry($this->getLoggedInUser()); | |
1199 | $entry1->setTitle('test title entry7'); | |
1200 | $entry1->setArchived(true); | |
1201 | $entry1->setArchivedAt(new \DateTime('2010-04-03T13:37:00')); | |
1202 | $this->getEntityManager()->persist($entry1); | |
1203 | ||
1204 | $entry2 = new Entry($this->getLoggedInUser()); | |
1205 | $entry2->setTitle('test title entry8'); | |
1206 | $entry2->setArchived(true); | |
1207 | $entry2->setArchivedAt(new \DateTime('2000-04-03T13:37:00')); | |
1208 | $this->getEntityManager()->persist($entry2); | |
1209 | ||
1210 | $entry3 = new Entry($this->getLoggedInUser()); | |
1211 | $entry3->setTitle('test title entry9'); | |
1212 | $entry3->setArchived(true); | |
1213 | $entry3->setArchivedAt(new \DateTime('2020-04-03T13:37:00')); | |
1214 | $this->getEntityManager()->persist($entry3); | |
1215 | ||
1216 | $this->getEntityManager()->flush(); | |
1217 | ||
1218 | $crawler = $client->request('GET', '/archive/list'); | |
1219 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1220 | $data = [ | |
1221 | 'entry_sort[sortType]' => 'archivedAt', | |
1222 | 'entry_sort[sortOrder]' => 'asc', | |
1223 | ]; | |
1224 | $crawler = $client->submit($form, $data); | |
1225 | ||
1226 | $this->assertCount(4, $crawler->filter('li.entry')); | |
1227 | ||
1228 | $matches = []; | |
1229 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1230 | ||
1231 | $results = array_values(array_unique($matches[0])); | |
1232 | ||
82cee42b | 1233 | $ids = [8, 7, 9, 6]; |
76459e56 NL |
1234 | |
1235 | foreach ($results as $key => $result) { | |
1236 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1237 | } | |
1238 | ||
1239 | $ids = array_reverse($ids); | |
1240 | ||
1241 | $crawler = $client->request('GET', '/archive/list'); | |
1242 | $form = $crawler->filter('button[id=submit-sort]')->form(); | |
1243 | $data = [ | |
1244 | 'entry_sort[sortType]' => 'archivedAt', | |
1245 | 'entry_sort[sortOrder]' => 'desc', | |
1246 | ]; | |
1247 | $crawler = $client->submit($form, $data); | |
1248 | ||
1249 | $matches = []; | |
1250 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | |
1251 | ||
1252 | $results = array_values(array_unique($matches[0])); | |
1253 | ||
1254 | foreach ($results as $key => $result) { | |
1255 | $this->assertSame('test title entry' . $ids[$key], $result); | |
1256 | } | |
1257 | } | |
1258 | ||
21d82c3c | 1259 | public function testShareEntryPublicly() |
a7e2218e NL |
1260 | { |
1261 | $this->logInAs('admin'); | |
1262 | $client = $this->getClient(); | |
1263 | ||
7ab5eb95 | 1264 | // sharing is enabled |
1265 | $client->getContainer()->get('craue_config')->set('share_public', 1); | |
1266 | ||
1267 | $content = new Entry($this->getLoggedInUser()); | |
1268 | $content->setUrl($this->url); | |
1269 | $this->getEntityManager()->persist($content); | |
1270 | $this->getEntityManager()->flush(); | |
1271 | $this->getEntityManager()->clear(); | |
a7e2218e | 1272 | |
7239082a | 1273 | // no uid |
f808b016 JB |
1274 | $client->request('GET', '/share/' . $content->getUid()); |
1275 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
eddda878 | 1276 | |
7239082a | 1277 | // generating the uid |
f808b016 JB |
1278 | $client->request('GET', '/share/' . $content->getId()); |
1279 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
eddda878 | 1280 | |
115de64e JB |
1281 | $shareUrl = $client->getResponse()->getTargetUrl(); |
1282 | ||
1283 | // use a new client to have a fresh empty session (instead of a logged one from the previous client) | |
1284 | $client->restart(); | |
1285 | ||
1286 | $client->request('GET', $shareUrl); | |
1287 | ||
f808b016 | 1288 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
eddda878 JB |
1289 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); |
1290 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
1291 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
a7e2218e | 1292 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
21d82c3c NL |
1293 | $this->assertContains('og:title', $client->getResponse()->getContent()); |
1294 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
1295 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
d5c45d52 | 1296 | $this->assertContains('og:image', $client->getResponse()->getContent()); |
a7e2218e | 1297 | |
eddda878 JB |
1298 | // sharing is now disabled |
1299 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
f808b016 JB |
1300 | $client->request('GET', '/share/' . $content->getUid()); |
1301 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
eddda878 | 1302 | |
eddda878 | 1303 | // removing the share |
f808b016 JB |
1304 | $client->request('GET', '/share/delete/' . $content->getId()); |
1305 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
eddda878 JB |
1306 | |
1307 | // share is now disable | |
f808b016 JB |
1308 | $client->request('GET', '/share/' . $content->getUid()); |
1309 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
a7e2218e | 1310 | } |
d1495dd0 | 1311 | |
71f7e58f KD |
1312 | /** |
1313 | * @group NetworkCalls | |
1314 | */ | |
d1495dd0 JB |
1315 | public function testNewEntryWithDownloadImagesEnabled() |
1316 | { | |
be085c3d | 1317 | $this->downloadImagesEnabled = true; |
d1495dd0 JB |
1318 | $this->logInAs('admin'); |
1319 | $client = $this->getClient(); | |
1320 | ||
26e2f074 | 1321 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; |
d1495dd0 JB |
1322 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
1323 | ||
1324 | $crawler = $client->request('GET', '/new'); | |
1325 | ||
f808b016 | 1326 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1327 | |
1328 | $form = $crawler->filter('form[name=entry]')->form(); | |
1329 | ||
1330 | $data = [ | |
1331 | 'entry[url]' => $url, | |
1332 | ]; | |
1333 | ||
1334 | $client->submit($form, $data); | |
1335 | ||
f808b016 | 1336 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1337 | |
1338 | $em = $client->getContainer() | |
1339 | ->get('doctrine.orm.entity_manager'); | |
1340 | ||
1341 | $entry = $em | |
1342 | ->getRepository('WallabagCoreBundle:Entry') | |
1343 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1344 | ||
1345 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
f808b016 | 1346 | $this->assertSame($url, $entry->getUrl()); |
d81bf605 | 1347 | $this->assertContains('Judo', $entry->getTitle()); |
be085c3d | 1348 | // instead of checking for the filename (which might change) check that the image is now local |
d81bf605 | 1349 | $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent()); |
d1495dd0 | 1350 | |
e0597476 JB |
1351 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
1352 | } | |
1353 | ||
1354 | /** | |
1355 | * @depends testNewEntryWithDownloadImagesEnabled | |
1356 | */ | |
1357 | public function testRemoveEntryWithDownloadImagesEnabled() | |
1358 | { | |
be085c3d | 1359 | $this->downloadImagesEnabled = true; |
e0597476 JB |
1360 | $this->logInAs('admin'); |
1361 | $client = $this->getClient(); | |
1362 | ||
26e2f074 | 1363 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; |
e0597476 JB |
1364 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
1365 | ||
7ab5eb95 | 1366 | $crawler = $client->request('GET', '/new'); |
1367 | ||
f808b016 | 1368 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
7ab5eb95 | 1369 | |
1370 | $form = $crawler->filter('form[name=entry]')->form(); | |
1371 | ||
1372 | $data = [ | |
1373 | 'entry[url]' => $url, | |
1374 | ]; | |
1375 | ||
1376 | $client->submit($form, $data); | |
1377 | ||
f808b016 | 1378 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
7ab5eb95 | 1379 | |
e0597476 JB |
1380 | $content = $client->getContainer() |
1381 | ->get('doctrine.orm.entity_manager') | |
1382 | ->getRepository('WallabagCoreBundle:Entry') | |
1383 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1384 | ||
f808b016 | 1385 | $client->request('GET', '/delete/' . $content->getId()); |
e0597476 | 1386 | |
f808b016 | 1387 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1388 | |
1389 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
1390 | } | |
65cd8a4a NL |
1391 | |
1392 | public function testRedirectToHomepage() | |
1393 | { | |
1394 | $this->logInAs('empty'); | |
1395 | $client = $this->getClient(); | |
1396 | ||
65cd8a4a | 1397 | // Redirect to homepage |
7ab5eb95 | 1398 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1399 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
7ab5eb95 | 1400 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1401 | |
7ab5eb95 | 1402 | $entry = new Entry($this->getLoggedInUser()); |
1403 | $entry->setUrl($this->url); | |
1404 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1405 | |
7ab5eb95 | 1406 | $this->getEntityManager()->flush(); |
1407 | ||
f808b016 JB |
1408 | $client->request('GET', '/view/' . $entry->getId()); |
1409 | $client->request('GET', '/archive/' . $entry->getId()); | |
65cd8a4a | 1410 | |
f808b016 JB |
1411 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
1412 | $this->assertSame('/', $client->getResponse()->headers->get('location')); | |
65cd8a4a NL |
1413 | } |
1414 | ||
1415 | public function testRedirectToCurrentPage() | |
1416 | { | |
1417 | $this->logInAs('empty'); | |
1418 | $client = $this->getClient(); | |
1419 | ||
65cd8a4a | 1420 | // Redirect to current page |
7ab5eb95 | 1421 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1422 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
7ab5eb95 | 1423 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1424 | |
7ab5eb95 | 1425 | $entry = new Entry($this->getLoggedInUser()); |
1426 | $entry->setUrl($this->url); | |
1427 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1428 | |
7ab5eb95 | 1429 | $this->getEntityManager()->flush(); |
1430 | ||
f808b016 JB |
1431 | $client->request('GET', '/view/' . $entry->getId()); |
1432 | $client->request('GET', '/archive/' . $entry->getId()); | |
65cd8a4a | 1433 | |
f808b016 JB |
1434 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
1435 | $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location')); | |
65cd8a4a | 1436 | } |
10b35097 NL |
1437 | |
1438 | public function testFilterOnHttpStatus() | |
1439 | { | |
1440 | $this->logInAs('admin'); | |
1441 | $client = $this->getClient(); | |
1442 | ||
7ab5eb95 | 1443 | $entry = new Entry($this->getLoggedInUser()); |
77854331 | 1444 | $entry->setUrl('https://www.lemonde.fr/incorrect-url/'); |
7ab5eb95 | 1445 | $entry->setHttpStatus(404); |
1446 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1447 | |
7ab5eb95 | 1448 | $this->getEntityManager()->flush(); |
10b35097 NL |
1449 | |
1450 | $crawler = $client->request('GET', '/all/list'); | |
1451 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1452 | ||
1453 | $data = [ | |
1454 | 'entry_filter[httpStatus]' => 404, | |
1455 | ]; | |
1456 | ||
1457 | $crawler = $client->submit($form, $data); | |
1458 | ||
ef81e3c8 | 1459 | $this->assertCount(1, $crawler->filter('li.entry')); |
10b35097 | 1460 | |
7ab5eb95 | 1461 | $entry = new Entry($this->getLoggedInUser()); |
1462 | $entry->setUrl($this->url); | |
1463 | $entry->setHttpStatus(200); | |
1464 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1465 | |
7ab5eb95 | 1466 | $entry = new Entry($this->getLoggedInUser()); |
1467 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); | |
1468 | $entry->setHttpStatus(200); | |
1469 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1470 | |
7ab5eb95 | 1471 | $this->getEntityManager()->flush(); |
10b35097 NL |
1472 | |
1473 | $crawler = $client->request('GET', '/all/list'); | |
1474 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1475 | ||
1476 | $data = [ | |
1477 | 'entry_filter[httpStatus]' => 200, | |
1478 | ]; | |
1479 | ||
1480 | $crawler = $client->submit($form, $data); | |
1481 | ||
ef81e3c8 | 1482 | $this->assertCount(2, $crawler->filter('li.entry')); |
d215273c NL |
1483 | |
1484 | $crawler = $client->request('GET', '/all/list'); | |
1485 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1486 | ||
1487 | $data = [ | |
1488 | 'entry_filter[httpStatus]' => 1024, | |
1489 | ]; | |
1490 | ||
1491 | $crawler = $client->submit($form, $data); | |
1492 | ||
ef81e3c8 | 1493 | $this->assertCount(8, $crawler->filter('li.entry')); |
10b35097 | 1494 | } |
32f455c1 NL |
1495 | |
1496 | public function testSearch() | |
1497 | { | |
1498 | $this->logInAs('admin'); | |
1499 | $client = $this->getClient(); | |
1500 | ||
7ab5eb95 | 1501 | $entry = new Entry($this->getLoggedInUser()); |
1502 | $entry->setUrl($this->url); | |
1503 | $entry->setTitle('test'); | |
1504 | $this->getEntityManager()->persist($entry); | |
1505 | $this->getEntityManager()->flush(); | |
1506 | ||
32f455c1 NL |
1507 | // Search on unread list |
1508 | $crawler = $client->request('GET', '/unread/list'); | |
1509 | ||
1510 | $form = $crawler->filter('form[name=search]')->form(); | |
1511 | $data = [ | |
1512 | 'search_entry[term]' => 'title', | |
1513 | ]; | |
1514 | ||
1515 | $crawler = $client->submit($form, $data); | |
1516 | ||
ef81e3c8 | 1517 | $this->assertCount(4, $crawler->filter('li.entry')); |
32f455c1 NL |
1518 | |
1519 | // Search on starred list | |
1520 | $crawler = $client->request('GET', '/starred/list'); | |
1521 | ||
7ab5eb95 | 1522 | $entry = new Entry($this->getLoggedInUser()); |
1523 | $entry->setUrl('http://localhost/foo/bar'); | |
1524 | $entry->setTitle('testeur'); | |
1525 | $entry->setStarred(true); | |
1526 | $this->getEntityManager()->persist($entry); | |
1527 | $this->getEntityManager()->flush(); | |
1528 | ||
32f455c1 NL |
1529 | $form = $crawler->filter('form[name=search]')->form(); |
1530 | $data = [ | |
7ab5eb95 | 1531 | 'search_entry[term]' => 'testeur', |
32f455c1 NL |
1532 | ]; |
1533 | ||
1534 | $crawler = $client->submit($form, $data); | |
1535 | ||
ef81e3c8 | 1536 | $this->assertCount(1, $crawler->filter('li.entry')); |
32f455c1 | 1537 | |
32f455c1 NL |
1538 | $crawler = $client->request('GET', '/archive/list'); |
1539 | ||
7ab5eb95 | 1540 | // Added new article to test on archive list |
1541 | $entry = new Entry($this->getLoggedInUser()); | |
1542 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | |
1543 | $entry->setTitle('Le manège'); | |
7975395d | 1544 | $entry->updateArchived(true); |
7ab5eb95 | 1545 | $this->getEntityManager()->persist($entry); |
1546 | $this->getEntityManager()->flush(); | |
1547 | ||
32f455c1 NL |
1548 | $form = $crawler->filter('form[name=search]')->form(); |
1549 | $data = [ | |
1550 | 'search_entry[term]' => 'manège', | |
1551 | ]; | |
1552 | ||
1553 | $crawler = $client->submit($form, $data); | |
1554 | ||
ef81e3c8 | 1555 | $this->assertCount(1, $crawler->filter('li.entry')); |
f808b016 | 1556 | $client->request('GET', '/delete/' . $entry->getId()); |
32f455c1 NL |
1557 | |
1558 | // test on list of all articles | |
1559 | $crawler = $client->request('GET', '/all/list'); | |
1560 | ||
1561 | $form = $crawler->filter('form[name=search]')->form(); | |
1562 | $data = [ | |
995c2044 | 1563 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database |
32f455c1 NL |
1564 | ]; |
1565 | ||
1566 | $crawler = $client->submit($form, $data); | |
1567 | ||
ef81e3c8 | 1568 | $this->assertCount(0, $crawler->filter('li.entry')); |
eac09b48 KD |
1569 | |
1570 | // test url search on list of all articles | |
7ab5eb95 | 1571 | $entry = new Entry($this->getLoggedInUser()); |
1572 | $entry->setUrl('http://domain/qux'); | |
1573 | $entry->setTitle('Le manège'); | |
7975395d | 1574 | $entry->updateArchived(true); |
7ab5eb95 | 1575 | $this->getEntityManager()->persist($entry); |
1576 | $this->getEntityManager()->flush(); | |
1577 | ||
eac09b48 KD |
1578 | $crawler = $client->request('GET', '/all/list'); |
1579 | ||
1580 | $form = $crawler->filter('form[name=search]')->form(); | |
1581 | $data = [ | |
1582 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1583 | ]; | |
1584 | ||
1585 | $crawler = $client->submit($form, $data); | |
1586 | ||
ef81e3c8 | 1587 | $this->assertCount(1, $crawler->filter('li.entry')); |
eac09b48 KD |
1588 | |
1589 | // same as previous test but for case-sensitivity | |
1590 | $crawler = $client->request('GET', '/all/list'); | |
1591 | ||
1592 | $form = $crawler->filter('form[name=search]')->form(); | |
1593 | $data = [ | |
1594 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1595 | ]; | |
1596 | ||
1597 | $crawler = $client->submit($form, $data); | |
1598 | ||
ef81e3c8 | 1599 | $this->assertCount(1, $crawler->filter('li.entry')); |
32f455c1 | 1600 | } |
42f3bb2c JB |
1601 | |
1602 | public function dataForLanguage() | |
1603 | { | |
1604 | return [ | |
1605 | 'ru' => [ | |
1606 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | |
1607 | 'ru', | |
1608 | ], | |
739a4024 FB |
1609 | 'fr' => [ |
1610 | 'https://fr.wikipedia.org/wiki/Wallabag', | |
1611 | 'fr', | |
42f3bb2c JB |
1612 | ], |
1613 | 'de' => [ | |
3be96dcb | 1614 | 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', |
42f3bb2c JB |
1615 | 'de', |
1616 | ], | |
1617 | 'it' => [ | |
3cd659fc | 1618 | 'https://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', |
42f3bb2c JB |
1619 | 'it', |
1620 | ], | |
1621 | 'zh_CN' => [ | |
1622 | 'http://www.hao123.com/shequ?__noscript__-=1', | |
1623 | 'zh_CN', | |
1624 | ], | |
42f3bb2c | 1625 | 'pt_BR' => [ |
4408ebd4 | 1626 | 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', |
42f3bb2c JB |
1627 | 'pt_BR', |
1628 | ], | |
80e49ba7 | 1629 | 'fucked_list_of_languages' => [ |
42f3bb2c | 1630 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', |
38520658 | 1631 | null, |
42f3bb2c | 1632 | ], |
80e49ba7 | 1633 | 'es-ES' => [ |
77854331 | 1634 | 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', |
987237d5 | 1635 | 'es_ES', |
80e49ba7 | 1636 | ], |
42f3bb2c JB |
1637 | ]; |
1638 | } | |
1639 | ||
1640 | /** | |
1641 | * @dataProvider dataForLanguage | |
71f7e58f | 1642 | * @group NetworkCalls |
42f3bb2c JB |
1643 | */ |
1644 | public function testLanguageValidation($url, $expectedLanguage) | |
1645 | { | |
1646 | $this->logInAs('admin'); | |
1647 | $client = $this->getClient(); | |
1648 | ||
1649 | $crawler = $client->request('GET', '/new'); | |
1650 | ||
f808b016 | 1651 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
42f3bb2c JB |
1652 | |
1653 | $form = $crawler->filter('form[name=entry]')->form(); | |
1654 | ||
1655 | $data = [ | |
1656 | 'entry[url]' => $url, | |
1657 | ]; | |
1658 | ||
1659 | $client->submit($form, $data); | |
1660 | ||
f808b016 | 1661 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
42f3bb2c JB |
1662 | |
1663 | $content = $client->getContainer() | |
1664 | ->get('doctrine.orm.entity_manager') | |
1665 | ->getRepository('WallabagCoreBundle:Entry') | |
1666 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1667 | ||
1668 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
f808b016 JB |
1669 | $this->assertSame($url, $content->getUrl()); |
1670 | $this->assertSame($expectedLanguage, $content->getLanguage()); | |
42f3bb2c | 1671 | } |
9de9f1e5 JB |
1672 | |
1673 | /** | |
71f7e58f | 1674 | * @group NetworkCalls |
9de9f1e5 JB |
1675 | */ |
1676 | public function testRestrictedArticle() | |
1677 | { | |
f645d371 | 1678 | $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475'; |
9de9f1e5 JB |
1679 | $this->logInAs('admin'); |
1680 | $client = $this->getClient(); | |
1681 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1682 | ||
1683 | // enable restricted access | |
1684 | $client->getContainer()->get('craue_config')->set('restricted_access', 1); | |
1685 | ||
1686 | // create a new site_credential | |
1687 | $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
1688 | $credential = new SiteCredential($user); | |
1689 | $credential->setHost('monde-diplomatique.fr'); | |
bead8b42 | 1690 | $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); |
906424c1 | 1691 | $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); |
9de9f1e5 JB |
1692 | |
1693 | $em->persist($credential); | |
1694 | $em->flush(); | |
1695 | ||
1696 | $crawler = $client->request('GET', '/new'); | |
1697 | ||
f808b016 | 1698 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1699 | |
1700 | $form = $crawler->filter('form[name=entry]')->form(); | |
1701 | ||
1702 | $data = [ | |
1703 | 'entry[url]' => $url, | |
1704 | ]; | |
1705 | ||
1706 | $client->submit($form, $data); | |
1707 | ||
f808b016 | 1708 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1709 | |
1710 | $crawler = $client->followRedirect(); | |
1711 | ||
f808b016 | 1712 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1713 | $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); |
1714 | ||
1715 | $content = $em | |
1716 | ->getRepository('WallabagCoreBundle:Entry') | |
1717 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1718 | ||
1719 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
1720 | $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); | |
1721 | ||
1722 | $client->getContainer()->get('craue_config')->set('restricted_access', 0); | |
1723 | } | |
300f293c KD |
1724 | |
1725 | public function testPostEntryWhenFetchFails() | |
1726 | { | |
1727 | $url = 'http://example.com/papers/email_tracking.pdf'; | |
1728 | $this->logInAs('admin'); | |
1729 | $client = $this->getClient(); | |
1730 | ||
1731 | $container = $client->getContainer(); | |
1732 | $contentProxy = $this->getMockBuilder(ContentProxy::class) | |
1733 | ->disableOriginalConstructor() | |
1734 | ->setMethods(['updateEntry']) | |
1735 | ->getMock(); | |
1736 | $contentProxy->expects($this->any()) | |
1737 | ->method('updateEntry') | |
1738 | ->willThrowException(new \Exception('Test Fetch content fails')); | |
1739 | ||
1740 | $crawler = $client->request('GET', '/new'); | |
1741 | ||
1742 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1743 | ||
1744 | $form = $crawler->filter('form[name=entry]')->form(); | |
1745 | ||
1746 | $data = [ | |
1747 | 'entry[url]' => $url, | |
1748 | ]; | |
1749 | ||
1750 | /** | |
1751 | * We generate a new client to be able to use Mock ContentProxy | |
1752 | * Also we reinject the cookie from the previous client to keep the | |
1753 | * session. | |
1754 | */ | |
1755 | $cookie = $client->getCookieJar()->all(); | |
1756 | $client = $this->getNewClient(); | |
1757 | $client->getCookieJar()->set($cookie[0]); | |
1758 | $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy); | |
1759 | $client->submit($form, $data); | |
1760 | ||
1761 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1762 | ||
1763 | $content = $client->getContainer() | |
1764 | ->get('doctrine.orm.entity_manager') | |
1765 | ->getRepository('WallabagCoreBundle:Entry') | |
1766 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1767 | ||
1768 | $authors = $content->getPublishedBy(); | |
1769 | $this->assertSame('email_tracking.pdf', $content->getTitle()); | |
1770 | $this->assertSame('example.com', $content->getDomainName()); | |
1771 | } | |
e0a862b6 KD |
1772 | |
1773 | public function testEntryDeleteTagLink() | |
1774 | { | |
1775 | $this->logInAs('admin'); | |
1776 | $client = $this->getClient(); | |
1777 | ||
1778 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1779 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | |
1780 | $tag = $entry->getTags()[0]; | |
1781 | ||
1782 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | |
1783 | ||
1784 | // As long as the deletion link of a tag is following | |
1785 | // a link to the tag view, we take the second one to retrieve | |
1786 | // the deletion link of the first tag | |
1787 | $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1]; | |
1788 | ||
1789 | $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); | |
1790 | } | |
0447a75b JB |
1791 | |
1792 | public function testRandom() | |
1793 | { | |
1794 | $this->logInAs('admin'); | |
1795 | $client = $this->getClient(); | |
1796 | ||
1797 | $client->request('GET', '/unread/random'); | |
1798 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1799 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random'); | |
1800 | ||
1801 | $client->request('GET', '/starred/random'); | |
1802 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1803 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random'); | |
1804 | ||
1805 | $client->request('GET', '/archive/random'); | |
1806 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1807 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random'); | |
1808 | ||
1809 | $client->request('GET', '/untagged/random'); | |
1810 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1811 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random'); | |
1812 | ||
1813 | $client->request('GET', '/all/random'); | |
1814 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1815 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random'); | |
1816 | } | |
46732777 NL |
1817 | |
1818 | public function testMass() | |
1819 | { | |
1820 | $this->logInAs('admin'); | |
1821 | $client = $this->getClient(); | |
1822 | ||
1823 | $entry1 = new Entry($this->getLoggedInUser()); | |
1824 | $entry1->setUrl($this->url); | |
1825 | $this->getEntityManager()->persist($entry1); | |
1826 | ||
1827 | $entry2 = new Entry($this->getLoggedInUser()); | |
1828 | $entry2->setUrl($this->url); | |
1829 | $this->getEntityManager()->persist($entry2); | |
1830 | ||
1831 | $this->getEntityManager()->flush(); | |
1832 | $this->getEntityManager()->clear(); | |
1833 | ||
1834 | $entries = []; | |
1835 | $entries[] = $entry1->getId(); | |
1836 | $entries[] = $entry2->getId(); | |
1837 | ||
1838 | // Mass actions : archive | |
1839 | $client->request('POST', '/mass', [ | |
1840 | 'toggle-archive' => '', | |
1841 | 'entry-checkbox' => $entries, | |
1842 | ]); | |
1843 | ||
1844 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1845 | ||
1846 | $res = $client->getContainer() | |
1847 | ->get('doctrine.orm.entity_manager') | |
1848 | ->getRepository('WallabagCoreBundle:Entry') | |
1849 | ->find($entry1->getId()); | |
1850 | ||
1851 | $this->assertSame(1, $res->isArchived()); | |
1852 | ||
1853 | $res = $client->getContainer() | |
1854 | ->get('doctrine.orm.entity_manager') | |
1855 | ->getRepository('WallabagCoreBundle:Entry') | |
1856 | ->find($entry2->getId()); | |
1857 | ||
1858 | $this->assertSame(1, $res->isArchived()); | |
1859 | ||
1860 | // Mass actions : star | |
1861 | $client->request('POST', '/mass', [ | |
1862 | 'toggle-star' => '', | |
1863 | 'entry-checkbox' => $entries, | |
1864 | ]); | |
1865 | ||
1866 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1867 | ||
1868 | $res = $client->getContainer() | |
1869 | ->get('doctrine.orm.entity_manager') | |
1870 | ->getRepository('WallabagCoreBundle:Entry') | |
1871 | ->find($entry1->getId()); | |
1872 | ||
1873 | $this->assertSame(1, $res->isStarred()); | |
1874 | ||
1875 | $res = $client->getContainer() | |
1876 | ->get('doctrine.orm.entity_manager') | |
1877 | ->getRepository('WallabagCoreBundle:Entry') | |
1878 | ->find($entry2->getId()); | |
1879 | ||
1880 | $this->assertSame(1, $res->isStarred()); | |
1881 | ||
1882 | // Mass actions : delete | |
1883 | $client->request('POST', '/mass', [ | |
1884 | 'delete' => '', | |
1885 | 'entry-checkbox' => $entries, | |
1886 | ]); | |
1887 | ||
1888 | $client->request('GET', '/delete/' . $entry1->getId()); | |
1889 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1890 | ||
1891 | $client->request('GET', '/delete/' . $entry2->getId()); | |
1892 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1893 | } | |
93fd4692 | 1894 | } |