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