From 65cd8a4a9a1d15d962033f58276005a5f7716f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 10:26:05 +0100 Subject: Added tests --- .../CoreBundle/Controller/EntryControllerTest.php | 65 ++++++++++++++++++++++ tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 4 +- 2 files changed, 67 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag') 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 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase @@ -896,4 +897,68 @@ class EntryControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } + + public function testRedirectToHomepage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to homepage + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals('/', $client->getResponse()->headers->get('location')); + } + + public function testRedirectToCurrentPage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to current page + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); + } } diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 825e8d53..a2d6a524 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -25,14 +25,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase { $redirectUrl = $this->redirect->to(null, 'fallback'); - $this->assertEquals('fallback', $redirectUrl); + $this->assertEquals(null, $redirectUrl); } public function testRedirectToNullWithoutFallback() { $redirectUrl = $this->redirect->to(null); - $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertEquals(null, $redirectUrl); } public function testRedirectToValidUrl() -- cgit v1.2.3