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