aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/admin
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-13 11:08:13 +0200
committerArthurHoaro <arthur@hoa.ro>2020-08-13 11:08:13 +0200
commitbedbb845eec20363b928b424143787dbe988eefe (patch)
tree6b835ca247e39157b333323a539dde3c410c08f5 /tests/front/controller/admin
parent1a68ae5a29bc33ab80c9cfbe043cb1213551533c (diff)
downloadShaarli-bedbb845eec20363b928b424143787dbe988eefe.tar.gz
Shaarli-bedbb845eec20363b928b424143787dbe988eefe.tar.zst
Shaarli-bedbb845eec20363b928b424143787dbe988eefe.zip
Move all admin controller into a dedicated group
Also handle authentication check in a new middleware for the admin group.
Diffstat (limited to 'tests/front/controller/admin')
-rw-r--r--tests/front/controller/admin/SessionFilterControllerTest.php51
-rw-r--r--tests/front/controller/admin/ShaarliAdminControllerTest.php15
2 files changed, 0 insertions, 66 deletions
diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php
index 7d5511ed..d306c6e9 100644
--- a/tests/front/controller/admin/SessionFilterControllerTest.php
+++ b/tests/front/controller/admin/SessionFilterControllerTest.php
@@ -174,55 +174,4 @@ class SessionFilterControllerTest extends TestCase
174 static::assertSame(302, $result->getStatusCode()); 174 static::assertSame(302, $result->getStatusCode());
175 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location')); 175 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));
176 } 176 }
177
178 /**
179 * Untagged only - valid call
180 */
181 public function testUntaggedOnly(): void
182 {
183 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
184
185 $request = $this->createMock(Request::class);
186 $response = new Response();
187
188 $this->container->sessionManager
189 ->expects(static::once())
190 ->method('setSessionParameter')
191 ->with(SessionManager::KEY_UNTAGGED_ONLY, true)
192 ;
193
194 $result = $this->controller->untaggedOnly($request, $response);
195
196 static::assertInstanceOf(Response::class, $result);
197 static::assertSame(302, $result->getStatusCode());
198 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));
199 }
200
201 /**
202 * Untagged only - toggle off
203 */
204 public function testUntaggedOnlyToggleOff(): void
205 {
206 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
207
208 $request = $this->createMock(Request::class);
209 $response = new Response();
210
211 $this->container->sessionManager
212 ->method('getSessionParameter')
213 ->with(SessionManager::KEY_UNTAGGED_ONLY)
214 ->willReturn(true)
215 ;
216 $this->container->sessionManager
217 ->expects(static::once())
218 ->method('setSessionParameter')
219 ->with(SessionManager::KEY_UNTAGGED_ONLY, false)
220 ;
221
222 $result = $this->controller->untaggedOnly($request, $response);
223
224 static::assertInstanceOf(Response::class, $result);
225 static::assertSame(302, $result->getStatusCode());
226 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));
227 }
228} 177}
diff --git a/tests/front/controller/admin/ShaarliAdminControllerTest.php b/tests/front/controller/admin/ShaarliAdminControllerTest.php
index 7c5f50a6..fff427cb 100644
--- a/tests/front/controller/admin/ShaarliAdminControllerTest.php
+++ b/tests/front/controller/admin/ShaarliAdminControllerTest.php
@@ -5,9 +5,7 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Exception\UnauthorizedException;
9use Shaarli\Front\Exception\WrongTokenException; 8use Shaarli\Front\Exception\WrongTokenException;
10use Shaarli\Security\LoginManager;
11use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
12use Slim\Http\Request; 10use Slim\Http\Request;
13 11
@@ -53,19 +51,6 @@ class ShaarliAdminControllerTest extends TestCase
53 } 51 }
54 52
55 /** 53 /**
56 * Creating an instance of an admin controller while logged out should raise an exception.
57 */
58 public function testInstantiateWhileLoggedOut(): void
59 {
60 $this->expectException(UnauthorizedException::class);
61
62 $this->container->loginManager = $this->createMock(LoginManager::class);
63 $this->container->loginManager->method('isLoggedIn')->willReturn(false);
64
65 $this->controller = new class($this->container) extends ShaarliAdminController {};
66 }
67
68 /**
69 * Trigger controller's checkToken with a valid token. 54 * Trigger controller's checkToken with a valid token.
70 */ 55 */
71 public function testCheckTokenWithValidToken(): void 56 public function testCheckTokenWithValidToken(): void