]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Tried to fix tests
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Thu, 10 Nov 2016 14:50:10 +0000 (15:50 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 16 Nov 2016 22:07:34 +0000 (23:07 +0100)
src/Wallabag/CoreBundle/Helper/Redirect.php
tests/Wallabag/CoreBundle/Helper/RedirectTest.php

index 82792aec37eaba2b68b4f82326ee9548be6f429c..f78b7fe0d8b0799879489ec3e48e223b480e1ca3 100644 (file)
@@ -13,7 +13,6 @@ class Redirect
 {
     private $router;
     private $tokenStorage;
-    private $actionMarkAsRead;
 
     public function __construct(Router $router, TokenStorageInterface $tokenStorage)
     {
index a2d6a5245e9b20a7d556bf6e6f50bb67441d27d1..3dcdf8de6cb2ab68278de5e6132a36299bc2d861 100644 (file)
@@ -12,12 +12,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
     /** @var Redirect */
     private $redirect;
 
+    const PASSWORD = 's3Cr3t';
+    const SALT = '^S4lt$';
+
     public function setUp()
     {
         $this->routerMock = $this->getRouterMock();
-        $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
-            ->disableOriginalConstructor()
-            ->getMock();
+        $user = $this->createUser();
+        $tokenStorage = $this->createTokenStorage($user);
         $this->redirect = new Redirect($this->routerMock, $tokenStorage);
     }
 
@@ -25,14 +27,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
     {
         $redirectUrl = $this->redirect->to(null, 'fallback');
 
-        $this->assertEquals(null, $redirectUrl);
+        $this->assertEquals('fallback', $redirectUrl);
     }
 
     public function testRedirectToNullWithoutFallback()
     {
         $redirectUrl = $this->redirect->to(null);
 
-        $this->assertEquals(null, $redirectUrl);
+        $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
     }
 
     public function testRedirectToValidUrl()
@@ -55,4 +57,57 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
 
         return $mock;
     }
+
+    protected function createTokenStorage($user = null)
+    {
+        $token = $this->createAuthenticationToken($user);
+
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getToken')
+            ->will($this->returnValue($token))
+        ;
+
+        return $mock;
+    }
+
+    protected function createUser()
+    {
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getPassword')
+            ->will($this->returnValue(static::PASSWORD))
+        ;
+
+        $mock
+            ->expects($this->any())
+            ->method('getSalt')
+            ->will($this->returnValue(static::SALT))
+        ;
+
+        return $mock;
+    }
+
+    protected function createAuthenticationToken($user = null)
+    {
+        $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $mock
+            ->expects($this->any())
+            ->method('getUser')
+            ->will($this->returnValue($user))
+        ;
+
+        return $mock;
+    }
 }