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