aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php108
1 files changed, 86 insertions, 22 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 479e0700..3a8f92e7 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -13,7 +13,7 @@ class EntryControllerTest extends WallabagCoreTestCase
13{ 13{
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'; 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';
15 public $downloadImagesEnabled = false; 15 public $downloadImagesEnabled = false;
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'; 16 public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html';
17 17
18 /** 18 /**
19 * @after 19 * @after
@@ -164,9 +164,8 @@ class EntryControllerTest extends WallabagCoreTestCase
164 164
165 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); 165 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
166 $this->assertSame($this->url, $content->getUrl()); 166 $this->assertSame($this->url, $content->getUrl());
167 $this->assertContains('Google', $content->getTitle()); 167 $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle());
168 $this->assertSame('fr', $content->getLanguage()); 168 $this->assertSame('fr', $content->getLanguage());
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()); 169 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
171 $client->getContainer()->get('craue_config')->set('store_article_headers', 0); 170 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
172 } 171 }
@@ -200,8 +199,8 @@ class EntryControllerTest extends WallabagCoreTestCase
200 $authors = $content->getPublishedBy(); 199 $authors = $content->getPublishedBy();
201 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); 200 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
202 $this->assertSame('fr', $content->getLanguage()); 201 $this->assertSame('fr', $content->getLanguage());
203 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]); 202 $this->assertSame('Raphaël Balenieri', $authors[0]);
204 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]); 203 $this->assertSame('Frédéric Autran', $authors[1]);
205 } 204 }
206 205
207 public function testPostNewOkUrlExist() 206 public function testPostNewOkUrlExist()
@@ -236,7 +235,45 @@ class EntryControllerTest extends WallabagCoreTestCase
236 $this->logInAs('admin'); 235 $this->logInAs('admin');
237 $client = $this->getClient(); 236 $client = $this->getClient();
238 237
239 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; 238 $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
239
240 $crawler = $client->request('GET', '/new');
241
242 $this->assertSame(200, $client->getResponse()->getStatusCode());
243
244 $form = $crawler->filter('form[name=entry]')->form();
245
246 $data = [
247 'entry[url]' => $url,
248 ];
249
250 $client->submit($form, $data);
251
252 $crawler = $client->request('GET', '/new');
253
254 $this->assertSame(200, $client->getResponse()->getStatusCode());
255
256 $form = $crawler->filter('form[name=entry]')->form();
257
258 $data = [
259 'entry[url]' => $url,
260 ];
261
262 $client->submit($form, $data);
263
264 $this->assertSame(302, $client->getResponse()->getStatusCode());
265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
266 }
267
268 /**
269 * This test will require an internet connection.
270 */
271 public function testPostNewOkUrlExistWithRedirection()
272 {
273 $this->logInAs('admin');
274 $client = $this->getClient();
275
276 $url = 'https://wllbg.org/test-redirect/c51c';
240 277
241 $crawler = $client->request('GET', '/new'); 278 $crawler = $client->request('GET', '/new');
242 279
@@ -522,9 +559,12 @@ class EntryControllerTest extends WallabagCoreTestCase
522 559
523 $crawler = $client->followRedirect(); 560 $crawler = $client->followRedirect();
524 561
525 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); 562 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
563 $this->assertGreaterThan(1, $title);
526 $this->assertContains('My updated title hehe :)', $title[0]); 564 $this->assertContains('My updated title hehe :)', $title[0]);
527 $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); 565
566 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
567 $this->assertCount(1, $stats);
528 $this->assertNotContains('example.io', trim($stats[0])); 568 $this->assertNotContains('example.io', trim($stats[0]));
529 } 569 }
530 570
@@ -620,7 +660,7 @@ class EntryControllerTest extends WallabagCoreTestCase
620 $content->setMimetype('text/html'); 660 $content->setMimetype('text/html');
621 $content->setTitle('test title entry'); 661 $content->setTitle('test title entry');
622 $content->setContent('This is my content /o/'); 662 $content->setContent('This is my content /o/');
623 $content->setArchived(true); 663 $content->updateArchived(true);
624 $content->setLanguage('fr'); 664 $content->setLanguage('fr');
625 665
626 $em->persist($content); 666 $em->persist($content);
@@ -773,7 +813,7 @@ class EntryControllerTest extends WallabagCoreTestCase
773 813
774 $entry = new Entry($this->getLoggedInUser()); 814 $entry = new Entry($this->getLoggedInUser());
775 $entry->setUrl($this->url); 815 $entry->setUrl($this->url);
776 $entry->setArchived(false); 816 $entry->updateArchived(false);
777 $this->getEntityManager()->persist($entry); 817 $this->getEntityManager()->persist($entry);
778 $this->getEntityManager()->flush(); 818 $this->getEntityManager()->flush();
779 819
@@ -984,8 +1024,13 @@ class EntryControllerTest extends WallabagCoreTestCase
984 $client->request('GET', '/share/' . $content->getId()); 1024 $client->request('GET', '/share/' . $content->getId());
985 $this->assertSame(302, $client->getResponse()->getStatusCode()); 1025 $this->assertSame(302, $client->getResponse()->getStatusCode());
986 1026
987 // follow link with uid 1027 $shareUrl = $client->getResponse()->getTargetUrl();
988 $crawler = $client->followRedirect(); 1028
1029 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1030 $client->restart();
1031
1032 $client->request('GET', $shareUrl);
1033
989 $this->assertSame(200, $client->getResponse()->getStatusCode()); 1034 $this->assertSame(200, $client->getResponse()->getStatusCode());
990 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 1035 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
991 $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); 1036 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
@@ -1001,9 +1046,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1001 $client->request('GET', '/share/' . $content->getUid()); 1046 $client->request('GET', '/share/' . $content->getUid());
1002 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1047 $this->assertSame(404, $client->getResponse()->getStatusCode());
1003 1048
1004 $client->request('GET', '/view/' . $content->getId());
1005 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
1006
1007 // removing the share 1049 // removing the share
1008 $client->request('GET', '/share/delete/' . $content->getId()); 1050 $client->request('GET', '/share/delete/' . $content->getId());
1009 $this->assertSame(302, $client->getResponse()->getStatusCode()); 1051 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -1244,7 +1286,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1244 $entry = new Entry($this->getLoggedInUser()); 1286 $entry = new Entry($this->getLoggedInUser());
1245 $entry->setUrl('http://0.0.0.0/foo/baz/qux'); 1287 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1246 $entry->setTitle('Le manège'); 1288 $entry->setTitle('Le manège');
1247 $entry->setArchived(true); 1289 $entry->updateArchived(true);
1248 $this->getEntityManager()->persist($entry); 1290 $this->getEntityManager()->persist($entry);
1249 $this->getEntityManager()->flush(); 1291 $this->getEntityManager()->flush();
1250 1292
@@ -1274,7 +1316,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1274 $entry = new Entry($this->getLoggedInUser()); 1316 $entry = new Entry($this->getLoggedInUser());
1275 $entry->setUrl('http://domain/qux'); 1317 $entry->setUrl('http://domain/qux');
1276 $entry->setTitle('Le manège'); 1318 $entry->setTitle('Le manège');
1277 $entry->setArchived(true); 1319 $entry->updateArchived(true);
1278 $this->getEntityManager()->persist($entry); 1320 $this->getEntityManager()->persist($entry);
1279 $this->getEntityManager()->flush(); 1321 $this->getEntityManager()->flush();
1280 1322
@@ -1325,10 +1367,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1325 'http://www.hao123.com/shequ?__noscript__-=1', 1367 'http://www.hao123.com/shequ?__noscript__-=1',
1326 'zh_CN', 1368 'zh_CN',
1327 ], 1369 ],
1328 'ru' => [
1329 'https://www.kp.ru/daily/26879.7/3921982/',
1330 'ru',
1331 ],
1332 'pt_BR' => [ 1370 'pt_BR' => [
1333 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', 1371 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1334 'pt_BR', 1372 'pt_BR',
@@ -1339,7 +1377,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1339 ], 1377 ],
1340 'es-ES' => [ 1378 'es-ES' => [
1341 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', 1379 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1342 'es', 1380 'es_ES',
1343 ], 1381 ],
1344 ]; 1382 ];
1345 } 1383 }
@@ -1494,4 +1532,30 @@ class EntryControllerTest extends WallabagCoreTestCase
1494 1532
1495 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); 1533 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1496 } 1534 }
1535
1536 public function testRandom()
1537 {
1538 $this->logInAs('admin');
1539 $client = $this->getClient();
1540
1541 $client->request('GET', '/unread/random');
1542 $this->assertSame(302, $client->getResponse()->getStatusCode());
1543 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1544
1545 $client->request('GET', '/starred/random');
1546 $this->assertSame(302, $client->getResponse()->getStatusCode());
1547 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1548
1549 $client->request('GET', '/archive/random');
1550 $this->assertSame(302, $client->getResponse()->getStatusCode());
1551 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1552
1553 $client->request('GET', '/untagged/random');
1554 $this->assertSame(302, $client->getResponse()->getStatusCode());
1555 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1556
1557 $client->request('GET', '/all/random');
1558 $this->assertSame(302, $client->getResponse()->getStatusCode());
1559 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');
1560 }
1497} 1561}