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