aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-05-29 11:14:00 +0200
committerGitHub <noreply@github.com>2019-05-29 11:14:00 +0200
commit73ec68b1ffafb792265a3805833e5cd84c966aed (patch)
tree33c6040c050f85c537f8dbf5e91d8c281db092cd /tests/Wallabag/CoreBundle
parent2ba365c7c49556cd23b444dc3bb8d4a8cf08809d (diff)
parent2cbee36a0184786644470a84fdd8c720cfcac58e (diff)
downloadwallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.gz
wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.zst
wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.zip
Merge pull request #3984 from wallabag/2.4
Merge 2.4 into master
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php98
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php18
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php3
-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
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php23
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php77
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php213
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php123
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php3
-rw-r--r--tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php (renamed from tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php)58
-rw-r--r--tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php25
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php4
19 files changed, 971 insertions, 450 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php
new file mode 100644
index 00000000..17eed210
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php
@@ -0,0 +1,98 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
8use Wallabag\CoreBundle\Command\GenerateUrlHashesCommand;
9use Wallabag\CoreBundle\Entity\Entry;
10
11class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
12{
13 public function testRunGenerateUrlHashesCommand()
14 {
15 $application = new Application($this->getClient()->getKernel());
16 $application->add(new GenerateUrlHashesCommand());
17
18 $command = $application->find('wallabag:generate-hashed-urls');
19
20 $tester = new CommandTester($command);
21 $tester->execute([
22 'command' => $command->getName(),
23 ]);
24
25 $this->assertContains('Generating hashed urls for "3" users', $tester->getDisplay());
26 $this->assertContains('Finished generated hashed urls', $tester->getDisplay());
27 }
28
29 public function testRunGenerateUrlHashesCommandWithBadUsername()
30 {
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new GenerateUrlHashesCommand());
33
34 $command = $application->find('wallabag:generate-hashed-urls');
35
36 $tester = new CommandTester($command);
37 $tester->execute([
38 'command' => $command->getName(),
39 'username' => 'unknown',
40 ]);
41
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
43 }
44
45 public function testRunGenerateUrlHashesCommandForUser()
46 {
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new GenerateUrlHashesCommand());
49
50 $command = $application->find('wallabag:generate-hashed-urls');
51
52 $tester = new CommandTester($command);
53 $tester->execute([
54 'command' => $command->getName(),
55 'username' => 'admin',
56 ]);
57
58 $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay());
59 }
60
61 public function testGenerateUrls()
62 {
63 $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html';
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
66
67 $this->logInAs('admin');
68
69 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
70
71 $entry1 = new Entry($user);
72 $entry1->setUrl($url);
73
74 $em->persist($entry1);
75 $em->flush();
76
77 $application = new Application($this->getClient()->getKernel());
78 $application->add(new GenerateUrlHashesCommand());
79
80 $command = $application->find('wallabag:generate-hashed-urls');
81
82 $tester = new CommandTester($command);
83 $tester->execute([
84 'command' => $command->getName(),
85 'username' => 'admin',
86 ]);
87
88 $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay());
89
90 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url);
91
92 $this->assertSame($entry->getHashedUrl(), hash('sha1', $url));
93
94 $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url');
95 $query->setParameter('url', $url);
96 $query->execute();
97 }
98}
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index bd351b18..d8928451 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand;
18 18
19class InstallCommandTest extends WallabagCoreTestCase 19class InstallCommandTest extends WallabagCoreTestCase
20{ 20{
21 public static function setUpBeforeClass()
22 {
23 // disable doctrine-test-bundle
24 StaticDriver::setKeepStaticConnections(false);
25 }
26
27 public static function tearDownAfterClass()
28 {
29 // enable doctrine-test-bundle
30 StaticDriver::setKeepStaticConnections(true);
31 }
32
21 public function setUp() 33 public function setUp()
22 { 34 {
23 parent::setUp(); 35 parent::setUp();
@@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase
51 parent::setUp(); 63 parent::setUp();
52 } 64 }
53 65
54 // disable doctrine-test-bundle
55 StaticDriver::setKeepStaticConnections(false);
56
57 $this->resetDatabase($this->getClient()); 66 $this->resetDatabase($this->getClient());
58 } 67 }
59 68
@@ -62,6 +71,7 @@ class InstallCommandTest extends WallabagCoreTestCase
62 $databasePath = getenv('TEST_DATABASE_PATH'); 71 $databasePath = getenv('TEST_DATABASE_PATH');
63 // Remove variable environnement 72 // Remove variable environnement
64 putenv('TEST_DATABASE_PATH'); 73 putenv('TEST_DATABASE_PATH');
74
65 if ($databasePath && file_exists($databasePath)) { 75 if ($databasePath && file_exists($databasePath)) {
66 unlink($databasePath); 76 unlink($databasePath);
67 } else { 77 } else {
@@ -71,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase
71 $this->resetDatabase($client); 81 $this->resetDatabase($client);
72 } 82 }
73 83
74 // enable doctrine-test-bundle
75 StaticDriver::setKeepStaticConnections(true);
76 parent::tearDown(); 84 parent::tearDown();
77 } 85 }
78 86
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
index b13f6519..c4bd6dac 100644
--- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
@@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
26 { 26 {
27 parent::setUp(); 27 parent::setUp();
28 28
29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); 29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
30 30
31 $user = $userRepository->findOneByUserName('admin'); 31 $user = $userRepository->findOneByUserName('admin');
32 $this->adminEntry = new Entry($user); 32 $this->adminEntry = new Entry($user);
@@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
60 60
61 $reloadedEntries = $this->getClient() 61 $reloadedEntries = $this->getClient()
62 ->getContainer() 62 ->getContainer()
63 ->get('wallabag_core.entry_repository') 63 ->get('wallabag_core.entry_repository.test')
64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); 64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
65 65
66 foreach ($reloadedEntries as $reloadedEntry) { 66 foreach ($reloadedEntries as $reloadedEntry) {
@@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
84 'interactive' => false, 84 'interactive' => false,
85 ]); 85 ]);
86 86
87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); 87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
88 88
89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); 89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
90 $this->assertNotEmpty($reloadedAdminEntry->getContent()); 90 $this->assertNotEmpty($reloadedAdminEntry->getContent());
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
index 9b34f2a0..ed383a2c 100644
--- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
@@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase
59 $this->assertContains('Username: admin', $tester->getDisplay()); 59 $this->assertContains('Username: admin', $tester->getDisplay());
60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); 60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay());
61 $this->assertContains('Display name: Big boss', $tester->getDisplay()); 61 $this->assertContains('Display name: Big boss', $tester->getDisplay());
62 $this->assertContains('2FA activated: no', $tester->getDisplay()); 62 $this->assertContains('2FA (email) activated', $tester->getDisplay());
63 $this->assertContains('2FA (OTP) activated', $tester->getDisplay());
63 } 64 }
64 65
65 public function testShowUser() 66 public function testShowUser()
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}
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
index 93edfde8..ff0a9602 100644
--- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
@@ -56,4 +56,27 @@ class UserLocaleListenerTest extends TestCase
56 56
57 $this->assertNull($session->get('_locale')); 57 $this->assertNull($session->get('_locale'));
58 } 58 }
59
60 public function testWithLanguageFromSession()
61 {
62 $session = new Session(new MockArraySessionStorage());
63 $listener = new UserLocaleListener($session);
64 $session->set('_locale', 'de');
65
66 $user = new User();
67 $user->setEnabled(true);
68
69 $config = new Config($user);
70 $config->setLanguage('fr');
71
72 $user->setConfig($config);
73
74 $userToken = new UsernamePasswordToken($user, '', 'test');
75 $request = Request::create('/');
76 $event = new InteractiveLoginEvent($request, $userToken);
77
78 $listener->onInteractiveLogin($event);
79
80 $this->assertSame('de', $session->get('_locale'));
81 }
59} 82}
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
index 845762dc..9e0a9136 100644
--- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -12,6 +12,8 @@ use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder;
12 12
13class GrabySiteConfigBuilderTest extends WallabagCoreTestCase 13class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
14{ 14{
15 private $builder;
16
15 public function testBuildConfigExists() 17 public function testBuildConfigExists()
16 { 18 {
17 $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') 19 $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
@@ -29,7 +31,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
29 $grabyConfigBuilderMock 31 $grabyConfigBuilderMock
30 ->method('buildForHost') 32 ->method('buildForHost')
31 ->with('api.example.com') 33 ->with('api.example.com')
32 ->will($this->returnValue($grabySiteConfig)); 34 ->willReturn($grabySiteConfig);
33 35
34 $logger = new Logger('foo'); 36 $logger = new Logger('foo');
35 $handler = new TestHandler(); 37 $handler = new TestHandler();
@@ -88,7 +90,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
88 $grabyConfigBuilderMock 90 $grabyConfigBuilderMock
89 ->method('buildForHost') 91 ->method('buildForHost')
90 ->with('unknown.com') 92 ->with('unknown.com')
91 ->will($this->returnValue(new GrabySiteConfig())); 93 ->willReturn(new GrabySiteConfig());
92 94
93 $logger = new Logger('foo'); 95 $logger = new Logger('foo');
94 $handler = new TestHandler(); 96 $handler = new TestHandler();
@@ -130,6 +132,73 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
130 $this->assertCount(1, $records, 'One log was recorded'); 132 $this->assertCount(1, $records, 'One log was recorded');
131 } 133 }
132 134
135 public function testBuildConfigWithBadExtraFields()
136 {
137 $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
138 ->disableOriginalConstructor()
139 ->getMock();
140
141 $grabySiteConfig = new GrabySiteConfig();
142 $grabySiteConfig->requires_login = true;
143 $grabySiteConfig->login_uri = 'http://www.example.com/login';
144 $grabySiteConfig->login_username_field = 'login';
145 $grabySiteConfig->login_password_field = 'password';
146 $grabySiteConfig->login_extra_fields = ['field'];
147 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
148
149 $grabyConfigBuilderMock
150 ->method('buildForHost')
151 ->with('example.com')
152 ->willReturn($grabySiteConfig);
153
154 $logger = new Logger('foo');
155 $handler = new TestHandler();
156 $logger->pushHandler($handler);
157
158 $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository')
159 ->disableOriginalConstructor()
160 ->getMock();
161 $siteCrentialRepo->expects($this->once())
162 ->method('findOneByHostsAndUser')
163 ->with(['example.com', '.com'], 1)
164 ->willReturn(['username' => 'foo', 'password' => 'bar']);
165
166 $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
167 ->disableOriginalConstructor()
168 ->getMock();
169 $user->expects($this->once())
170 ->method('getId')
171 ->willReturn(1);
172
173 $token = new UsernamePasswordToken($user, 'pass', 'provider');
174
175 $tokenStorage = new TokenStorage();
176 $tokenStorage->setToken($token);
177
178 $this->builder = new GrabySiteConfigBuilder(
179 $grabyConfigBuilderMock,
180 $tokenStorage,
181 $siteCrentialRepo,
182 $logger
183 );
184
185 $config = $this->builder->buildForHost('www.example.com');
186
187 $this->assertSame('example.com', $config->getHost());
188 $this->assertTrue($config->requiresLogin());
189 $this->assertSame('http://www.example.com/login', $config->getLoginUri());
190 $this->assertSame('login', $config->getUsernameField());
191 $this->assertSame('password', $config->getPasswordField());
192 $this->assertSame([], $config->getExtraFields());
193 $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath());
194 $this->assertSame('foo', $config->getUsername());
195 $this->assertSame('bar', $config->getPassword());
196
197 $records = $handler->getRecords();
198
199 $this->assertCount(1, $records, 'One log was recorded');
200 }
201
133 public function testBuildConfigUserNotDefined() 202 public function testBuildConfigUserNotDefined()
134 { 203 {
135 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') 204 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
@@ -139,7 +208,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
139 $grabyConfigBuilderMock 208 $grabyConfigBuilderMock
140 ->method('buildForHost') 209 ->method('buildForHost')
141 ->with('unknown.com') 210 ->with('unknown.com')
142 ->will($this->returnValue(new GrabySiteConfig())); 211 ->willReturn(new GrabySiteConfig());
143 212
144 $logger = new Logger('foo'); 213 $logger = new Logger('foo');
145 $handler = new TestHandler(); 214 $handler = new TestHandler();
@@ -210,7 +279,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
210 $grabyConfigBuilderMock 279 $grabyConfigBuilderMock
211 ->method('buildForHost') 280 ->method('buildForHost')
212 ->with($host) 281 ->with($host)
213 ->will($this->returnValue($grabySiteConfig)); 282 ->willReturn($grabySiteConfig);
214 283
215 $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') 284 $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
216 ->disableOriginalConstructor() 285 ->disableOriginalConstructor()
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 3dd9273c..9ce72c79 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -36,7 +36,9 @@ class ContentProxyTest extends TestCase
36 'html' => false, 36 'html' => false,
37 'title' => '', 37 'title' => '',
38 'url' => '', 38 'url' => '',
39 'content_type' => '', 39 'headers' => [
40 'content-type' => '',
41 ],
40 'language' => '', 42 'language' => '',
41 ]); 43 ]);
42 44
@@ -71,7 +73,9 @@ class ContentProxyTest extends TestCase
71 'html' => false, 73 'html' => false,
72 'title' => '', 74 'title' => '',
73 'url' => '', 75 'url' => '',
74 'content_type' => '', 76 'headers' => [
77 'content-type' => '',
78 ],
75 'language' => '', 79 'language' => '',
76 ]); 80 ]);
77 81
@@ -104,15 +108,14 @@ class ContentProxyTest extends TestCase
104 ->method('fetchContent') 108 ->method('fetchContent')
105 ->willReturn([ 109 ->willReturn([
106 'html' => false, 110 'html' => false,
107 'title' => '', 111 'title' => 'my title',
108 'url' => '', 112 'url' => '',
109 'content_type' => '', 113 'headers' => [
114 'content-type' => '',
115 ],
110 'language' => '', 116 'language' => '',
111 'status' => '', 117 'status' => '',
112 'open_graph' => [ 118 'description' => 'desc',
113 'og_title' => 'my title',
114 'og_description' => 'desc',
115 ],
116 ]); 119 ]);
117 120
118 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 121 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
@@ -147,13 +150,12 @@ class ContentProxyTest extends TestCase
147 'html' => str_repeat('this is my content', 325), 150 'html' => str_repeat('this is my content', 325),
148 'title' => 'this is my title', 151 'title' => 'this is my title',
149 'url' => 'http://1.1.1.1', 152 'url' => 'http://1.1.1.1',
150 'content_type' => 'text/html',
151 'language' => 'fr', 153 'language' => 'fr',
152 'status' => '200', 154 'status' => '200',
153 'open_graph' => [ 155 'description' => 'OG desc',
154 'og_title' => 'my OG title', 156 'image' => 'http://3.3.3.3/cover.jpg',
155 'og_description' => 'OG desc', 157 'headers' => [
156 'og_image' => 'http://3.3.3.3/cover.jpg', 158 'content-type' => 'text/html',
157 ], 159 ],
158 ]); 160 ]);
159 161
@@ -163,7 +165,7 @@ class ContentProxyTest extends TestCase
163 165
164 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 166 $this->assertSame('http://1.1.1.1', $entry->getUrl());
165 $this->assertSame('this is my title', $entry->getTitle()); 167 $this->assertSame('this is my title', $entry->getTitle());
166 $this->assertContains('this is my content', $entry->getContent()); 168 $this->assertContains('content', $entry->getContent());
167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 169 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
168 $this->assertSame('text/html', $entry->getMimetype()); 170 $this->assertSame('text/html', $entry->getMimetype());
169 $this->assertSame('fr', $entry->getLanguage()); 171 $this->assertSame('fr', $entry->getLanguage());
@@ -189,13 +191,12 @@ class ContentProxyTest extends TestCase
189 'html' => str_repeat('this is my content', 325), 191 'html' => str_repeat('this is my content', 325),
190 'title' => 'this is my title', 192 'title' => 'this is my title',
191 'url' => 'http://1.1.1.1', 193 'url' => 'http://1.1.1.1',
192 'content_type' => 'text/html',
193 'language' => 'fr', 194 'language' => 'fr',
194 'status' => '200', 195 'status' => '200',
195 'open_graph' => [ 196 'description' => 'OG desc',
196 'og_title' => 'my OG title', 197 'image' => null,
197 'og_description' => 'OG desc', 198 'headers' => [
198 'og_image' => null, 199 'content-type' => 'text/html',
199 ], 200 ],
200 ]); 201 ]);
201 202
@@ -205,7 +206,7 @@ class ContentProxyTest extends TestCase
205 206
206 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 207 $this->assertSame('http://1.1.1.1', $entry->getUrl());
207 $this->assertSame('this is my title', $entry->getTitle()); 208 $this->assertSame('this is my title', $entry->getTitle());
208 $this->assertContains('this is my content', $entry->getContent()); 209 $this->assertContains('content', $entry->getContent());
209 $this->assertNull($entry->getPreviewPicture()); 210 $this->assertNull($entry->getPreviewPicture());
210 $this->assertSame('text/html', $entry->getMimetype()); 211 $this->assertSame('text/html', $entry->getMimetype());
211 $this->assertSame('fr', $entry->getLanguage()); 212 $this->assertSame('fr', $entry->getLanguage());
@@ -214,6 +215,86 @@ class ContentProxyTest extends TestCase
214 $this->assertSame('1.1.1.1', $entry->getDomainName()); 215 $this->assertSame('1.1.1.1', $entry->getDomainName());
215 } 216 }
216 217
218 public function testWithContentAndContentImage()
219 {
220 $tagger = $this->getTaggerMock();
221 $tagger->expects($this->once())
222 ->method('tag');
223
224 $graby = $this->getMockBuilder('Graby\Graby')
225 ->setMethods(['fetchContent'])
226 ->disableOriginalConstructor()
227 ->getMock();
228
229 $graby->expects($this->any())
230 ->method('fetchContent')
231 ->willReturn([
232 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>",
233 'title' => 'this is my title',
234 'url' => 'http://1.1.1.1',
235 'headers' => [
236 'content-type' => 'text/html',
237 ],
238 'language' => 'fr',
239 'status' => '200',
240 'image' => null,
241 ]);
242
243 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
244 $entry = new Entry(new User());
245 $proxy->updateEntry($entry, 'http://0.0.0.0');
246
247 $this->assertSame('http://1.1.1.1', $entry->getUrl());
248 $this->assertSame('this is my title', $entry->getTitle());
249 $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", $entry->getContent());
250 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
251 $this->assertSame('text/html', $entry->getMimetype());
252 $this->assertSame('fr', $entry->getLanguage());
253 $this->assertSame('200', $entry->getHttpStatus());
254 $this->assertSame(0.0, $entry->getReadingTime());
255 $this->assertSame('1.1.1.1', $entry->getDomainName());
256 }
257
258 public function testWithContentImageAndOgImage()
259 {
260 $tagger = $this->getTaggerMock();
261 $tagger->expects($this->once())
262 ->method('tag');
263
264 $graby = $this->getMockBuilder('Graby\Graby')
265 ->setMethods(['fetchContent'])
266 ->disableOriginalConstructor()
267 ->getMock();
268
269 $graby->expects($this->any())
270 ->method('fetchContent')
271 ->willReturn([
272 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>",
273 'title' => 'this is my title',
274 'url' => 'http://1.1.1.1',
275 'headers' => [
276 'content-type' => 'text/html',
277 ],
278 'language' => 'fr',
279 'status' => '200',
280 'image' => 'http://3.3.3.3/cover.jpg',
281 ]);
282
283 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
284 $entry = new Entry(new User());
285 $proxy->updateEntry($entry, 'http://0.0.0.0');
286
287 $this->assertSame('http://1.1.1.1', $entry->getUrl());
288 $this->assertSame('this is my title', $entry->getTitle());
289 $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", $entry->getContent());
290 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
291 $this->assertSame('text/html', $entry->getMimetype());
292 $this->assertSame('fr', $entry->getLanguage());
293 $this->assertSame('200', $entry->getHttpStatus());
294 $this->assertSame(0.0, $entry->getReadingTime());
295 $this->assertSame('1.1.1.1', $entry->getDomainName());
296 }
297
217 public function testWithContentAndBadLanguage() 298 public function testWithContentAndBadLanguage()
218 { 299 {
219 $tagger = $this->getTaggerMock(); 300 $tagger = $this->getTaggerMock();
@@ -236,9 +317,11 @@ class ContentProxyTest extends TestCase
236 'html' => str_repeat('this is my content', 325), 317 'html' => str_repeat('this is my content', 325),
237 'title' => 'this is my title', 318 'title' => 'this is my title',
238 'url' => 'http://1.1.1.1', 319 'url' => 'http://1.1.1.1',
239 'content_type' => 'text/html',
240 'language' => 'dontexist', 320 'language' => 'dontexist',
241 'status' => '200', 321 'status' => '200',
322 'headers' => [
323 'content-type' => 'text/html',
324 ],
242 ]); 325 ]);
243 326
244 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); 327 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage);
@@ -247,7 +330,7 @@ class ContentProxyTest extends TestCase
247 330
248 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 331 $this->assertSame('http://1.1.1.1', $entry->getUrl());
249 $this->assertSame('this is my title', $entry->getTitle()); 332 $this->assertSame('this is my title', $entry->getTitle());
250 $this->assertContains('this is my content', $entry->getContent()); 333 $this->assertContains('content', $entry->getContent());
251 $this->assertSame('text/html', $entry->getMimetype()); 334 $this->assertSame('text/html', $entry->getMimetype());
252 $this->assertNull($entry->getLanguage()); 335 $this->assertNull($entry->getLanguage());
253 $this->assertSame('200', $entry->getHttpStatus()); 336 $this->assertSame('200', $entry->getHttpStatus());
@@ -280,14 +363,13 @@ class ContentProxyTest extends TestCase
280 'html' => str_repeat('this is my content', 325), 363 'html' => str_repeat('this is my content', 325),
281 'title' => 'this is my title', 364 'title' => 'this is my title',
282 'url' => 'http://1.1.1.1', 365 'url' => 'http://1.1.1.1',
283 'content_type' => 'text/html', 366 'headers' => [
367 'content-type' => 'text/html',
368 ],
284 'language' => 'fr', 369 'language' => 'fr',
285 'status' => '200', 370 'status' => '200',
286 'open_graph' => [ 371 'description' => 'OG desc',
287 'og_title' => 'my OG title', 372 'image' => 'https://',
288 'og_description' => 'OG desc',
289 'og_image' => 'https://',
290 ],
291 ]); 373 ]);
292 374
293 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); 375 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage);
@@ -296,7 +378,7 @@ class ContentProxyTest extends TestCase
296 378
297 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 379 $this->assertSame('http://1.1.1.1', $entry->getUrl());
298 $this->assertSame('this is my title', $entry->getTitle()); 380 $this->assertSame('this is my title', $entry->getTitle());
299 $this->assertContains('this is my content', $entry->getContent()); 381 $this->assertContains('content', $entry->getContent());
300 $this->assertNull($entry->getPreviewPicture()); 382 $this->assertNull($entry->getPreviewPicture());
301 $this->assertSame('text/html', $entry->getMimetype()); 383 $this->assertSame('text/html', $entry->getMimetype());
302 $this->assertSame('fr', $entry->getLanguage()); 384 $this->assertSame('fr', $entry->getLanguage());
@@ -320,19 +402,19 @@ class ContentProxyTest extends TestCase
320 'html' => str_repeat('this is my content', 325), 402 'html' => str_repeat('this is my content', 325),
321 'title' => 'this is my title', 403 'title' => 'this is my title',
322 'url' => 'http://1.1.1.1', 404 'url' => 'http://1.1.1.1',
323 'content_type' => 'text/html',
324 'language' => 'fr', 405 'language' => 'fr',
325 'date' => '1395635872', 406 'date' => '1395635872',
326 'authors' => ['Jeremy', 'Nico', 'Thomas'], 407 'authors' => ['Jeremy', 'Nico', 'Thomas'],
327 'all_headers' => [ 408 'headers' => [
328 'Cache-Control' => 'no-cache', 409 'cache-control' => 'no-cache',
410 'content-type' => 'text/html',
329 ], 411 ],
330 ] 412 ]
331 ); 413 );
332 414
333 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 415 $this->assertSame('http://1.1.1.1', $entry->getUrl());
334 $this->assertSame('this is my title', $entry->getTitle()); 416 $this->assertSame('this is my title', $entry->getTitle());
335 $this->assertContains('this is my content', $entry->getContent()); 417 $this->assertContains('content', $entry->getContent());
336 $this->assertSame('text/html', $entry->getMimetype()); 418 $this->assertSame('text/html', $entry->getMimetype());
337 $this->assertSame('fr', $entry->getLanguage()); 419 $this->assertSame('fr', $entry->getLanguage());
338 $this->assertSame(4.0, $entry->getReadingTime()); 420 $this->assertSame(4.0, $entry->getReadingTime());
@@ -363,15 +445,17 @@ class ContentProxyTest extends TestCase
363 'html' => str_repeat('this is my content', 325), 445 'html' => str_repeat('this is my content', 325),
364 'title' => 'this is my title', 446 'title' => 'this is my title',
365 'url' => 'http://1.1.1.1', 447 'url' => 'http://1.1.1.1',
366 'content_type' => 'text/html',
367 'language' => 'fr', 448 'language' => 'fr',
368 'date' => '2016-09-08T11:55:58+0200', 449 'date' => '2016-09-08T11:55:58+0200',
450 'headers' => [
451 'content-type' => 'text/html',
452 ],
369 ] 453 ]
370 ); 454 );
371 455
372 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 456 $this->assertSame('http://1.1.1.1', $entry->getUrl());
373 $this->assertSame('this is my title', $entry->getTitle()); 457 $this->assertSame('this is my title', $entry->getTitle());
374 $this->assertContains('this is my content', $entry->getContent()); 458 $this->assertContains('content', $entry->getContent());
375 $this->assertSame('text/html', $entry->getMimetype()); 459 $this->assertSame('text/html', $entry->getMimetype());
376 $this->assertSame('fr', $entry->getLanguage()); 460 $this->assertSame('fr', $entry->getLanguage());
377 $this->assertSame(4.0, $entry->getReadingTime()); 461 $this->assertSame(4.0, $entry->getReadingTime());
@@ -398,15 +482,17 @@ class ContentProxyTest extends TestCase
398 'html' => str_repeat('this is my content', 325), 482 'html' => str_repeat('this is my content', 325),
399 'title' => 'this is my title', 483 'title' => 'this is my title',
400 'url' => 'http://1.1.1.1', 484 'url' => 'http://1.1.1.1',
401 'content_type' => 'text/html',
402 'language' => 'fr', 485 'language' => 'fr',
403 'date' => '01 02 2012', 486 'date' => '01 02 2012',
487 'headers' => [
488 'content-type' => 'text/html',
489 ],
404 ] 490 ]
405 ); 491 );
406 492
407 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 493 $this->assertSame('http://1.1.1.1', $entry->getUrl());
408 $this->assertSame('this is my title', $entry->getTitle()); 494 $this->assertSame('this is my title', $entry->getTitle());
409 $this->assertContains('this is my content', $entry->getContent()); 495 $this->assertContains('content', $entry->getContent());
410 $this->assertSame('text/html', $entry->getMimetype()); 496 $this->assertSame('text/html', $entry->getMimetype());
411 $this->assertSame('fr', $entry->getLanguage()); 497 $this->assertSame('fr', $entry->getLanguage());
412 $this->assertSame(4.0, $entry->getReadingTime()); 498 $this->assertSame(4.0, $entry->getReadingTime());
@@ -415,7 +501,7 @@ class ContentProxyTest extends TestCase
415 501
416 $records = $handler->getRecords(); 502 $records = $handler->getRecords();
417 503
418 $this->assertCount(1, $records); 504 $this->assertCount(3, $records);
419 $this->assertContains('Error while defining date', $records[0]['message']); 505 $this->assertContains('Error while defining date', $records[0]['message']);
420 } 506 }
421 507
@@ -435,8 +521,10 @@ class ContentProxyTest extends TestCase
435 'html' => str_repeat('this is my content', 325), 521 'html' => str_repeat('this is my content', 325),
436 'title' => 'this is my title', 522 'title' => 'this is my title',
437 'url' => 'http://1.1.1.1', 523 'url' => 'http://1.1.1.1',
438 'content_type' => 'text/html',
439 'language' => 'fr', 524 'language' => 'fr',
525 'headers' => [
526 'content-type' => 'text/html',
527 ],
440 ] 528 ]
441 ); 529 );
442 530
@@ -475,13 +563,13 @@ class ContentProxyTest extends TestCase
475 'html' => $html, 563 'html' => $html,
476 'title' => 'this is my title', 564 'title' => 'this is my title',
477 'url' => 'http://1.1.1.1', 565 'url' => 'http://1.1.1.1',
478 'content_type' => 'text/html',
479 'language' => 'fr', 566 'language' => 'fr',
480 'status' => '200', 567 'status' => '200',
481 'open_graph' => [ 568 //'og_title' => 'my OG title',
482 'og_title' => 'my OG title', 569 'description' => 'OG desc',
483 'og_description' => 'OG desc', 570 'image' => 'http://3.3.3.3/cover.jpg',
484 'og_image' => 'http://3.3.3.3/cover.jpg', 571 'headers' => [
572 'content-type' => 'text/html',
485 ], 573 ],
486 ] 574 ]
487 ); 575 );
@@ -513,9 +601,10 @@ class ContentProxyTest extends TestCase
513 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', 601 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>',
514 'title' => 'this is my title', 602 'title' => 'this is my title',
515 'url' => 'http://1.1.1.1/image.jpg', 603 'url' => 'http://1.1.1.1/image.jpg',
516 'content_type' => 'image/jpeg',
517 'status' => '200', 604 'status' => '200',
518 'open_graph' => [], 605 'headers' => [
606 'content-type' => 'image/jpeg',
607 ],
519 ]); 608 ]);
520 609
521 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 610 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
@@ -553,7 +642,9 @@ class ContentProxyTest extends TestCase
553 'html' => false, 642 'html' => false,
554 'title' => $actualTitle, 643 'title' => $actualTitle,
555 'url' => '', 644 'url' => '',
556 'content_type' => 'text/html', 645 'headers' => [
646 'content-type' => 'text/html',
647 ],
557 'language' => '', 648 'language' => '',
558 ]); 649 ]);
559 650
@@ -588,7 +679,9 @@ class ContentProxyTest extends TestCase
588 'html' => false, 679 'html' => false,
589 'title' => $actualTitle, 680 'title' => $actualTitle,
590 'url' => '', 681 'url' => '',
591 'content_type' => 'text/html', 682 'headers' => [
683 'content-type' => 'text/html',
684 ],
592 'language' => '', 685 'language' => '',
593 ]); 686 ]);
594 687
@@ -622,7 +715,9 @@ class ContentProxyTest extends TestCase
622 'html' => false, 715 'html' => false,
623 'title' => $actualTitle, 716 'title' => $actualTitle,
624 'url' => '', 717 'url' => '',
625 'content_type' => 'application/pdf', 718 'headers' => [
719 'content-type' => 'application/pdf',
720 ],
626 'language' => '', 721 'language' => '',
627 ]); 722 ]);
628 723
@@ -656,7 +751,9 @@ class ContentProxyTest extends TestCase
656 'html' => false, 751 'html' => false,
657 'title' => $actualTitle, 752 'title' => $actualTitle,
658 'url' => '', 753 'url' => '',
659 'content_type' => 'application/pdf', 754 'headers' => [
755 'content-type' => 'application/pdf',
756 ],
660 'language' => '', 757 'language' => '',
661 ]); 758 ]);
662 759
@@ -690,7 +787,9 @@ class ContentProxyTest extends TestCase
690 'html' => false, 787 'html' => false,
691 'title' => $actualTitle, 788 'title' => $actualTitle,
692 'url' => '', 789 'url' => '',
693 'content_type' => 'application/pdf', 790 'headers' => [
791 'content-type' => 'application/pdf',
792 ],
694 'language' => '', 793 'language' => '',
695 ]); 794 ]);
696 795
@@ -725,7 +824,9 @@ class ContentProxyTest extends TestCase
725 'html' => false, 824 'html' => false,
726 'title' => $actualTitle, 825 'title' => $actualTitle,
727 'url' => '', 826 'url' => '',
728 'content_type' => 'application/pdf', 827 'headers' => [
828 'content-type' => 'application/pdf',
829 ],
729 'language' => '', 830 'language' => '',
730 ]); 831 ]);
731 832
@@ -855,7 +956,9 @@ class ContentProxyTest extends TestCase
855 'html' => false, 956 'html' => false,
856 'title' => '', 957 'title' => '',
857 'url' => $content_url, 958 'url' => $content_url,
858 'content_type' => '', 959 'headers' => [
960 'content-type' => '',
961 ],
859 'language' => '', 962 'language' => '',
860 ], 963 ],
861 true 964 true
@@ -886,7 +989,9 @@ class ContentProxyTest extends TestCase
886 } 989 }
887 990
888 /** 991 /**
889 * https://stackoverflow.com/a/18506801. 992 * Convert hex to string.
993 *
994 * @see https://stackoverflow.com/a/18506801
890 * 995 *
891 * @param $hex 996 * @param $hex
892 * 997 *
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
index cda5f843..3c720425 100644
--- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
@@ -2,10 +2,8 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use GuzzleHttp\Client; 5use GuzzleHttp\Psr7\Response;
6use GuzzleHttp\Message\Response; 6use Http\Mock\Client as HttpMockClient;
7use GuzzleHttp\Stream\Stream;
8use GuzzleHttp\Subscriber\Mock;
9use Monolog\Handler\TestHandler; 7use Monolog\Handler\TestHandler;
10use Monolog\Logger; 8use Monolog\Logger;
11use PHPUnit\Framework\TestCase; 9use PHPUnit\Framework\TestCase;
@@ -32,18 +30,14 @@ class DownloadImagesTest extends TestCase
32 */ 30 */
33 public function testProcessHtml($html, $url) 31 public function testProcessHtml($html, $url)
34 { 32 {
35 $client = new Client(); 33 $httpMockClient = new HttpMockClient();
36 34
37 $mock = new Mock([ 35 $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
38 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))),
39 ]);
40
41 $client->getEmitter()->attach($mock);
42 36
43 $logHandler = new TestHandler(); 37 $logHandler = new TestHandler();
44 $logger = new Logger('test', [$logHandler]); 38 $logger = new Logger('test', [$logHandler]);
45 39
46 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 40 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
47 41
48 $res = $download->processHtml(123, $html, $url); 42 $res = $download->processHtml(123, $html, $url);
49 43
@@ -53,18 +47,13 @@ class DownloadImagesTest extends TestCase
53 47
54 public function testProcessHtmlWithBadImage() 48 public function testProcessHtmlWithBadImage()
55 { 49 {
56 $client = new Client(); 50 $httpMockClient = new HttpMockClient();
57 51 $httpMockClient->addResponse(new Response(200, ['content-type' => 'application/json'], ''));
58 $mock = new Mock([
59 new Response(200, ['content-type' => 'application/json'], Stream::factory('')),
60 ]);
61
62 $client->getEmitter()->attach($mock);
63 52
64 $logHandler = new TestHandler(); 53 $logHandler = new TestHandler();
65 $logger = new Logger('test', [$logHandler]); 54 $logger = new Logger('test', [$logHandler]);
66 55
67 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 56 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
68 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); 57 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
69 58
70 $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); 59 $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type');
@@ -85,18 +74,13 @@ class DownloadImagesTest extends TestCase
85 */ 74 */
86 public function testProcessSingleImage($header, $extension) 75 public function testProcessSingleImage($header, $extension)
87 { 76 {
88 $client = new Client(); 77 $httpMockClient = new HttpMockClient();
89 78 $httpMockClient->addResponse(new Response(200, ['content-type' => $header], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
90 $mock = new Mock([
91 new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))),
92 ]);
93
94 $client->getEmitter()->attach($mock);
95 79
96 $logHandler = new TestHandler(); 80 $logHandler = new TestHandler();
97 $logger = new Logger('test', [$logHandler]); 81 $logger = new Logger('test', [$logHandler]);
98 82
99 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 83 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
100 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); 84 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
101 85
102 $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); 86 $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res);
@@ -104,18 +88,13 @@ class DownloadImagesTest extends TestCase
104 88
105 public function testProcessSingleImageWithBadUrl() 89 public function testProcessSingleImageWithBadUrl()
106 { 90 {
107 $client = new Client(); 91 $httpMockClient = new HttpMockClient();
108 92 $httpMockClient->addResponse(new Response(404, []));
109 $mock = new Mock([
110 new Response(404, []),
111 ]);
112
113 $client->getEmitter()->attach($mock);
114 93
115 $logHandler = new TestHandler(); 94 $logHandler = new TestHandler();
116 $logger = new Logger('test', [$logHandler]); 95 $logger = new Logger('test', [$logHandler]);
117 96
118 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 97 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
119 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); 98 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
120 99
121 $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); 100 $this->assertFalse($res, 'Image can not be found, so it will not be replaced');
@@ -123,18 +102,13 @@ class DownloadImagesTest extends TestCase
123 102
124 public function testProcessSingleImageWithBadImage() 103 public function testProcessSingleImageWithBadImage()
125 { 104 {
126 $client = new Client(); 105 $httpMockClient = new HttpMockClient();
127 106 $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], ''));
128 $mock = new Mock([
129 new Response(200, ['content-type' => 'image/png'], Stream::factory('')),
130 ]);
131
132 $client->getEmitter()->attach($mock);
133 107
134 $logHandler = new TestHandler(); 108 $logHandler = new TestHandler();
135 $logger = new Logger('test', [$logHandler]); 109 $logger = new Logger('test', [$logHandler]);
136 110
137 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 111 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
138 $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); 112 $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
139 113
140 $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); 114 $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced');
@@ -142,18 +116,13 @@ class DownloadImagesTest extends TestCase
142 116
143 public function testProcessSingleImageFailAbsolute() 117 public function testProcessSingleImageFailAbsolute()
144 { 118 {
145 $client = new Client(); 119 $httpMockClient = new HttpMockClient();
146 120 $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
147 $mock = new Mock([
148 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))),
149 ]);
150
151 $client->getEmitter()->attach($mock);
152 121
153 $logHandler = new TestHandler(); 122 $logHandler = new TestHandler();
154 $logger = new Logger('test', [$logHandler]); 123 $logger = new Logger('test', [$logHandler]);
155 124
156 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 125 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
157 $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); 126 $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY');
158 127
159 $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); 128 $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced');
@@ -161,18 +130,13 @@ class DownloadImagesTest extends TestCase
161 130
162 public function testProcessRealImage() 131 public function testProcessRealImage()
163 { 132 {
164 $client = new Client(); 133 $httpMockClient = new HttpMockClient();
165 134 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
166 $mock = new Mock([
167 new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
168 ]);
169
170 $client->getEmitter()->attach($mock);
171 135
172 $logHandler = new TestHandler(); 136 $logHandler = new TestHandler();
173 $logger = new Logger('test', [$logHandler]); 137 $logger = new Logger('test', [$logHandler]);
174 138
175 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 139 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
176 140
177 $res = $download->processSingleImage( 141 $res = $download->processSingleImage(
178 123, 142 123,
@@ -186,20 +150,15 @@ class DownloadImagesTest extends TestCase
186 150
187 public function testProcessImageWithSrcset() 151 public function testProcessImageWithSrcset()
188 { 152 {
189 $client = new Client(); 153 $httpMockClient = new HttpMockClient();
190 154 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
191 $mock = new Mock([ 155 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
192 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), 156 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
193 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
194 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
195 ]);
196
197 $client->getEmitter()->attach($mock);
198 157
199 $logHandler = new TestHandler(); 158 $logHandler = new TestHandler();
200 $logger = new Logger('test', [$logHandler]); 159 $logger = new Logger('test', [$logHandler]);
201 160
202 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 161 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
203 $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); 162 $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/');
204 163
205 $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); 164 $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced');
@@ -207,20 +166,15 @@ class DownloadImagesTest extends TestCase
207 166
208 public function testProcessImageWithTrickySrcset() 167 public function testProcessImageWithTrickySrcset()
209 { 168 {
210 $client = new Client(); 169 $httpMockClient = new HttpMockClient();
211 170 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
212 $mock = new Mock([ 171 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
213 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), 172 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
214 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
215 new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
216 ]);
217
218 $client->getEmitter()->attach($mock);
219 173
220 $logHandler = new TestHandler(); 174 $logHandler = new TestHandler();
221 $logger = new Logger('test', [$logHandler]); 175 $logger = new Logger('test', [$logHandler]);
222 176
223 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 177 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
224 $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) 178 $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 )
225 (min-width: 1251px) calc( (100vw - 530px) / 2 ) 179 (min-width: 1251px) calc( (100vw - 530px) / 2 )
226 (min-width: 1086px) calc(100vw - 480px) 180 (min-width: 1086px) calc(100vw - 480px)
@@ -232,18 +186,13 @@ class DownloadImagesTest extends TestCase
232 186
233 public function testProcessImageWithNullPath() 187 public function testProcessImageWithNullPath()
234 { 188 {
235 $client = new Client(); 189 $httpMockClient = new HttpMockClient();
236 190 $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
237 $mock = new Mock([
238 new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))),
239 ]);
240
241 $client->getEmitter()->attach($mock);
242 191
243 $logHandler = new TestHandler(); 192 $logHandler = new TestHandler();
244 $logger = new Logger('test', [$logHandler]); 193 $logger = new Logger('test', [$logHandler]);
245 194
246 $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); 195 $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
247 196
248 $res = $download->processSingleImage( 197 $res = $download->processSingleImage(
249 123, 198 123,
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index 04e1a59c..29e12cbe 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -17,6 +17,9 @@ class RedirectTest extends TestCase
17 /** @var Redirect */ 17 /** @var Redirect */
18 private $redirect; 18 private $redirect;
19 19
20 /** @var UsernamePasswordToken */
21 private $token;
22
20 public function setUp() 23 public function setUp()
21 { 24 {
22 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') 25 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php
index b044a700..48c82dde 100644
--- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
+++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php
@@ -1,19 +1,19 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Command; 3namespace Tests\Wallabag\CoreBundle\ParamConverter;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter; 8use Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter;
9use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
10 10
11class UsernameRssTokenConverterTest extends TestCase 11class UsernameFeedTokenConverterTest extends TestCase
12{ 12{
13 public function testSupportsWithNoRegistry() 13 public function testSupportsWithNoRegistry()
14 { 14 {
15 $params = new ParamConverter([]); 15 $params = new ParamConverter([]);
16 $converter = new UsernameRssTokenConverter(); 16 $converter = new UsernameFeedTokenConverter();
17 17
18 $this->assertFalse($converter->supports($params)); 18 $this->assertFalse($converter->supports($params));
19 } 19 }
@@ -26,10 +26,10 @@ class UsernameRssTokenConverterTest extends TestCase
26 26
27 $registry->expects($this->once()) 27 $registry->expects($this->once())
28 ->method('getManagers') 28 ->method('getManagers')
29 ->will($this->returnValue([])); 29 ->willReturn([]);
30 30
31 $params = new ParamConverter([]); 31 $params = new ParamConverter([]);
32 $converter = new UsernameRssTokenConverter($registry); 32 $converter = new UsernameFeedTokenConverter($registry);
33 33
34 $this->assertFalse($converter->supports($params)); 34 $this->assertFalse($converter->supports($params));
35 } 35 }
@@ -42,10 +42,10 @@ class UsernameRssTokenConverterTest extends TestCase
42 42
43 $registry->expects($this->once()) 43 $registry->expects($this->once())
44 ->method('getManagers') 44 ->method('getManagers')
45 ->will($this->returnValue(['default' => null])); 45 ->willReturn(['default' => null]);
46 46
47 $params = new ParamConverter([]); 47 $params = new ParamConverter([]);
48 $converter = new UsernameRssTokenConverter($registry); 48 $converter = new UsernameFeedTokenConverter($registry);
49 49
50 $this->assertFalse($converter->supports($params)); 50 $this->assertFalse($converter->supports($params));
51 } 51 }
@@ -58,7 +58,7 @@ class UsernameRssTokenConverterTest extends TestCase
58 58
59 $meta->expects($this->once()) 59 $meta->expects($this->once())
60 ->method('getName') 60 ->method('getName')
61 ->will($this->returnValue('nothingrelated')); 61 ->willReturn('nothingrelated');
62 62
63 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') 63 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
64 ->disableOriginalConstructor() 64 ->disableOriginalConstructor()
@@ -67,7 +67,7 @@ class UsernameRssTokenConverterTest extends TestCase
67 $em->expects($this->once()) 67 $em->expects($this->once())
68 ->method('getClassMetadata') 68 ->method('getClassMetadata')
69 ->with('superclass') 69 ->with('superclass')
70 ->will($this->returnValue($meta)); 70 ->willReturn($meta);
71 71
72 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') 72 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
73 ->disableOriginalConstructor() 73 ->disableOriginalConstructor()
@@ -75,15 +75,15 @@ class UsernameRssTokenConverterTest extends TestCase
75 75
76 $registry->expects($this->once()) 76 $registry->expects($this->once())
77 ->method('getManagers') 77 ->method('getManagers')
78 ->will($this->returnValue(['default' => null])); 78 ->willReturn(['default' => null]);
79 79
80 $registry->expects($this->once()) 80 $registry->expects($this->once())
81 ->method('getManagerForClass') 81 ->method('getManagerForClass')
82 ->with('superclass') 82 ->with('superclass')
83 ->will($this->returnValue($em)); 83 ->willReturn($em);
84 84
85 $params = new ParamConverter(['class' => 'superclass']); 85 $params = new ParamConverter(['class' => 'superclass']);
86 $converter = new UsernameRssTokenConverter($registry); 86 $converter = new UsernameFeedTokenConverter($registry);
87 87
88 $this->assertFalse($converter->supports($params)); 88 $this->assertFalse($converter->supports($params));
89 } 89 }
@@ -96,7 +96,7 @@ class UsernameRssTokenConverterTest extends TestCase
96 96
97 $meta->expects($this->once()) 97 $meta->expects($this->once())
98 ->method('getName') 98 ->method('getName')
99 ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); 99 ->willReturn('Wallabag\UserBundle\Entity\User');
100 100
101 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') 101 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
102 ->disableOriginalConstructor() 102 ->disableOriginalConstructor()
@@ -105,7 +105,7 @@ class UsernameRssTokenConverterTest extends TestCase
105 $em->expects($this->once()) 105 $em->expects($this->once())
106 ->method('getClassMetadata') 106 ->method('getClassMetadata')
107 ->with('WallabagUserBundle:User') 107 ->with('WallabagUserBundle:User')
108 ->will($this->returnValue($meta)); 108 ->willReturn($meta);
109 109
110 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') 110 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
111 ->disableOriginalConstructor() 111 ->disableOriginalConstructor()
@@ -113,15 +113,15 @@ class UsernameRssTokenConverterTest extends TestCase
113 113
114 $registry->expects($this->once()) 114 $registry->expects($this->once())
115 ->method('getManagers') 115 ->method('getManagers')
116 ->will($this->returnValue(['default' => null])); 116 ->willReturn(['default' => null]);
117 117
118 $registry->expects($this->once()) 118 $registry->expects($this->once())
119 ->method('getManagerForClass') 119 ->method('getManagerForClass')
120 ->with('WallabagUserBundle:User') 120 ->with('WallabagUserBundle:User')
121 ->will($this->returnValue($em)); 121 ->willReturn($em);
122 122
123 $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); 123 $params = new ParamConverter(['class' => 'WallabagUserBundle:User']);
124 $converter = new UsernameRssTokenConverter($registry); 124 $converter = new UsernameFeedTokenConverter($registry);
125 125
126 $this->assertTrue($converter->supports($params)); 126 $this->assertTrue($converter->supports($params));
127 } 127 }
@@ -129,7 +129,7 @@ class UsernameRssTokenConverterTest extends TestCase
129 public function testApplyEmptyRequest() 129 public function testApplyEmptyRequest()
130 { 130 {
131 $params = new ParamConverter([]); 131 $params = new ParamConverter([]);
132 $converter = new UsernameRssTokenConverter(); 132 $converter = new UsernameFeedTokenConverter();
133 133
134 $res = $converter->apply(new Request(), $params); 134 $res = $converter->apply(new Request(), $params);
135 135
@@ -147,9 +147,9 @@ class UsernameRssTokenConverterTest extends TestCase
147 ->getMock(); 147 ->getMock();
148 148
149 $repo->expects($this->once()) 149 $repo->expects($this->once())
150 ->method('findOneByUsernameAndRsstoken') 150 ->method('findOneByUsernameAndFeedToken')
151 ->with('test', 'test') 151 ->with('test', 'test')
152 ->will($this->returnValue(null)); 152 ->willReturn(null);
153 153
154 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') 154 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
155 ->disableOriginalConstructor() 155 ->disableOriginalConstructor()
@@ -158,7 +158,7 @@ class UsernameRssTokenConverterTest extends TestCase
158 $em->expects($this->once()) 158 $em->expects($this->once())
159 ->method('getRepository') 159 ->method('getRepository')
160 ->with('WallabagUserBundle:User') 160 ->with('WallabagUserBundle:User')
161 ->will($this->returnValue($repo)); 161 ->willReturn($repo);
162 162
163 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') 163 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
164 ->disableOriginalConstructor() 164 ->disableOriginalConstructor()
@@ -167,10 +167,10 @@ class UsernameRssTokenConverterTest extends TestCase
167 $registry->expects($this->once()) 167 $registry->expects($this->once())
168 ->method('getManagerForClass') 168 ->method('getManagerForClass')
169 ->with('WallabagUserBundle:User') 169 ->with('WallabagUserBundle:User')
170 ->will($this->returnValue($em)); 170 ->willReturn($em);
171 171
172 $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); 172 $params = new ParamConverter(['class' => 'WallabagUserBundle:User']);
173 $converter = new UsernameRssTokenConverter($registry); 173 $converter = new UsernameFeedTokenConverter($registry);
174 $request = new Request([], [], ['username' => 'test', 'token' => 'test']); 174 $request = new Request([], [], ['username' => 'test', 'token' => 'test']);
175 175
176 $converter->apply($request, $params); 176 $converter->apply($request, $params);
@@ -185,9 +185,9 @@ class UsernameRssTokenConverterTest extends TestCase
185 ->getMock(); 185 ->getMock();
186 186
187 $repo->expects($this->once()) 187 $repo->expects($this->once())
188 ->method('findOneByUsernameAndRsstoken') 188 ->method('findOneByUsernameAndFeedtoken')
189 ->with('test', 'test') 189 ->with('test', 'test')
190 ->will($this->returnValue($user)); 190 ->willReturn($user);
191 191
192 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') 192 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
193 ->disableOriginalConstructor() 193 ->disableOriginalConstructor()
@@ -196,7 +196,7 @@ class UsernameRssTokenConverterTest extends TestCase
196 $em->expects($this->once()) 196 $em->expects($this->once())
197 ->method('getRepository') 197 ->method('getRepository')
198 ->with('WallabagUserBundle:User') 198 ->with('WallabagUserBundle:User')
199 ->will($this->returnValue($repo)); 199 ->willReturn($repo);
200 200
201 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') 201 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
202 ->disableOriginalConstructor() 202 ->disableOriginalConstructor()
@@ -205,10 +205,10 @@ class UsernameRssTokenConverterTest extends TestCase
205 $registry->expects($this->once()) 205 $registry->expects($this->once())
206 ->method('getManagerForClass') 206 ->method('getManagerForClass')
207 ->with('WallabagUserBundle:User') 207 ->with('WallabagUserBundle:User')
208 ->will($this->returnValue($em)); 208 ->willReturn($em);
209 209
210 $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); 210 $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']);
211 $converter = new UsernameRssTokenConverter($registry); 211 $converter = new UsernameFeedTokenConverter($registry);
212 $request = new Request([], [], ['username' => 'test', 'token' => 'test']); 212 $request = new Request([], [], ['username' => 'test', 'token' => 'test']);
213 213
214 $converter->apply($request, $params); 214 $converter->apply($request, $params);
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
index bb92f745..39fcec16 100644
--- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
+++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
@@ -32,6 +32,31 @@ class WallabagExtensionTest extends TestCase
32 $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); 32 $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com'));
33 } 33 }
34 34
35 public function testRemoveScheme()
36 {
37 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
38 ->disableOriginalConstructor()
39 ->getMock();
40
41 $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
42 ->disableOriginalConstructor()
43 ->getMock();
44
45 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
46 ->disableOriginalConstructor()
47 ->getMock();
48
49 $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
50 ->disableOriginalConstructor()
51 ->getMock();
52
53 $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
54
55 $this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr'));
56 $this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com'));
57 $this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com'));
58 }
59
35 public function testRemoveSchemeAndWww() 60 public function testRemoveSchemeAndWww()
36 { 61 {
37 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 62 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 6e1163c5..816d22f4 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -84,8 +84,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
84 $container = $this->client->getContainer(); 84 $container = $this->client->getContainer();
85 $session = $container->get('session'); 85 $session = $container->get('session');
86 86
87 $userManager = $container->get('fos_user.user_manager'); 87 $userManager = $container->get('fos_user.user_manager.test');
88 $loginManager = $container->get('fos_user.security.login_manager'); 88 $loginManager = $container->get('fos_user.security.login_manager.test');
89 $firewallName = $container->getParameter('fos_user.firewall_name'); 89 $firewallName = $container->getParameter('fos_user.firewall_name');
90 90
91 $user = $userManager->findUserBy(['username' => $username]); 91 $user = $userManager->findUserBy(['username' => $username]);