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