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