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