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