aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php152
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php57
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php261
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php221
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php32
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php45
7 files changed, 505 insertions, 265 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index e07c57dd..d8478ce3 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation; 6use Wallabag\AnnotationBundle\Entity\Annotation;
@@ -33,7 +33,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
33 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 33 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
34 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); 34 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
35 $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); 35 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
36 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); 36 $this->assertCount(1, $crawler->filter('button[id=feed_config_save]'));
37 } 37 }
38 38
39 public function testUpdate() 39 public function testUpdate()
@@ -297,7 +297,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]); 297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
298 } 298 }
299 299
300 public function testRssUpdateResetToken() 300 public function testFeedUpdateResetToken()
301 { 301 {
302 $this->logInAs('admin'); 302 $this->logInAs('admin');
303 $client = $this->getClient(); 303 $client = $this->getClient();
@@ -313,7 +313,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
313 } 313 }
314 314
315 $config = $user->getConfig(); 315 $config = $user->getConfig();
316 $config->setRssToken(null); 316 $config->setFeedToken(null);
317 $em->persist($config); 317 $em->persist($config);
318 $em->flush(); 318 $em->flush();
319 319
@@ -322,7 +322,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
322 $this->assertSame(200, $client->getResponse()->getStatusCode()); 322 $this->assertSame(200, $client->getResponse()->getStatusCode());
323 323
324 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 324 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
325 $this->assertContains('config.form_rss.no_token', $body[0]); 325 $this->assertContains('config.form_feed.no_token', $body[0]);
326 326
327 $client->request('GET', '/generate-token'); 327 $client->request('GET', '/generate-token');
328 $this->assertSame(302, $client->getResponse()->getStatusCode()); 328 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -330,7 +330,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
330 $crawler = $client->followRedirect(); 330 $crawler = $client->followRedirect();
331 331
332 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 332 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
333 $this->assertNotContains('config.form_rss.no_token', $body[0]); 333 $this->assertNotContains('config.form_feed.no_token', $body[0]);
334 } 334 }
335 335
336 public function testGenerateTokenAjax() 336 public function testGenerateTokenAjax()
@@ -351,7 +351,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
351 $this->assertArrayHasKey('token', $content); 351 $this->assertArrayHasKey('token', $content);
352 } 352 }
353 353
354 public function testRssUpdate() 354 public function testFeedUpdate()
355 { 355 {
356 $this->logInAs('admin'); 356 $this->logInAs('admin');
357 $client = $this->getClient(); 357 $client = $this->getClient();
@@ -360,10 +360,10 @@ class ConfigControllerTest extends WallabagCoreTestCase
360 360
361 $this->assertSame(200, $client->getResponse()->getStatusCode()); 361 $this->assertSame(200, $client->getResponse()->getStatusCode());
362 362
363 $form = $crawler->filter('button[id=rss_config_save]')->form(); 363 $form = $crawler->filter('button[id=feed_config_save]')->form();
364 364
365 $data = [ 365 $data = [
366 'rss_config[rss_limit]' => 12, 366 'feed_config[feed_limit]' => 12,
367 ]; 367 ];
368 368
369 $client->submit($form, $data); 369 $client->submit($form, $data);
@@ -372,31 +372,31 @@ class ConfigControllerTest extends WallabagCoreTestCase
372 372
373 $crawler = $client->followRedirect(); 373 $crawler = $client->followRedirect();
374 374
375 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); 375 $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]);
376 } 376 }
377 377
378 public function dataForRssFailed() 378 public function dataForFeedFailed()
379 { 379 {
380 return [ 380 return [
381 [ 381 [
382 [ 382 [
383 'rss_config[rss_limit]' => 0, 383 'feed_config[feed_limit]' => 0,
384 ], 384 ],
385 'This value should be 1 or more.', 385 'This value should be 1 or more.',
386 ], 386 ],
387 [ 387 [
388 [ 388 [
389 'rss_config[rss_limit]' => 1000000000000, 389 'feed_config[feed_limit]' => 1000000000000,
390 ], 390 ],
391 'validator.rss_limit_too_high', 391 'validator.feed_limit_too_high',
392 ], 392 ],
393 ]; 393 ];
394 } 394 }
395 395
396 /** 396 /**
397 * @dataProvider dataForRssFailed 397 * @dataProvider dataForFeedFailed
398 */ 398 */
399 public function testRssFailed($data, $expectedMessage) 399 public function testFeedFailed($data, $expectedMessage)
400 { 400 {
401 $this->logInAs('admin'); 401 $this->logInAs('admin');
402 $client = $this->getClient(); 402 $client = $this->getClient();
@@ -405,7 +405,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
405 405
406 $this->assertSame(200, $client->getResponse()->getStatusCode()); 406 $this->assertSame(200, $client->getResponse()->getStatusCode());
407 407
408 $form = $crawler->filter('button[id=rss_config_save]')->form(); 408 $form = $crawler->filter('button[id=feed_config_save]')->form();
409 409
410 $crawler = $client->submit($form, $data); 410 $crawler = $client->submit($form, $data);
411 411
@@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
849 $entryArchived->setContent('Youhou'); 849 $entryArchived->setContent('Youhou');
850 $entryArchived->setTitle('Youhou'); 850 $entryArchived->setTitle('Youhou');
851 $entryArchived->addTag($tagArchived); 851 $entryArchived->addTag($tagArchived);
852 $entryArchived->setArchived(true); 852 $entryArchived->updateArchived(true);
853 $em->persist($entryArchived); 853 $em->persist($entryArchived);
854 854
855 $annotationArchived = new Annotation($user); 855 $annotationArchived = new Annotation($user);
@@ -965,4 +965,120 @@ class ConfigControllerTest extends WallabagCoreTestCase
965 965
966 $client->request('GET', '/config/view-mode'); 966 $client->request('GET', '/config/view-mode');
967 } 967 }
968
969 public function testChangeLocaleWithoutReferer()
970 {
971 $client = $this->getClient();
972
973 $client->request('GET', '/locale/de');
974 $client->followRedirect();
975
976 $this->assertSame('de', $client->getRequest()->getLocale());
977 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
978 }
979
980 public function testChangeLocaleWithReferer()
981 {
982 $client = $this->getClient();
983
984 $client->request('GET', '/login');
985 $client->request('GET', '/locale/de');
986 $client->followRedirect();
987
988 $this->assertSame('de', $client->getRequest()->getLocale());
989 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
990 }
991
992 public function testChangeLocaleToBadLocale()
993 {
994 $client = $this->getClient();
995
996 $client->request('GET', '/login');
997 $client->request('GET', '/locale/yuyuyuyu');
998 $client->followRedirect();
999
1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1002 }
1003
1004 public function testUserEnable2faEmail()
1005 {
1006 $this->logInAs('admin');
1007 $client = $this->getClient();
1008
1009 $crawler = $client->request('GET', '/config/otp/email');
1010
1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
1012
1013 $crawler = $client->followRedirect();
1014
1015 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1016 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1017
1018 // restore user
1019 $em = $this->getEntityManager();
1020 $user = $em
1021 ->getRepository('WallabagUserBundle:User')
1022 ->findOneByUsername('admin');
1023
1024 $this->assertTrue($user->isEmailTwoFactor());
1025
1026 $user->setEmailTwoFactor(false);
1027 $em->persist($user);
1028 $em->flush();
1029 }
1030
1031 public function testUserEnable2faGoogle()
1032 {
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1035
1036 $crawler = $client->request('GET', '/config/otp/app');
1037
1038 $this->assertSame(200, $client->getResponse()->getStatusCode());
1039
1040 // restore user
1041 $em = $this->getEntityManager();
1042 $user = $em
1043 ->getRepository('WallabagUserBundle:User')
1044 ->findOneByUsername('admin');
1045
1046 $this->assertTrue($user->isGoogleTwoFactor());
1047 $this->assertGreaterThan(0, $user->getBackupCodes());
1048
1049 $user->setGoogleAuthenticatorSecret(false);
1050 $user->setBackupCodes(null);
1051 $em->persist($user);
1052 $em->flush();
1053 }
1054
1055 public function testUserEnable2faGoogleCancel()
1056 {
1057 $this->logInAs('admin');
1058 $client = $this->getClient();
1059
1060 $crawler = $client->request('GET', '/config/otp/app');
1061
1062 $this->assertSame(200, $client->getResponse()->getStatusCode());
1063
1064 // restore user
1065 $em = $this->getEntityManager();
1066 $user = $em
1067 ->getRepository('WallabagUserBundle:User')
1068 ->findOneByUsername('admin');
1069
1070 $this->assertTrue($user->isGoogleTwoFactor());
1071 $this->assertGreaterThan(0, $user->getBackupCodes());
1072
1073 $crawler = $client->request('GET', '/config/otp/app/cancel');
1074
1075 $this->assertSame(302, $client->getResponse()->getStatusCode());
1076
1077 $user = $em
1078 ->getRepository('WallabagUserBundle:User')
1079 ->findOneByUsername('admin');
1080
1081 $this->assertFalse($user->isGoogleTwoFactor());
1082 $this->assertEmpty($user->getBackupCodes());
1083 }
968} 1084}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 265e4205..9dee9891 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -522,9 +522,12 @@ class EntryControllerTest extends WallabagCoreTestCase
522 522
523 $crawler = $client->followRedirect(); 523 $crawler = $client->followRedirect();
524 524
525 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); 525 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
526 $this->assertGreaterThan(1, $title);
526 $this->assertContains('My updated title hehe :)', $title[0]); 527 $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']))); 528
529 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
530 $this->assertCount(1, $stats);
528 $this->assertNotContains('example.io', trim($stats[0])); 531 $this->assertNotContains('example.io', trim($stats[0]));
529 } 532 }
530 533
@@ -620,7 +623,7 @@ class EntryControllerTest extends WallabagCoreTestCase
620 $content->setMimetype('text/html'); 623 $content->setMimetype('text/html');
621 $content->setTitle('test title entry'); 624 $content->setTitle('test title entry');
622 $content->setContent('This is my content /o/'); 625 $content->setContent('This is my content /o/');
623 $content->setArchived(true); 626 $content->updateArchived(true);
624 $content->setLanguage('fr'); 627 $content->setLanguage('fr');
625 628
626 $em->persist($content); 629 $em->persist($content);
@@ -773,7 +776,7 @@ class EntryControllerTest extends WallabagCoreTestCase
773 776
774 $entry = new Entry($this->getLoggedInUser()); 777 $entry = new Entry($this->getLoggedInUser());
775 $entry->setUrl($this->url); 778 $entry->setUrl($this->url);
776 $entry->setArchived(false); 779 $entry->updateArchived(false);
777 $this->getEntityManager()->persist($entry); 780 $this->getEntityManager()->persist($entry);
778 $this->getEntityManager()->flush(); 781 $this->getEntityManager()->flush();
779 782
@@ -984,8 +987,13 @@ class EntryControllerTest extends WallabagCoreTestCase
984 $client->request('GET', '/share/' . $content->getId()); 987 $client->request('GET', '/share/' . $content->getId());
985 $this->assertSame(302, $client->getResponse()->getStatusCode()); 988 $this->assertSame(302, $client->getResponse()->getStatusCode());
986 989
987 // follow link with uid 990 $shareUrl = $client->getResponse()->getTargetUrl();
988 $crawler = $client->followRedirect(); 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
989 $this->assertSame(200, $client->getResponse()->getStatusCode()); 997 $this->assertSame(200, $client->getResponse()->getStatusCode());
990 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 998 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
991 $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); 999 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
@@ -1001,9 +1009,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1001 $client->request('GET', '/share/' . $content->getUid()); 1009 $client->request('GET', '/share/' . $content->getUid());
1002 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1010 $this->assertSame(404, $client->getResponse()->getStatusCode());
1003 1011
1004 $client->request('GET', '/view/' . $content->getId());
1005 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
1006
1007 // removing the share 1012 // removing the share
1008 $client->request('GET', '/share/delete/' . $content->getId()); 1013 $client->request('GET', '/share/delete/' . $content->getId());
1009 $this->assertSame(302, $client->getResponse()->getStatusCode()); 1014 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -1244,7 +1249,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1244 $entry = new Entry($this->getLoggedInUser()); 1249 $entry = new Entry($this->getLoggedInUser());
1245 $entry->setUrl('http://0.0.0.0/foo/baz/qux'); 1250 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1246 $entry->setTitle('Le manège'); 1251 $entry->setTitle('Le manège');
1247 $entry->setArchived(true); 1252 $entry->updateArchived(true);
1248 $this->getEntityManager()->persist($entry); 1253 $this->getEntityManager()->persist($entry);
1249 $this->getEntityManager()->flush(); 1254 $this->getEntityManager()->flush();
1250 1255
@@ -1274,7 +1279,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1274 $entry = new Entry($this->getLoggedInUser()); 1279 $entry = new Entry($this->getLoggedInUser());
1275 $entry->setUrl('http://domain/qux'); 1280 $entry->setUrl('http://domain/qux');
1276 $entry->setTitle('Le manège'); 1281 $entry->setTitle('Le manège');
1277 $entry->setArchived(true); 1282 $entry->updateArchived(true);
1278 $this->getEntityManager()->persist($entry); 1283 $this->getEntityManager()->persist($entry);
1279 $this->getEntityManager()->flush(); 1284 $this->getEntityManager()->flush();
1280 1285
@@ -1325,10 +1330,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1325 'http://www.hao123.com/shequ?__noscript__-=1', 1330 'http://www.hao123.com/shequ?__noscript__-=1',
1326 'zh_CN', 1331 'zh_CN',
1327 ], 1332 ],
1328 'ru' => [
1329 'https://www.kp.ru/daily/26879.7/3921982/',
1330 'ru',
1331 ],
1332 'pt_BR' => [ 1333 'pt_BR' => [
1333 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', 1334 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1334 'pt_BR', 1335 'pt_BR',
@@ -1494,4 +1495,30 @@ class EntryControllerTest extends WallabagCoreTestCase
1494 1495
1495 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); 1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1496 } 1497 }
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 }
1497} 1524}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 0c3d4c83..d7ce7c45 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -180,7 +180,7 @@ class ExportControllerTest extends WallabagCoreTestCase
180 180
181 $this->assertGreaterThan(1, $csv); 181 $this->assertGreaterThan(1, $csv);
182 // +1 for title line 182 // +1 for title line
183 $this->assertSame(\count($contentInDB) + 1, \count($csv)); 183 $this->assertCount(\count($contentInDB) + 1, $csv);
184 $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); 184 $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
185 $this->assertContains($contentInDB[0]['title'], $csv[1]); 185 $this->assertContains($contentInDB[0]['title'], $csv[1]);
186 $this->assertContains($contentInDB[0]['url'], $csv[1]); 186 $this->assertContains($contentInDB[0]['url'], $csv[1]);
diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php
new file mode 100644
index 00000000..d52d7bb8
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php
@@ -0,0 +1,261 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class FeedControllerTest extends WallabagCoreTestCase
8{
9 public function validateDom($xml, $type, $nb = null, $tagValue = null)
10 {
11 $doc = new \DOMDocument();
12 $doc->loadXML($xml);
13
14 $xpath = new \DOMXPath($doc);
15 $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom');
16
17 if (null === $nb) {
18 $this->assertGreaterThan(0, $xpath->query('//a:entry')->length);
19 } else {
20 $this->assertSame($nb, $xpath->query('//a:entry')->length);
21 }
22
23 $this->assertSame(1, $xpath->query('/a:feed')->length);
24
25 $this->assertSame(1, $xpath->query('/a:feed/a:title')->length);
26 $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue);
27 $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue);
28
29 $this->assertSame(1, $xpath->query('/a:feed/a:updated')->length);
30
31 $this->assertSame(1, $xpath->query('/a:feed/a:generator')->length);
32 $this->assertSame('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue);
33 $this->assertSame('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue);
34
35 $this->assertSame(1, $xpath->query('/a:feed/a:subtitle')->length);
36 if (null !== $tagValue && 0 === strpos($type, 'tag')) {
37 $this->assertSame('wallabag — ' . $type . ' ' . $tagValue . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue);
38 $this->assertSame('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue);
39 } else {
40 $this->assertSame('wallabag — ' . $type . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue);
41 $this->assertSame('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue);
42 }
43
44 $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length);
45 $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href'));
46
47 $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length);
48
49 foreach ($xpath->query('//a:entry') as $item) {
50 $this->assertSame(1, $xpath->query('a:title', $item)->length);
51 $this->assertSame(1, $xpath->query('a:link[@rel="via"]', $item)->length);
52 $this->assertSame(1, $xpath->query('a:link[@rel="alternate"]', $item)->length);
53 $this->assertSame(1, $xpath->query('a:id', $item)->length);
54 $this->assertSame(1, $xpath->query('a:published', $item)->length);
55 $this->assertSame(1, $xpath->query('a:content', $item)->length);
56 }
57 }
58
59 public function dataForBadUrl()
60 {
61 return [
62 [
63 '/feed/admin/YZIOAUZIAO/unread',
64 ],
65 [
66 '/feed/wallace/YZIOAUZIAO/starred',
67 ],
68 [
69 '/feed/wallace/YZIOAUZIAO/archives',
70 ],
71 [
72 '/feed/wallace/YZIOAUZIAO/all',
73 ],
74 ];
75 }
76
77 /**
78 * @dataProvider dataForBadUrl
79 */
80 public function testBadUrl($url)
81 {
82 $client = $this->getClient();
83
84 $client->request('GET', $url);
85
86 $this->assertSame(404, $client->getResponse()->getStatusCode());
87 }
88
89 public function testUnread()
90 {
91 $client = $this->getClient();
92 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
93 $user = $em
94 ->getRepository('WallabagUserBundle:User')
95 ->findOneByUsername('admin');
96
97 $config = $user->getConfig();
98 $config->setFeedToken('SUPERTOKEN');
99 $config->setFeedLimit(2);
100 $em->persist($config);
101 $em->flush();
102
103 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
104
105 $this->assertSame(200, $client->getResponse()->getStatusCode());
106
107 $this->validateDom($client->getResponse()->getContent(), 'unread', 2);
108 }
109
110 public function testStarred()
111 {
112 $client = $this->getClient();
113 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
114 $user = $em
115 ->getRepository('WallabagUserBundle:User')
116 ->findOneByUsername('admin');
117
118 $config = $user->getConfig();
119 $config->setFeedToken('SUPERTOKEN');
120 $config->setFeedLimit(1);
121 $em->persist($config);
122 $em->flush();
123
124 $client = $this->getClient();
125 $client->request('GET', '/feed/admin/SUPERTOKEN/starred');
126
127 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
128
129 $this->validateDom($client->getResponse()->getContent(), 'starred');
130 }
131
132 public function testArchives()
133 {
134 $client = $this->getClient();
135 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
136 $user = $em
137 ->getRepository('WallabagUserBundle:User')
138 ->findOneByUsername('admin');
139
140 $config = $user->getConfig();
141 $config->setFeedToken('SUPERTOKEN');
142 $config->setFeedLimit(null);
143 $em->persist($config);
144 $em->flush();
145
146 $client = $this->getClient();
147 $client->request('GET', '/feed/admin/SUPERTOKEN/archive');
148
149 $this->assertSame(200, $client->getResponse()->getStatusCode());
150
151 $this->validateDom($client->getResponse()->getContent(), 'archive');
152 }
153
154 public function testAll()
155 {
156 $client = $this->getClient();
157 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
158 $user = $em
159 ->getRepository('WallabagUserBundle:User')
160 ->findOneByUsername('admin');
161
162 $config = $user->getConfig();
163 $config->setFeedToken('SUPERTOKEN');
164 $config->setFeedLimit(null);
165 $em->persist($config);
166 $em->flush();
167
168 $client = $this->getClient();
169 $client->request('GET', '/feed/admin/SUPERTOKEN/all');
170
171 $this->assertSame(200, $client->getResponse()->getStatusCode());
172
173 $this->validateDom($client->getResponse()->getContent(), 'all');
174 }
175
176 public function testPagination()
177 {
178 $client = $this->getClient();
179 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
180 $user = $em
181 ->getRepository('WallabagUserBundle:User')
182 ->findOneByUsername('admin');
183
184 $config = $user->getConfig();
185 $config->setFeedToken('SUPERTOKEN');
186 $config->setFeedLimit(1);
187 $em->persist($config);
188 $em->flush();
189
190 $client = $this->getClient();
191
192 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
193 $this->assertSame(200, $client->getResponse()->getStatusCode());
194 $this->validateDom($client->getResponse()->getContent(), 'unread');
195
196 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2');
197 $this->assertSame(200, $client->getResponse()->getStatusCode());
198 $this->validateDom($client->getResponse()->getContent(), 'unread');
199
200 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000');
201 $this->assertSame(302, $client->getResponse()->getStatusCode());
202 }
203
204 public function testTags()
205 {
206 $client = $this->getClient();
207 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
208 $user = $em
209 ->getRepository('WallabagUserBundle:User')
210 ->findOneByUsername('admin');
211
212 $config = $user->getConfig();
213 $config->setFeedToken('SUPERTOKEN');
214 $config->setFeedLimit(null);
215 $em->persist($config);
216 $em->flush();
217
218 $client = $this->getClient();
219 $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo');
220
221 $this->assertSame(200, $client->getResponse()->getStatusCode());
222
223 $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo');
224
225 $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000');
226 $this->assertSame(302, $client->getResponse()->getStatusCode());
227 }
228
229 public function dataForRedirect()
230 {
231 return [
232 [
233 '/admin/YZIOAUZIAO/unread.xml',
234 ],
235 [
236 '/admin/YZIOAUZIAO/starred.xml',
237 ],
238 [
239 '/admin/YZIOAUZIAO/archive.xml',
240 ],
241 [
242 '/admin/YZIOAUZIAO/all.xml',
243 ],
244 [
245 '/admin/YZIOAUZIAO/tags/foo.xml',
246 ],
247 ];
248 }
249
250 /**
251 * @dataProvider dataForRedirect
252 */
253 public function testRedirectFromRssToAtom($url)
254 {
255 $client = $this->getClient();
256
257 $client->request('GET', $url);
258
259 $this->assertSame(301, $client->getResponse()->getStatusCode());
260 }
261}
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
deleted file mode 100644
index 2af6e14f..00000000
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ /dev/null
@@ -1,221 +0,0 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class RssControllerTest extends WallabagCoreTestCase
8{
9 public function validateDom($xml, $type, $urlPagination, $nb = null)
10 {
11 $doc = new \DOMDocument();
12 $doc->loadXML($xml);
13
14 $xpath = new \DOMXpath($doc);
15
16 if (null === $nb) {
17 $this->assertGreaterThan(0, $xpath->query('//item')->length);
18 } else {
19 $this->assertSame($nb, $xpath->query('//item')->length);
20 }
21
22 $this->assertSame(1, $xpath->query('/rss')->length);
23 $this->assertSame(1, $xpath->query('/rss/channel')->length);
24
25 $this->assertSame(1, $xpath->query('/rss/channel/title')->length);
26 $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue);
27
28 $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length);
29
30 $this->assertSame(1, $xpath->query('/rss/channel/generator')->length);
31 $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue);
32
33 $this->assertSame(1, $xpath->query('/rss/channel/description')->length);
34 $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue);
35
36 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length);
37 $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
38
39 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length);
40 $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41
42 foreach ($xpath->query('//item') as $item) {
43 $this->assertSame(1, $xpath->query('title', $item)->length);
44 $this->assertSame(1, $xpath->query('source', $item)->length);
45 $this->assertSame(1, $xpath->query('link', $item)->length);
46 $this->assertSame(1, $xpath->query('guid', $item)->length);
47 $this->assertSame(1, $xpath->query('pubDate', $item)->length);
48 $this->assertSame(1, $xpath->query('description', $item)->length);
49 }
50 }
51
52 public function dataForBadUrl()
53 {
54 return [
55 [
56 '/admin/YZIOAUZIAO/unread.xml',
57 ],
58 [
59 '/wallace/YZIOAUZIAO/starred.xml',
60 ],
61 [
62 '/wallace/YZIOAUZIAO/archives.xml',
63 ],
64 [
65 '/wallace/YZIOAUZIAO/all.xml',
66 ],
67 ];
68 }
69
70 /**
71 * @dataProvider dataForBadUrl
72 */
73 public function testBadUrl($url)
74 {
75 $client = $this->getClient();
76
77 $client->request('GET', $url);
78
79 $this->assertSame(404, $client->getResponse()->getStatusCode());
80 }
81
82 public function testUnread()
83 {
84 $client = $this->getClient();
85 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
86 $user = $em
87 ->getRepository('WallabagUserBundle:User')
88 ->findOneByUsername('admin');
89
90 $config = $user->getConfig();
91 $config->setRssToken('SUPERTOKEN');
92 $config->setRssLimit(2);
93 $em->persist($config);
94 $em->flush();
95
96 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
97
98 $this->assertSame(200, $client->getResponse()->getStatusCode());
99
100 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2);
101 }
102
103 public function testStarred()
104 {
105 $client = $this->getClient();
106 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
107 $user = $em
108 ->getRepository('WallabagUserBundle:User')
109 ->findOneByUsername('admin');
110
111 $config = $user->getConfig();
112 $config->setRssToken('SUPERTOKEN');
113 $config->setRssLimit(1);
114 $em->persist($config);
115 $em->flush();
116
117 $client = $this->getClient();
118 $client->request('GET', '/admin/SUPERTOKEN/starred.xml');
119
120 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
121
122 $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred');
123 }
124
125 public function testArchives()
126 {
127 $client = $this->getClient();
128 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
129 $user = $em
130 ->getRepository('WallabagUserBundle:User')
131 ->findOneByUsername('admin');
132
133 $config = $user->getConfig();
134 $config->setRssToken('SUPERTOKEN');
135 $config->setRssLimit(null);
136 $em->persist($config);
137 $em->flush();
138
139 $client = $this->getClient();
140 $client->request('GET', '/admin/SUPERTOKEN/archive.xml');
141
142 $this->assertSame(200, $client->getResponse()->getStatusCode());
143
144 $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive');
145 }
146
147 public function testAll()
148 {
149 $client = $this->getClient();
150 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
151 $user = $em
152 ->getRepository('WallabagUserBundle:User')
153 ->findOneByUsername('admin');
154
155 $config = $user->getConfig();
156 $config->setRssToken('SUPERTOKEN');
157 $config->setRssLimit(null);
158 $em->persist($config);
159 $em->flush();
160
161 $client = $this->getClient();
162 $client->request('GET', '/admin/SUPERTOKEN/all.xml');
163
164 $this->assertSame(200, $client->getResponse()->getStatusCode());
165
166 $this->validateDom($client->getResponse()->getContent(), 'all', 'all');
167 }
168
169 public function testPagination()
170 {
171 $client = $this->getClient();
172 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
173 $user = $em
174 ->getRepository('WallabagUserBundle:User')
175 ->findOneByUsername('admin');
176
177 $config = $user->getConfig();
178 $config->setRssToken('SUPERTOKEN');
179 $config->setRssLimit(1);
180 $em->persist($config);
181 $em->flush();
182
183 $client = $this->getClient();
184
185 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
186 $this->assertSame(200, $client->getResponse()->getStatusCode());
187 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
188
189 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
190 $this->assertSame(200, $client->getResponse()->getStatusCode());
191 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
192
193 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
194 $this->assertSame(302, $client->getResponse()->getStatusCode());
195 }
196
197 public function testTags()
198 {
199 $client = $this->getClient();
200 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
201 $user = $em
202 ->getRepository('WallabagUserBundle:User')
203 ->findOneByUsername('admin');
204
205 $config = $user->getConfig();
206 $config->setRssToken('SUPERTOKEN');
207 $config->setRssLimit(null);
208 $em->persist($config);
209 $em->flush();
210
211 $client = $this->getClient();
212 $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml');
213
214 $this->assertSame(200, $client->getResponse()->getStatusCode());
215
216 $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo');
217
218 $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000');
219 $this->assertSame(302, $client->getResponse()->getStatusCode());
220 }
221}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 395208a2..93019b1f 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -13,7 +13,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
13 $client->followRedirects(); 13 $client->followRedirects();
14 14
15 $crawler = $client->request('GET', '/config'); 15 $crawler = $client->request('GET', '/config');
16 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); 16 $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
17 } 17 }
18 18
19 public function testLoginWithout2Factor() 19 public function testLoginWithout2Factor()
@@ -23,10 +23,10 @@ class SecurityControllerTest extends WallabagCoreTestCase
23 $client->followRedirects(); 23 $client->followRedirects();
24 24
25 $crawler = $client->request('GET', '/config'); 25 $crawler = $client->request('GET', '/config');
26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); 26 $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
27 } 27 }
28 28
29 public function testLoginWith2Factor() 29 public function testLoginWith2FactorEmail()
30 { 30 {
31 $client = $this->getClient(); 31 $client = $this->getClient();
32 32
@@ -42,7 +42,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
42 $user = $em 42 $user = $em
43 ->getRepository('WallabagUserBundle:User') 43 ->getRepository('WallabagUserBundle:User')
44 ->findOneByUsername('admin'); 44 ->findOneByUsername('admin');
45 $user->setTwoFactorAuthentication(true); 45 $user->setEmailTwoFactor(true);
46 $em->persist($user); 46 $em->persist($user);
47 $em->flush(); 47 $em->flush();
48 48
@@ -54,12 +54,12 @@ class SecurityControllerTest extends WallabagCoreTestCase
54 $user = $em 54 $user = $em
55 ->getRepository('WallabagUserBundle:User') 55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin'); 56 ->findOneByUsername('admin');
57 $user->setTwoFactorAuthentication(false); 57 $user->setEmailTwoFactor(false);
58 $em->persist($user); 58 $em->persist($user);
59 $em->flush(); 59 $em->flush();
60 } 60 }
61 61
62 public function testTrustedComputer() 62 public function testLoginWith2FactorGoogle()
63 { 63 {
64 $client = $this->getClient(); 64 $client = $this->getClient();
65 65
@@ -69,15 +69,27 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 return; 69 return;
70 } 70 }
71 71
72 $client->followRedirects();
73
72 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 74 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
73 $user = $em 75 $user = $em
74 ->getRepository('WallabagUserBundle:User') 76 ->getRepository('WallabagUserBundle:User')
75 ->findOneByUsername('admin'); 77 ->findOneByUsername('admin');
78 $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
79 $em->persist($user);
80 $em->flush();
81
82 $this->logInAsUsingHttp('admin');
83 $crawler = $client->request('GET', '/config');
84 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
76 85
77 $date = new \DateTime(); 86 // restore user
78 $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); 87 $user = $em
79 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 88 ->getRepository('WallabagUserBundle:User')
80 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 89 ->findOneByUsername('admin');
90 $user->setGoogleAuthenticatorSecret(null);
91 $em->persist($user);
92 $em->flush();
81 } 93 }
82 94
83 public function testEnabledRegistration() 95 public function testEnabledRegistration()
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 768f4c07..be17dcf5 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -176,4 +176,49 @@ class TagControllerTest extends WallabagCoreTestCase
176 $em->remove($tag); 176 $em->remove($tag);
177 $em->flush(); 177 $em->flush();
178 } 178 }
179
180 public function testRenameTagUsingTheFormInsideTagList()
181 {
182 $this->logInAs('admin');
183 $client = $this->getClient();
184
185 $tag = new Tag();
186 $tag->setLabel($this->tagName);
187 $entry = new Entry($this->getLoggedInUser());
188 $entry->setUrl('http://0.0.0.0/foo');
189 $entry->addTag($tag);
190 $this->getEntityManager()->persist($entry);
191 $this->getEntityManager()->flush();
192 $this->getEntityManager()->clear();
193
194 // We make a first request to set an history and test redirection after tag deletion
195 $crawler = $client->request('GET', '/tag/list');
196 $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
197
198 $data = [
199 'tag[label]' => 'specific label',
200 ];
201
202 $client->submit($form, $data);
203 $this->assertSame(302, $client->getResponse()->getStatusCode());
204
205 $freshEntry = $client->getContainer()
206 ->get('doctrine.orm.entity_manager')
207 ->getRepository('WallabagCoreBundle:Entry')
208 ->find($entry->getId());
209
210 $tags = $freshEntry->getTags()->toArray();
211 foreach ($tags as $key => $item) {
212 $tags[$key] = $item->getLabel();
213 }
214
215 $this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entry anymore.');
216
217 $newTag = $client->getContainer()
218 ->get('doctrine.orm.entity_manager')
219 ->getRepository('WallabagCoreBundle:Tag')
220 ->findOneByLabel('specific label');
221 $this->assertInstanceOf(Tag::class, $newTag, 'Tag "specific label" exists.');
222 $this->assertTrue($newTag->hasEntry($freshEntry), 'Tag "specific label" is assigned to the entry.');
223 }
179} 224}