xref: /webtrees/tests/app/Http/RequestHandlers/PingTest.php (revision 8d897fd11a9a8845d8456cb9eaad33b9c9d5a225)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Http\RequestHandlers;
20
21use Fisharebest\Webtrees\Services\ServerCheckService;
22use Fisharebest\Webtrees\Services\UserService;
23use Fisharebest\Webtrees\TestCase;
24
25/**
26 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\Ping
27 */
28class PingTest extends TestCase
29{
30    protected static $uses_database = true;
31
32    /**
33     * @return void
34     */
35    public function testPing(): void
36    {
37        $handler      = new Ping(new ServerCheckService());
38        $request      = self::createRequest('GET');
39        $response     = $handler->handle($request);
40
41        self::assertSame(self::STATUS_OK, $response->getStatusCode());
42        self::assertSame('OK', (string) $response->getBody());
43    }
44
45    /**
46     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
47     * @expectedExceptionMessage User ID 98765 not found
48     * @return void
49     */
50    public function testDeleteNonExistingUser(): void
51    {
52        $user_service = new UserService();
53        $user_service->create('user1', 'real1', 'email1', 'pass1');
54        $handler = new DeleteUser($user_service);
55        $request = self::createRequest('POST', ['route' => 'delete-user'], ['user_id' => 98765]);
56        $handler->handle($request);
57    }
58
59    /**
60     * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
61     * @expectedExceptionMessage Cannot delete an administrator
62     * @return void
63     */
64    public function testCannotDeleteAdministrator(): void
65    {
66        $user_service = new UserService();
67        $user         = $user_service->create('user1', 'real1', 'email1', 'pass1');
68        $user->setPreference('canadmin', '1');
69        $handler = new DeleteUser($user_service);
70        $request = self::createRequest('POST', ['route' => 'delete-user'], ['user_id' => $user->id()]);
71        $handler->handle($request);
72    }
73}
74