diff options
Diffstat (limited to 'tests')
4 files changed, 114 insertions, 12 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 568576a3..a2863014 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -51,6 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
51 | 'config[theme]' => 'baggy', | 51 | 'config[theme]' => 'baggy', |
52 | 'config[items_per_page]' => '30', | 52 | 'config[items_per_page]' => '30', |
53 | 'config[reading_speed]' => '0.5', | 53 | 'config[reading_speed]' => '0.5', |
54 | 'config[action_mark_as_read]' => '0', | ||
54 | 'config[language]' => 'en', | 55 | 'config[language]' => 'en', |
55 | ]; | 56 | ]; |
56 | 57 | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 4ab06dbf..bf4e0543 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
7 | 8 | ||
8 | class EntryControllerTest extends WallabagCoreTestCase | 9 | class EntryControllerTest extends WallabagCoreTestCase |
@@ -896,4 +897,68 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
896 | 897 | ||
897 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 898 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
898 | } | 899 | } |
900 | |||
901 | public function testRedirectToHomepage() | ||
902 | { | ||
903 | $this->logInAs('empty'); | ||
904 | $client = $this->getClient(); | ||
905 | |||
906 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
907 | $user = $em | ||
908 | ->getRepository('WallabagUserBundle:User') | ||
909 | ->find($this->getLoggedInUserId()); | ||
910 | |||
911 | if (!$user) { | ||
912 | $this->markTestSkipped('No user found in db.'); | ||
913 | } | ||
914 | |||
915 | // Redirect to homepage | ||
916 | $config = $user->getConfig(); | ||
917 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
918 | $em->persist($config); | ||
919 | $em->flush(); | ||
920 | |||
921 | $content = $client->getContainer() | ||
922 | ->get('doctrine.orm.entity_manager') | ||
923 | ->getRepository('WallabagCoreBundle:Entry') | ||
924 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
925 | |||
926 | $client->request('GET', '/view/'.$content->getId()); | ||
927 | $client->request('GET', '/archive/'.$content->getId()); | ||
928 | |||
929 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
930 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | ||
931 | } | ||
932 | |||
933 | public function testRedirectToCurrentPage() | ||
934 | { | ||
935 | $this->logInAs('empty'); | ||
936 | $client = $this->getClient(); | ||
937 | |||
938 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
939 | $user = $em | ||
940 | ->getRepository('WallabagUserBundle:User') | ||
941 | ->find($this->getLoggedInUserId()); | ||
942 | |||
943 | if (!$user) { | ||
944 | $this->markTestSkipped('No user found in db.'); | ||
945 | } | ||
946 | |||
947 | // Redirect to current page | ||
948 | $config = $user->getConfig(); | ||
949 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | ||
950 | $em->persist($config); | ||
951 | $em->flush(); | ||
952 | |||
953 | $content = $client->getContainer() | ||
954 | ->get('doctrine.orm.entity_manager') | ||
955 | ->getRepository('WallabagCoreBundle:Entry') | ||
956 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
957 | |||
958 | $client->request('GET', '/view/'.$content->getId()); | ||
959 | $client->request('GET', '/archive/'.$content->getId()); | ||
960 | |||
961 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
962 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | ||
963 | } | ||
899 | } | 964 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 920c21d9..85f12d87 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -3,7 +3,6 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Helper\DownloadImages; | 5 | use Wallabag\CoreBundle\Helper\DownloadImages; |
6 | use Psr\Log\NullLogger; | ||
7 | use Monolog\Logger; | 6 | use Monolog\Logger; |
8 | use Monolog\Handler\TestHandler; | 7 | use Monolog\Handler\TestHandler; |
9 | use GuzzleHttp\Client; | 8 | use GuzzleHttp\Client; |
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index f339f75e..0539f20a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -2,7 +2,11 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
5 | use Wallabag\CoreBundle\Helper\Redirect; | 7 | use Wallabag\CoreBundle\Helper\Redirect; |
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
6 | 10 | ||
7 | class RedirectTest extends \PHPUnit_Framework_TestCase | 11 | class RedirectTest extends \PHPUnit_Framework_TestCase |
8 | { | 12 | { |
@@ -14,8 +18,38 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
14 | 18 | ||
15 | public function setUp() | 19 | public function setUp() |
16 | { | 20 | { |
17 | $this->routerMock = $this->getRouterMock(); | 21 | $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') |
18 | $this->redirect = new Redirect($this->routerMock); | 22 | ->disableOriginalConstructor() |
23 | ->getMock(); | ||
24 | |||
25 | $this->routerMock->expects($this->any()) | ||
26 | ->method('generate') | ||
27 | ->with('homepage') | ||
28 | ->willReturn('homepage'); | ||
29 | |||
30 | $user = new User(); | ||
31 | $user->setName('youpi'); | ||
32 | $user->setEmail('youpi@youpi.org'); | ||
33 | $user->setUsername('youpi'); | ||
34 | $user->setPlainPassword('youpi'); | ||
35 | $user->setEnabled(true); | ||
36 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
37 | |||
38 | $config = new Config($user); | ||
39 | $config->setTheme('material'); | ||
40 | $config->setItemsPerPage(30); | ||
41 | $config->setReadingSpeed(1); | ||
42 | $config->setLanguage('en'); | ||
43 | $config->setPocketConsumerKey('xxxxx'); | ||
44 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | ||
45 | |||
46 | $user->setConfig($config); | ||
47 | |||
48 | $this->token = new UsernamePasswordToken($user, 'password', 'key'); | ||
49 | $tokenStorage = new TokenStorage(); | ||
50 | $tokenStorage->setToken($this->token); | ||
51 | |||
52 | $this->redirect = new Redirect($this->routerMock, $tokenStorage); | ||
19 | } | 53 | } |
20 | 54 | ||
21 | public function testRedirectToNullWithFallback() | 55 | public function testRedirectToNullWithFallback() |
@@ -39,17 +73,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
39 | $this->assertEquals('/unread/list', $redirectUrl); | 73 | $this->assertEquals('/unread/list', $redirectUrl); |
40 | } | 74 | } |
41 | 75 | ||
42 | private function getRouterMock() | 76 | public function testWithNotLoggedUser() |
43 | { | 77 | { |
44 | $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') | 78 | $redirect = new Redirect($this->routerMock, new TokenStorage()); |
45 | ->disableOriginalConstructor() | 79 | $redirectUrl = $redirect->to('/unread/list'); |
46 | ->getMock(); | ||
47 | 80 | ||
48 | $mock->expects($this->any()) | 81 | $this->assertEquals('/unread/list', $redirectUrl); |
49 | ->method('generate') | 82 | } |
50 | ->with('homepage') | ||
51 | ->willReturn('homepage'); | ||
52 | 83 | ||
53 | return $mock; | 84 | public function testUserForRedirectToHomepage() |
85 | { | ||
86 | $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
87 | |||
88 | $redirectUrl = $this->redirect->to('/unread/list'); | ||
89 | |||
90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | ||
54 | } | 91 | } |
55 | } | 92 | } |