]>
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; |
77854331 | 16 | public $url = 'https://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'; |
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()); |
a0d6ccc5 | 167 | $this->assertContains('Google', $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 | ||
268 | public function testPostNewOkUrlExistWithRedirection() | |
269 | { | |
270 | $this->logInAs('admin'); | |
271 | $client = $this->getClient(); | |
272 | ||
273 | $url = 'https://wllbg.org/test-redirect/c51c'; | |
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 | ||
f808b016 | 299 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
a0d6ccc5 | 300 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
9c0c8820 J |
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 | 512 | |
5614df19 | 513 | $form = $crawler->filter('button[id=entry_save]')->form(); |
82d6d9cb | 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 | ||
5614df19 | 546 | $form = $crawler->filter('button[id=entry_save]')->form(); |
97444566 KD |
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 | ||
1e0d8ad7 JB |
559 | $title = $crawler->filter('div[id=article] h1')->extract(['_text']); |
560 | $this->assertGreaterThan(1, $title); | |
97444566 | 561 | $this->assertContains('My updated title hehe :)', $title[0]); |
1e0d8ad7 JB |
562 | |
563 | $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']); | |
564 | $this->assertCount(1, $stats); | |
97444566 | 565 | $this->assertNotContains('example.io', trim($stats[0])); |
82d6d9cb JB |
566 | } |
567 | ||
eb3bd7ef J |
568 | public function testToggleArchive() |
569 | { | |
570 | $this->logInAs('admin'); | |
571 | $client = $this->getClient(); | |
572 | ||
7ab5eb95 | 573 | $entry = new Entry($this->getLoggedInUser()); |
574 | $entry->setUrl($this->url); | |
575 | $this->getEntityManager()->persist($entry); | |
576 | $this->getEntityManager()->flush(); | |
577 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 578 | |
f808b016 | 579 | $client->request('GET', '/archive/' . $entry->getId()); |
eb3bd7ef | 580 | |
f808b016 | 581 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef J |
582 | |
583 | $res = $client->getContainer() | |
584 | ->get('doctrine.orm.entity_manager') | |
585 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 586 | ->find($entry->getId()); |
eb3bd7ef | 587 | |
38520658 | 588 | $this->assertSame(1, $res->isArchived()); |
eb3bd7ef J |
589 | } |
590 | ||
591 | public function testToggleStar() | |
592 | { | |
593 | $this->logInAs('admin'); | |
594 | $client = $this->getClient(); | |
595 | ||
7ab5eb95 | 596 | $entry = new Entry($this->getLoggedInUser()); |
597 | $entry->setUrl($this->url); | |
598 | $this->getEntityManager()->persist($entry); | |
599 | $this->getEntityManager()->flush(); | |
600 | $this->getEntityManager()->clear(); | |
eb3bd7ef | 601 | |
f808b016 | 602 | $client->request('GET', '/star/' . $entry->getId()); |
eb3bd7ef | 603 | |
f808b016 | 604 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef J |
605 | |
606 | $res = $client->getContainer() | |
607 | ->get('doctrine.orm.entity_manager') | |
608 | ->getRepository('WallabagCoreBundle:Entry') | |
7ab5eb95 | 609 | ->findOneById($entry->getId()); |
eb3bd7ef | 610 | |
38520658 | 611 | $this->assertSame(1, $res->isStarred()); |
eb3bd7ef J |
612 | } |
613 | ||
614 | public function testDelete() | |
615 | { | |
616 | $this->logInAs('admin'); | |
617 | $client = $this->getClient(); | |
618 | ||
7ab5eb95 | 619 | $entry = new Entry($this->getLoggedInUser()); |
620 | $entry->setUrl($this->url); | |
621 | $this->getEntityManager()->persist($entry); | |
622 | $this->getEntityManager()->flush(); | |
eb3bd7ef | 623 | |
f808b016 | 624 | $client->request('GET', '/delete/' . $entry->getId()); |
eb3bd7ef | 625 | |
f808b016 | 626 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 627 | |
f808b016 | 628 | $client->request('GET', '/delete/' . $entry->getId()); |
eb3bd7ef | 629 | |
f808b016 | 630 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 631 | } |
3d2b2d62 | 632 | |
2863bf2a JB |
633 | /** |
634 | * It will create a new entry. | |
635 | * Browse to it. | |
636 | * Then remove it. | |
637 | * | |
638 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
639 | */ | |
640 | public function testViewAndDelete() | |
641 | { | |
642 | $this->logInAs('admin'); | |
643 | $client = $this->getClient(); | |
644 | ||
ac8cf632 JB |
645 | $em = $client->getContainer() |
646 | ->get('doctrine.orm.entity_manager'); | |
647 | ||
2863bf2a | 648 | // add a new content to be removed later |
ac8cf632 | 649 | $user = $em |
2863bf2a JB |
650 | ->getRepository('WallabagUserBundle:User') |
651 | ->findOneByUserName('admin'); | |
652 | ||
653 | $content = new Entry($user); | |
654 | $content->setUrl('http://1.1.1.1/entry'); | |
655 | $content->setReadingTime(12); | |
656 | $content->setDomainName('domain.io'); | |
657 | $content->setMimetype('text/html'); | |
658 | $content->setTitle('test title entry'); | |
659 | $content->setContent('This is my content /o/'); | |
7975395d | 660 | $content->updateArchived(true); |
2863bf2a JB |
661 | $content->setLanguage('fr'); |
662 | ||
ac8cf632 JB |
663 | $em->persist($content); |
664 | $em->flush(); | |
2863bf2a | 665 | |
f808b016 JB |
666 | $client->request('GET', '/view/' . $content->getId()); |
667 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
2863bf2a | 668 | |
f808b016 JB |
669 | $client->request('GET', '/delete/' . $content->getId()); |
670 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
2863bf2a JB |
671 | |
672 | $client->followRedirect(); | |
f808b016 | 673 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
2863bf2a JB |
674 | } |
675 | ||
3d2b2d62 J |
676 | public function testViewOtherUserEntry() |
677 | { | |
159986c4 | 678 | $this->logInAs('admin'); |
3d2b2d62 J |
679 | $client = $this->getClient(); |
680 | ||
681 | $content = $client->getContainer() | |
682 | ->get('doctrine.orm.entity_manager') | |
683 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 684 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 685 | |
f808b016 | 686 | $client->request('GET', '/view/' . $content->getId()); |
3d2b2d62 | 687 | |
f808b016 | 688 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
3d2b2d62 | 689 | } |
26864574 | 690 | |
3f357ee2 | 691 | public function testFilterOnReadingTime() |
26864574 NL |
692 | { |
693 | $this->logInAs('admin'); | |
7ab5eb95 | 694 | $this->useTheme('baggy'); |
26864574 | 695 | $client = $this->getClient(); |
7ab5eb95 | 696 | $entry = new Entry($this->getLoggedInUser()); |
697 | $entry->setUrl($this->url); | |
698 | $entry->setReadingTime(22); | |
699 | $this->getEntityManager()->persist($entry); | |
700 | $this->getEntityManager()->flush(); | |
26864574 NL |
701 | |
702 | $crawler = $client->request('GET', '/unread/list'); | |
703 | ||
704 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
705 | ||
4094ea47 | 706 | $data = [ |
d6a9e139 NL |
707 | 'entry_filter[readingTime][right_number]' => 22, |
708 | 'entry_filter[readingTime][left_number]' => 22, | |
4094ea47 | 709 | ]; |
26864574 NL |
710 | |
711 | $crawler = $client->submit($form, $data); | |
712 | ||
713 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
714 | } | |
ab2c93c7 | 715 | |
1b164717 JB |
716 | public function testFilterOnReadingTimeWithNegativeValue() |
717 | { | |
718 | $this->logInAs('admin'); | |
719 | $client = $this->getClient(); | |
720 | ||
721 | $crawler = $client->request('GET', '/unread/list'); | |
722 | ||
723 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
724 | ||
725 | $data = [ | |
726 | 'entry_filter[readingTime][right_number]' => -22, | |
727 | 'entry_filter[readingTime][left_number]' => -22, | |
728 | ]; | |
729 | ||
730 | $crawler = $client->submit($form, $data); | |
731 | ||
732 | // forcing negative value results in no entry displayed | |
733 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
734 | } | |
735 | ||
95859e54 JB |
736 | public function testFilterOnReadingTimeOnlyUpper() |
737 | { | |
738 | $this->logInAs('admin'); | |
7ab5eb95 | 739 | $this->useTheme('baggy'); |
95859e54 JB |
740 | $client = $this->getClient(); |
741 | ||
7ab5eb95 | 742 | $crawler = $client->request('GET', '/all/list'); |
743 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
744 | ||
745 | $entry = new Entry($this->getLoggedInUser()); | |
746 | $entry->setUrl($this->url); | |
747 | $entry->setReadingTime(23); | |
748 | $this->getEntityManager()->persist($entry); | |
749 | $this->getEntityManager()->flush(); | |
750 | ||
751 | $crawler = $client->request('GET', '/all/list'); | |
752 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | |
95859e54 JB |
753 | |
754 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
755 | ||
756 | $data = [ | |
757 | 'entry_filter[readingTime][right_number]' => 22, | |
758 | ]; | |
759 | ||
760 | $crawler = $client->submit($form, $data); | |
761 | ||
7ab5eb95 | 762 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
95859e54 JB |
763 | } |
764 | ||
765 | public function testFilterOnReadingTimeOnlyLower() | |
766 | { | |
767 | $this->logInAs('admin'); | |
7ab5eb95 | 768 | $this->useTheme('baggy'); |
95859e54 JB |
769 | $client = $this->getClient(); |
770 | ||
771 | $crawler = $client->request('GET', '/unread/list'); | |
772 | ||
773 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
774 | ||
775 | $data = [ | |
776 | 'entry_filter[readingTime][left_number]' => 22, | |
777 | ]; | |
778 | ||
779 | $crawler = $client->submit($form, $data); | |
780 | ||
7ab5eb95 | 781 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
782 | ||
783 | $entry = new Entry($this->getLoggedInUser()); | |
784 | $entry->setUrl($this->url); | |
785 | $entry->setReadingTime(23); | |
786 | $this->getEntityManager()->persist($entry); | |
787 | $this->getEntityManager()->flush(); | |
788 | ||
789 | $crawler = $client->submit($form, $data); | |
790 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
95859e54 JB |
791 | } |
792 | ||
30334567 DB |
793 | public function testFilterOnUnreadStatus() |
794 | { | |
795 | $this->logInAs('admin'); | |
7ab5eb95 | 796 | $this->useTheme('baggy'); |
30334567 DB |
797 | $client = $this->getClient(); |
798 | ||
799 | $crawler = $client->request('GET', '/all/list'); | |
800 | ||
801 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
802 | ||
803 | $data = [ | |
804 | 'entry_filter[isUnread]' => true, | |
805 | ]; | |
806 | ||
807 | $crawler = $client->submit($form, $data); | |
808 | ||
7ab5eb95 | 809 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
810 | ||
811 | $entry = new Entry($this->getLoggedInUser()); | |
812 | $entry->setUrl($this->url); | |
7975395d | 813 | $entry->updateArchived(false); |
7ab5eb95 | 814 | $this->getEntityManager()->persist($entry); |
815 | $this->getEntityManager()->flush(); | |
816 | ||
817 | $crawler = $client->submit($form, $data); | |
818 | ||
e9c80c99 | 819 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
30334567 DB |
820 | } |
821 | ||
3f357ee2 NL |
822 | public function testFilterOnCreationDate() |
823 | { | |
824 | $this->logInAs('admin'); | |
7ab5eb95 | 825 | $this->useTheme('baggy'); |
3f357ee2 NL |
826 | $client = $this->getClient(); |
827 | ||
828 | $crawler = $client->request('GET', '/unread/list'); | |
829 | ||
830 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
831 | ||
4094ea47 | 832 | $data = [ |
3f357ee2 | 833 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
8ce32af6 | 834 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
4094ea47 | 835 | ]; |
3f357ee2 NL |
836 | |
837 | $crawler = $client->submit($form, $data); | |
838 | ||
7ab5eb95 | 839 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 840 | |
4094ea47 | 841 | $data = [ |
f90af145 JB |
842 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
843 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
4094ea47 | 844 | ]; |
f90af145 JB |
845 | |
846 | $crawler = $client->submit($form, $data); | |
847 | ||
7ab5eb95 | 848 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
f90af145 | 849 | |
4094ea47 | 850 | $data = [ |
3f357ee2 | 851 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
8ce32af6 | 852 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
4094ea47 | 853 | ]; |
3f357ee2 NL |
854 | |
855 | $crawler = $client->submit($form, $data); | |
856 | ||
857 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
858 | } |
859 | ||
ab2c93c7 NL |
860 | public function testPaginationWithFilter() |
861 | { | |
862 | $this->logInAs('admin'); | |
863 | $client = $this->getClient(); | |
ab2c93c7 NL |
864 | $crawler = $client->request('GET', '/config'); |
865 | ||
866 | $form = $crawler->filter('button[id=config_save]')->form(); | |
867 | ||
4094ea47 | 868 | $data = [ |
ab2c93c7 | 869 | 'config[items_per_page]' => '1', |
4094ea47 | 870 | ]; |
ab2c93c7 NL |
871 | |
872 | $client->submit($form, $data); | |
873 | ||
76cd8dbb | 874 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
ab2c93c7 | 875 | |
f808b016 | 876 | $client->request('GET', 'unread/list' . $parameters); |
ab2c93c7 NL |
877 | |
878 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
879 | |
880 | // reset pagination | |
881 | $crawler = $client->request('GET', '/config'); | |
882 | $form = $crawler->filter('button[id=config_save]')->form(); | |
4094ea47 | 883 | $data = [ |
e1779760 | 884 | 'config[items_per_page]' => '12', |
4094ea47 | 885 | ]; |
e1779760 | 886 | $client->submit($form, $data); |
ab2c93c7 | 887 | } |
443cecd2 NL |
888 | |
889 | public function testFilterOnDomainName() | |
890 | { | |
891 | $this->logInAs('admin'); | |
7ab5eb95 | 892 | $this->useTheme('baggy'); |
443cecd2 NL |
893 | $client = $this->getClient(); |
894 | ||
895 | $crawler = $client->request('GET', '/unread/list'); | |
896 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 897 | $data = [ |
02d17813 | 898 | 'entry_filter[domainName]' => 'domain', |
4094ea47 | 899 | ]; |
443cecd2 NL |
900 | |
901 | $crawler = $client->submit($form, $data); | |
02d17813 | 902 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 | 903 | |
00fc2b44 KD |
904 | $crawler = $client->request('GET', '/unread/list'); |
905 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
906 | $data = [ | |
907 | 'entry_filter[domainName]' => 'dOmain', | |
908 | ]; | |
909 | ||
910 | $crawler = $client->submit($form, $data); | |
911 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
912 | ||
443cecd2 | 913 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
4094ea47 | 914 | $data = [ |
8ce32af6 | 915 | 'entry_filter[domainName]' => 'wallabag', |
4094ea47 | 916 | ]; |
443cecd2 NL |
917 | |
918 | $crawler = $client->submit($form, $data); | |
919 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
920 | } | |
e1779760 NL |
921 | |
922 | public function testFilterOnStatus() | |
923 | { | |
924 | $this->logInAs('admin'); | |
7ab5eb95 | 925 | $this->useTheme('baggy'); |
e1779760 NL |
926 | $client = $this->getClient(); |
927 | ||
928 | $crawler = $client->request('GET', '/unread/list'); | |
929 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
930 | $form['entry_filter[isArchived]']->tick(); | |
931 | $form['entry_filter[isStarred]']->untick(); | |
932 | ||
933 | $crawler = $client->submit($form); | |
159986c4 | 934 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
935 | |
936 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
937 | $form['entry_filter[isArchived]']->untick(); | |
938 | $form['entry_filter[isStarred]']->tick(); | |
939 | ||
940 | $crawler = $client->submit($form); | |
02d17813 | 941 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 942 | } |
497e0cad | 943 | |
e8911f7c JB |
944 | public function testFilterOnIsPublic() |
945 | { | |
946 | $this->logInAs('admin'); | |
947 | $this->useTheme('baggy'); | |
948 | $client = $this->getClient(); | |
949 | ||
950 | $crawler = $client->request('GET', '/unread/list'); | |
951 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
952 | $form['entry_filter[isPublic]']->tick(); | |
953 | ||
954 | $crawler = $client->submit($form); | |
955 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
956 | } | |
957 | ||
497e0cad NL |
958 | public function testPreviewPictureFilter() |
959 | { | |
960 | $this->logInAs('admin'); | |
7ab5eb95 | 961 | $this->useTheme('baggy'); |
497e0cad NL |
962 | $client = $this->getClient(); |
963 | ||
964 | $crawler = $client->request('GET', '/unread/list'); | |
965 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
966 | $form['entry_filter[previewPicture]']->tick(); | |
967 | ||
968 | $crawler = $client->submit($form); | |
7ab5eb95 | 969 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
497e0cad | 970 | } |
d4ebe5c5 JB |
971 | |
972 | public function testFilterOnLanguage() | |
973 | { | |
974 | $this->logInAs('admin'); | |
7ab5eb95 | 975 | $this->useTheme('baggy'); |
d4ebe5c5 JB |
976 | $client = $this->getClient(); |
977 | ||
7ab5eb95 | 978 | $entry = new Entry($this->getLoggedInUser()); |
979 | $entry->setUrl($this->url); | |
980 | $entry->setLanguage('fr'); | |
981 | $this->getEntityManager()->persist($entry); | |
982 | $this->getEntityManager()->flush(); | |
983 | ||
d4ebe5c5 JB |
984 | $crawler = $client->request('GET', '/unread/list'); |
985 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 986 | $data = [ |
159986c4 | 987 | 'entry_filter[language]' => 'fr', |
4094ea47 | 988 | ]; |
d4ebe5c5 JB |
989 | |
990 | $crawler = $client->submit($form, $data); | |
e9c80c99 | 991 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
992 | |
993 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 994 | $data = [ |
d4ebe5c5 | 995 | 'entry_filter[language]' => 'en', |
4094ea47 | 996 | ]; |
d4ebe5c5 JB |
997 | |
998 | $crawler = $client->submit($form, $data); | |
999 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
1000 | } | |
a7e2218e | 1001 | |
21d82c3c | 1002 | public function testShareEntryPublicly() |
a7e2218e NL |
1003 | { |
1004 | $this->logInAs('admin'); | |
1005 | $client = $this->getClient(); | |
1006 | ||
7ab5eb95 | 1007 | // sharing is enabled |
1008 | $client->getContainer()->get('craue_config')->set('share_public', 1); | |
1009 | ||
1010 | $content = new Entry($this->getLoggedInUser()); | |
1011 | $content->setUrl($this->url); | |
1012 | $this->getEntityManager()->persist($content); | |
1013 | $this->getEntityManager()->flush(); | |
1014 | $this->getEntityManager()->clear(); | |
a7e2218e | 1015 | |
7239082a | 1016 | // no uid |
f808b016 JB |
1017 | $client->request('GET', '/share/' . $content->getUid()); |
1018 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
eddda878 | 1019 | |
7239082a | 1020 | // generating the uid |
f808b016 JB |
1021 | $client->request('GET', '/share/' . $content->getId()); |
1022 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
eddda878 | 1023 | |
115de64e JB |
1024 | $shareUrl = $client->getResponse()->getTargetUrl(); |
1025 | ||
1026 | // use a new client to have a fresh empty session (instead of a logged one from the previous client) | |
1027 | $client->restart(); | |
1028 | ||
1029 | $client->request('GET', $shareUrl); | |
1030 | ||
f808b016 | 1031 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
eddda878 JB |
1032 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); |
1033 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
1034 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
a7e2218e | 1035 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
21d82c3c NL |
1036 | $this->assertContains('og:title', $client->getResponse()->getContent()); |
1037 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
1038 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
d5c45d52 | 1039 | $this->assertContains('og:image', $client->getResponse()->getContent()); |
a7e2218e | 1040 | |
eddda878 JB |
1041 | // sharing is now disabled |
1042 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
f808b016 JB |
1043 | $client->request('GET', '/share/' . $content->getUid()); |
1044 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
eddda878 | 1045 | |
eddda878 | 1046 | // removing the share |
f808b016 JB |
1047 | $client->request('GET', '/share/delete/' . $content->getId()); |
1048 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
eddda878 JB |
1049 | |
1050 | // share is now disable | |
f808b016 JB |
1051 | $client->request('GET', '/share/' . $content->getUid()); |
1052 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
a7e2218e | 1053 | } |
d1495dd0 JB |
1054 | |
1055 | public function testNewEntryWithDownloadImagesEnabled() | |
1056 | { | |
be085c3d | 1057 | $this->downloadImagesEnabled = true; |
d1495dd0 JB |
1058 | $this->logInAs('admin'); |
1059 | $client = $this->getClient(); | |
1060 | ||
26e2f074 | 1061 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; |
d1495dd0 JB |
1062 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
1063 | ||
1064 | $crawler = $client->request('GET', '/new'); | |
1065 | ||
f808b016 | 1066 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1067 | |
1068 | $form = $crawler->filter('form[name=entry]')->form(); | |
1069 | ||
1070 | $data = [ | |
1071 | 'entry[url]' => $url, | |
1072 | ]; | |
1073 | ||
1074 | $client->submit($form, $data); | |
1075 | ||
f808b016 | 1076 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1077 | |
1078 | $em = $client->getContainer() | |
1079 | ->get('doctrine.orm.entity_manager'); | |
1080 | ||
1081 | $entry = $em | |
1082 | ->getRepository('WallabagCoreBundle:Entry') | |
1083 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1084 | ||
1085 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
f808b016 | 1086 | $this->assertSame($url, $entry->getUrl()); |
d81bf605 | 1087 | $this->assertContains('Judo', $entry->getTitle()); |
be085c3d | 1088 | // instead of checking for the filename (which might change) check that the image is now local |
d81bf605 | 1089 | $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent()); |
d1495dd0 | 1090 | |
e0597476 JB |
1091 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
1092 | } | |
1093 | ||
1094 | /** | |
1095 | * @depends testNewEntryWithDownloadImagesEnabled | |
1096 | */ | |
1097 | public function testRemoveEntryWithDownloadImagesEnabled() | |
1098 | { | |
be085c3d | 1099 | $this->downloadImagesEnabled = true; |
e0597476 JB |
1100 | $this->logInAs('admin'); |
1101 | $client = $this->getClient(); | |
1102 | ||
26e2f074 | 1103 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; |
e0597476 JB |
1104 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
1105 | ||
7ab5eb95 | 1106 | $crawler = $client->request('GET', '/new'); |
1107 | ||
f808b016 | 1108 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
7ab5eb95 | 1109 | |
1110 | $form = $crawler->filter('form[name=entry]')->form(); | |
1111 | ||
1112 | $data = [ | |
1113 | 'entry[url]' => $url, | |
1114 | ]; | |
1115 | ||
1116 | $client->submit($form, $data); | |
1117 | ||
f808b016 | 1118 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
7ab5eb95 | 1119 | |
e0597476 JB |
1120 | $content = $client->getContainer() |
1121 | ->get('doctrine.orm.entity_manager') | |
1122 | ->getRepository('WallabagCoreBundle:Entry') | |
1123 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1124 | ||
f808b016 | 1125 | $client->request('GET', '/delete/' . $content->getId()); |
e0597476 | 1126 | |
f808b016 | 1127 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d1495dd0 JB |
1128 | |
1129 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
1130 | } | |
65cd8a4a NL |
1131 | |
1132 | public function testRedirectToHomepage() | |
1133 | { | |
1134 | $this->logInAs('empty'); | |
1135 | $client = $this->getClient(); | |
1136 | ||
65cd8a4a | 1137 | // Redirect to homepage |
7ab5eb95 | 1138 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1139 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
7ab5eb95 | 1140 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1141 | |
7ab5eb95 | 1142 | $entry = new Entry($this->getLoggedInUser()); |
1143 | $entry->setUrl($this->url); | |
1144 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1145 | |
7ab5eb95 | 1146 | $this->getEntityManager()->flush(); |
1147 | ||
f808b016 JB |
1148 | $client->request('GET', '/view/' . $entry->getId()); |
1149 | $client->request('GET', '/archive/' . $entry->getId()); | |
65cd8a4a | 1150 | |
f808b016 JB |
1151 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
1152 | $this->assertSame('/', $client->getResponse()->headers->get('location')); | |
65cd8a4a NL |
1153 | } |
1154 | ||
1155 | public function testRedirectToCurrentPage() | |
1156 | { | |
1157 | $this->logInAs('empty'); | |
1158 | $client = $this->getClient(); | |
1159 | ||
65cd8a4a | 1160 | // Redirect to current page |
7ab5eb95 | 1161 | $config = $this->getLoggedInUser()->getConfig(); |
65cd8a4a | 1162 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
7ab5eb95 | 1163 | $this->getEntityManager()->persist($config); |
65cd8a4a | 1164 | |
7ab5eb95 | 1165 | $entry = new Entry($this->getLoggedInUser()); |
1166 | $entry->setUrl($this->url); | |
1167 | $this->getEntityManager()->persist($entry); | |
65cd8a4a | 1168 | |
7ab5eb95 | 1169 | $this->getEntityManager()->flush(); |
1170 | ||
f808b016 JB |
1171 | $client->request('GET', '/view/' . $entry->getId()); |
1172 | $client->request('GET', '/archive/' . $entry->getId()); | |
65cd8a4a | 1173 | |
f808b016 JB |
1174 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
1175 | $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location')); | |
65cd8a4a | 1176 | } |
10b35097 NL |
1177 | |
1178 | public function testFilterOnHttpStatus() | |
1179 | { | |
1180 | $this->logInAs('admin'); | |
7ab5eb95 | 1181 | $this->useTheme('baggy'); |
10b35097 NL |
1182 | $client = $this->getClient(); |
1183 | ||
7ab5eb95 | 1184 | $entry = new Entry($this->getLoggedInUser()); |
77854331 | 1185 | $entry->setUrl('https://www.lemonde.fr/incorrect-url/'); |
7ab5eb95 | 1186 | $entry->setHttpStatus(404); |
1187 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1188 | |
7ab5eb95 | 1189 | $this->getEntityManager()->flush(); |
10b35097 NL |
1190 | |
1191 | $crawler = $client->request('GET', '/all/list'); | |
1192 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1193 | ||
1194 | $data = [ | |
1195 | 'entry_filter[httpStatus]' => 404, | |
1196 | ]; | |
1197 | ||
1198 | $crawler = $client->submit($form, $data); | |
1199 | ||
1200 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1201 | ||
7ab5eb95 | 1202 | $entry = new Entry($this->getLoggedInUser()); |
1203 | $entry->setUrl($this->url); | |
1204 | $entry->setHttpStatus(200); | |
1205 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1206 | |
7ab5eb95 | 1207 | $entry = new Entry($this->getLoggedInUser()); |
1208 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); | |
1209 | $entry->setHttpStatus(200); | |
1210 | $this->getEntityManager()->persist($entry); | |
10b35097 | 1211 | |
7ab5eb95 | 1212 | $this->getEntityManager()->flush(); |
10b35097 NL |
1213 | |
1214 | $crawler = $client->request('GET', '/all/list'); | |
1215 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1216 | ||
1217 | $data = [ | |
1218 | 'entry_filter[httpStatus]' => 200, | |
1219 | ]; | |
1220 | ||
1221 | $crawler = $client->submit($form, $data); | |
1222 | ||
e9c80c99 | 1223 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d215273c NL |
1224 | |
1225 | $crawler = $client->request('GET', '/all/list'); | |
1226 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1227 | ||
1228 | $data = [ | |
1229 | 'entry_filter[httpStatus]' => 1024, | |
1230 | ]; | |
1231 | ||
1232 | $crawler = $client->submit($form, $data); | |
1233 | ||
e9c80c99 | 1234 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
10b35097 | 1235 | } |
32f455c1 NL |
1236 | |
1237 | public function testSearch() | |
1238 | { | |
1239 | $this->logInAs('admin'); | |
7ab5eb95 | 1240 | $this->useTheme('baggy'); |
32f455c1 NL |
1241 | $client = $this->getClient(); |
1242 | ||
7ab5eb95 | 1243 | $entry = new Entry($this->getLoggedInUser()); |
1244 | $entry->setUrl($this->url); | |
1245 | $entry->setTitle('test'); | |
1246 | $this->getEntityManager()->persist($entry); | |
1247 | $this->getEntityManager()->flush(); | |
1248 | ||
32f455c1 NL |
1249 | // Search on unread list |
1250 | $crawler = $client->request('GET', '/unread/list'); | |
1251 | ||
1252 | $form = $crawler->filter('form[name=search]')->form(); | |
1253 | $data = [ | |
1254 | 'search_entry[term]' => 'title', | |
1255 | ]; | |
1256 | ||
1257 | $crawler = $client->submit($form, $data); | |
1258 | ||
7ab5eb95 | 1259 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
32f455c1 NL |
1260 | |
1261 | // Search on starred list | |
1262 | $crawler = $client->request('GET', '/starred/list'); | |
1263 | ||
7ab5eb95 | 1264 | $entry = new Entry($this->getLoggedInUser()); |
1265 | $entry->setUrl('http://localhost/foo/bar'); | |
1266 | $entry->setTitle('testeur'); | |
1267 | $entry->setStarred(true); | |
1268 | $this->getEntityManager()->persist($entry); | |
1269 | $this->getEntityManager()->flush(); | |
1270 | ||
32f455c1 NL |
1271 | $form = $crawler->filter('form[name=search]')->form(); |
1272 | $data = [ | |
7ab5eb95 | 1273 | 'search_entry[term]' => 'testeur', |
32f455c1 NL |
1274 | ]; |
1275 | ||
1276 | $crawler = $client->submit($form, $data); | |
1277 | ||
1278 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1279 | ||
32f455c1 NL |
1280 | $crawler = $client->request('GET', '/archive/list'); |
1281 | ||
7ab5eb95 | 1282 | // Added new article to test on archive list |
1283 | $entry = new Entry($this->getLoggedInUser()); | |
1284 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | |
1285 | $entry->setTitle('Le manège'); | |
7975395d | 1286 | $entry->updateArchived(true); |
7ab5eb95 | 1287 | $this->getEntityManager()->persist($entry); |
1288 | $this->getEntityManager()->flush(); | |
1289 | ||
32f455c1 NL |
1290 | $form = $crawler->filter('form[name=search]')->form(); |
1291 | $data = [ | |
1292 | 'search_entry[term]' => 'manège', | |
1293 | ]; | |
1294 | ||
1295 | $crawler = $client->submit($form, $data); | |
1296 | ||
1297 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
f808b016 | 1298 | $client->request('GET', '/delete/' . $entry->getId()); |
32f455c1 NL |
1299 | |
1300 | // test on list of all articles | |
1301 | $crawler = $client->request('GET', '/all/list'); | |
1302 | ||
1303 | $form = $crawler->filter('form[name=search]')->form(); | |
1304 | $data = [ | |
995c2044 | 1305 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database |
32f455c1 NL |
1306 | ]; |
1307 | ||
1308 | $crawler = $client->submit($form, $data); | |
1309 | ||
1310 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
eac09b48 KD |
1311 | |
1312 | // test url search on list of all articles | |
7ab5eb95 | 1313 | $entry = new Entry($this->getLoggedInUser()); |
1314 | $entry->setUrl('http://domain/qux'); | |
1315 | $entry->setTitle('Le manège'); | |
7975395d | 1316 | $entry->updateArchived(true); |
7ab5eb95 | 1317 | $this->getEntityManager()->persist($entry); |
1318 | $this->getEntityManager()->flush(); | |
1319 | ||
eac09b48 KD |
1320 | $crawler = $client->request('GET', '/all/list'); |
1321 | ||
1322 | $form = $crawler->filter('form[name=search]')->form(); | |
1323 | $data = [ | |
1324 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1325 | ]; | |
1326 | ||
1327 | $crawler = $client->submit($form, $data); | |
1328 | ||
1329 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1330 | ||
1331 | // same as previous test but for case-sensitivity | |
1332 | $crawler = $client->request('GET', '/all/list'); | |
1333 | ||
1334 | $form = $crawler->filter('form[name=search]')->form(); | |
1335 | $data = [ | |
1336 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1337 | ]; | |
1338 | ||
1339 | $crawler = $client->submit($form, $data); | |
1340 | ||
1341 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
32f455c1 | 1342 | } |
42f3bb2c JB |
1343 | |
1344 | public function dataForLanguage() | |
1345 | { | |
1346 | return [ | |
1347 | 'ru' => [ | |
1348 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | |
1349 | 'ru', | |
1350 | ], | |
739a4024 FB |
1351 | 'fr' => [ |
1352 | 'https://fr.wikipedia.org/wiki/Wallabag', | |
1353 | 'fr', | |
42f3bb2c JB |
1354 | ], |
1355 | 'de' => [ | |
3be96dcb | 1356 | 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', |
42f3bb2c JB |
1357 | 'de', |
1358 | ], | |
1359 | 'it' => [ | |
1360 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | |
1361 | 'it', | |
1362 | ], | |
1363 | 'zh_CN' => [ | |
1364 | 'http://www.hao123.com/shequ?__noscript__-=1', | |
1365 | 'zh_CN', | |
1366 | ], | |
42f3bb2c | 1367 | 'pt_BR' => [ |
4408ebd4 | 1368 | 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', |
42f3bb2c JB |
1369 | 'pt_BR', |
1370 | ], | |
80e49ba7 | 1371 | 'fucked_list_of_languages' => [ |
42f3bb2c | 1372 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', |
38520658 | 1373 | null, |
42f3bb2c | 1374 | ], |
80e49ba7 | 1375 | 'es-ES' => [ |
77854331 JB |
1376 | 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', |
1377 | 'es', | |
80e49ba7 | 1378 | ], |
42f3bb2c JB |
1379 | ]; |
1380 | } | |
1381 | ||
1382 | /** | |
1383 | * @dataProvider dataForLanguage | |
1384 | */ | |
1385 | public function testLanguageValidation($url, $expectedLanguage) | |
1386 | { | |
1387 | $this->logInAs('admin'); | |
1388 | $client = $this->getClient(); | |
1389 | ||
1390 | $crawler = $client->request('GET', '/new'); | |
1391 | ||
f808b016 | 1392 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
42f3bb2c JB |
1393 | |
1394 | $form = $crawler->filter('form[name=entry]')->form(); | |
1395 | ||
1396 | $data = [ | |
1397 | 'entry[url]' => $url, | |
1398 | ]; | |
1399 | ||
1400 | $client->submit($form, $data); | |
1401 | ||
f808b016 | 1402 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
42f3bb2c JB |
1403 | |
1404 | $content = $client->getContainer() | |
1405 | ->get('doctrine.orm.entity_manager') | |
1406 | ->getRepository('WallabagCoreBundle:Entry') | |
1407 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1408 | ||
1409 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
f808b016 JB |
1410 | $this->assertSame($url, $content->getUrl()); |
1411 | $this->assertSame($expectedLanguage, $content->getLanguage()); | |
42f3bb2c | 1412 | } |
9de9f1e5 JB |
1413 | |
1414 | /** | |
1415 | * This test will require an internet connection. | |
1416 | */ | |
1417 | public function testRestrictedArticle() | |
1418 | { | |
f645d371 | 1419 | $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475'; |
9de9f1e5 JB |
1420 | $this->logInAs('admin'); |
1421 | $client = $this->getClient(); | |
1422 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1423 | ||
1424 | // enable restricted access | |
1425 | $client->getContainer()->get('craue_config')->set('restricted_access', 1); | |
1426 | ||
1427 | // create a new site_credential | |
1428 | $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
1429 | $credential = new SiteCredential($user); | |
1430 | $credential->setHost('monde-diplomatique.fr'); | |
bead8b42 | 1431 | $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); |
906424c1 | 1432 | $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); |
9de9f1e5 JB |
1433 | |
1434 | $em->persist($credential); | |
1435 | $em->flush(); | |
1436 | ||
1437 | $crawler = $client->request('GET', '/new'); | |
1438 | ||
f808b016 | 1439 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1440 | |
1441 | $form = $crawler->filter('form[name=entry]')->form(); | |
1442 | ||
1443 | $data = [ | |
1444 | 'entry[url]' => $url, | |
1445 | ]; | |
1446 | ||
1447 | $client->submit($form, $data); | |
1448 | ||
f808b016 | 1449 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1450 | |
1451 | $crawler = $client->followRedirect(); | |
1452 | ||
f808b016 | 1453 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9de9f1e5 JB |
1454 | $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); |
1455 | ||
1456 | $content = $em | |
1457 | ->getRepository('WallabagCoreBundle:Entry') | |
1458 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1459 | ||
1460 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
1461 | $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); | |
1462 | ||
1463 | $client->getContainer()->get('craue_config')->set('restricted_access', 0); | |
1464 | } | |
300f293c KD |
1465 | |
1466 | public function testPostEntryWhenFetchFails() | |
1467 | { | |
1468 | $url = 'http://example.com/papers/email_tracking.pdf'; | |
1469 | $this->logInAs('admin'); | |
1470 | $client = $this->getClient(); | |
1471 | ||
1472 | $container = $client->getContainer(); | |
1473 | $contentProxy = $this->getMockBuilder(ContentProxy::class) | |
1474 | ->disableOriginalConstructor() | |
1475 | ->setMethods(['updateEntry']) | |
1476 | ->getMock(); | |
1477 | $contentProxy->expects($this->any()) | |
1478 | ->method('updateEntry') | |
1479 | ->willThrowException(new \Exception('Test Fetch content fails')); | |
1480 | ||
1481 | $crawler = $client->request('GET', '/new'); | |
1482 | ||
1483 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1484 | ||
1485 | $form = $crawler->filter('form[name=entry]')->form(); | |
1486 | ||
1487 | $data = [ | |
1488 | 'entry[url]' => $url, | |
1489 | ]; | |
1490 | ||
1491 | /** | |
1492 | * We generate a new client to be able to use Mock ContentProxy | |
1493 | * Also we reinject the cookie from the previous client to keep the | |
1494 | * session. | |
1495 | */ | |
1496 | $cookie = $client->getCookieJar()->all(); | |
1497 | $client = $this->getNewClient(); | |
1498 | $client->getCookieJar()->set($cookie[0]); | |
1499 | $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy); | |
1500 | $client->submit($form, $data); | |
1501 | ||
1502 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1503 | ||
1504 | $content = $client->getContainer() | |
1505 | ->get('doctrine.orm.entity_manager') | |
1506 | ->getRepository('WallabagCoreBundle:Entry') | |
1507 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1508 | ||
1509 | $authors = $content->getPublishedBy(); | |
1510 | $this->assertSame('email_tracking.pdf', $content->getTitle()); | |
1511 | $this->assertSame('example.com', $content->getDomainName()); | |
1512 | } | |
e0a862b6 KD |
1513 | |
1514 | public function testEntryDeleteTagLink() | |
1515 | { | |
1516 | $this->logInAs('admin'); | |
1517 | $client = $this->getClient(); | |
1518 | ||
1519 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1520 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | |
1521 | $tag = $entry->getTags()[0]; | |
1522 | ||
1523 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | |
1524 | ||
1525 | // As long as the deletion link of a tag is following | |
1526 | // a link to the tag view, we take the second one to retrieve | |
1527 | // the deletion link of the first tag | |
1528 | $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1]; | |
1529 | ||
1530 | $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); | |
1531 | } | |
0447a75b JB |
1532 | |
1533 | public function testRandom() | |
1534 | { | |
1535 | $this->logInAs('admin'); | |
1536 | $client = $this->getClient(); | |
1537 | ||
1538 | $client->request('GET', '/unread/random'); | |
1539 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1540 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random'); | |
1541 | ||
1542 | $client->request('GET', '/starred/random'); | |
1543 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1544 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random'); | |
1545 | ||
1546 | $client->request('GET', '/archive/random'); | |
1547 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1548 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random'); | |
1549 | ||
1550 | $client->request('GET', '/untagged/random'); | |
1551 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1552 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random'); | |
1553 | ||
1554 | $client->request('GET', '/all/random'); | |
1555 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1556 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random'); | |
1557 | } | |
93fd4692 | 1558 | } |