diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-02 16:07:57 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-02 19:05:18 +0300 |
commit | 31bc57a4e95fd5a0b25bec7e5b934110930cffd7 (patch) | |
tree | 148bb1a4b417cb5d2ae5d4913ff73ba9130e051c /tests | |
parent | d0fb26127dfebe455fc1faee7e4ef33c29bfc081 (diff) |
redirects to homepage instead showing error on blank page
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php b/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php index 30daa45b..a902fcce 100644 --- a/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php +++ b/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php @@ -24,10 +24,14 @@ namespace OCA\User_SAML\Tests\Middleware; use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Utility\IControllerMethodReflector; +use OCP\IURLGenerator; use OCP\IUserSession; class OnlyLoggedInMiddlewareTest extends \Test\TestCase { + /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ + protected $urlGenerator; /** @var IControllerMethodReflector|\PHPUnit_Framework_MockObject_MockObject */ private $reflector; /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ @@ -38,9 +42,11 @@ class OnlyLoggedInMiddlewareTest extends \Test\TestCase { protected function setUp(): void { $this->reflector = $this->createMock(IControllerMethodReflector::class); $this->userSession = $this->createMock(IUserSession::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->onlyLoggedInMiddleware = new OnlyLoggedInMiddleware( $this->reflector, - $this->userSession + $this->userSession, + $this->urlGenerator ); parent::setUp(); @@ -101,8 +107,14 @@ class OnlyLoggedInMiddlewareTest extends \Test\TestCase { } public function testAfterExceptionWithAlreadyLoggedInException() { + $homeUrl = 'https://my.nxt.cld/'; + $this->urlGenerator->expects($this->atLeastOnce()) + ->method('getAbsoluteURL') + ->with('/') + ->willReturn($homeUrl); + $exception = new \Exception('User is already logged-in'); - $expected = new JSONResponse('User is already logged-in', 403); + $expected = new RedirectResponse($homeUrl); $this->assertEquals($expected, $this->onlyLoggedInMiddleware->afterException($this->createMock(Controller::class), 'bar', $exception)); } } |