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