summaryrefslogtreecommitdiff
path: root/tests/app/Http/RequestHandlers
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2021-01-15 18:21:01 +0000
committerGreg Roach <greg@subaqua.co.uk>2021-01-15 18:21:01 +0000
commit4c3563c0d95e22997e247ca4944dff997416f927 (patch)
treec0b0ecfdd45f89ba4ac2c9931c8303c7edc2690d /tests/app/Http/RequestHandlers
parent26e1ac84be2e21522c28114803a36810b84aa8cc (diff)
downloadwebtrees-4c3563c0d95e22997e247ca4944dff997416f927.tar.gz
webtrees-4c3563c0d95e22997e247ca4944dff997416f927.tar.bz2
webtrees-4c3563c0d95e22997e247ca4944dff997416f927.zip
Refactor controller as request handlers
Diffstat (limited to 'tests/app/Http/RequestHandlers')
-rw-r--r--tests/app/Http/RequestHandlers/UserAddActionTest.php53
-rw-r--r--tests/app/Http/RequestHandlers/UserAddPageTest.php45
-rw-r--r--tests/app/Http/RequestHandlers/UserEditActionTest.php70
-rw-r--r--tests/app/Http/RequestHandlers/UserEditPageTest.php57
-rw-r--r--tests/app/Http/RequestHandlers/UserListDataTest.php51
-rw-r--r--tests/app/Http/RequestHandlers/UserListTest.php47
6 files changed, 323 insertions, 0 deletions
diff --git a/tests/app/Http/RequestHandlers/UserAddActionTest.php b/tests/app/Http/RequestHandlers/UserAddActionTest.php
new file mode 100644
index 0000000000..c00a36f33c
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserAddActionTest.php
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\RequestMethodInterface;
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Services\UserService;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserAddActionTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserAddAction
+ */
+class UserAddActionTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $user_service = new UserService();
+ $handler = new UserAddAction($user_service);
+ $request = self::createRequest(RequestMethodInterface::METHOD_POST, [], [
+ 'username' => 'User name',
+ 'email' => 'email@example.com',
+ 'real_name' => 'Real Name',
+ 'password' => 'Secret1234',
+ ]);
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
+ }
+}
diff --git a/tests/app/Http/RequestHandlers/UserAddPageTest.php b/tests/app/Http/RequestHandlers/UserAddPageTest.php
new file mode 100644
index 0000000000..6f8c9719e4
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserAddPageTest.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserAddPageTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserAddPage
+ */
+class UserAddPageTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $handler = new UserAddPage();
+ $request = self::createRequest();
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
+ }
+}
diff --git a/tests/app/Http/RequestHandlers/UserEditActionTest.php b/tests/app/Http/RequestHandlers/UserEditActionTest.php
new file mode 100644
index 0000000000..1657593ad6
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserEditActionTest.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\RequestMethodInterface;
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Services\EmailService;
+use Fisharebest\Webtrees\Services\TreeService;
+use Fisharebest\Webtrees\Services\UserService;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserEditActionTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserEditAction
+ */
+class UserEditActionTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $mail_service = new EmailService();
+ $tree_service = new TreeService();
+ $user_service = new UserService();
+ $user = $user_service->create('user', 'real', 'email', 'pass');
+ $handler = new UserEditAction($mail_service, $tree_service, $user_service);
+ $request = self::createRequest(RequestMethodInterface::METHOD_POST, [], [
+ 'user_id' => $user->id(),
+ 'username' => '',
+ 'real_name' => '',
+ 'email' => '',
+ 'theme' => '',
+ 'password' => '',
+ 'language' => '',
+ 'timezone' => '',
+ 'comment' => '',
+ 'contact-method' => '',
+ 'auto_accept' => '',
+ 'canadmin' => '',
+ 'visible-online' => '',
+ 'verified' => '',
+ 'approved' => '',
+ ])
+ ->withAttribute('user', $user);
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
+ }
+}
diff --git a/tests/app/Http/RequestHandlers/UserEditPageTest.php b/tests/app/Http/RequestHandlers/UserEditPageTest.php
new file mode 100644
index 0000000000..dd1af9a711
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserEditPageTest.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\RequestMethodInterface;
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Services\EmailService;
+use Fisharebest\Webtrees\Services\MessageService;
+use Fisharebest\Webtrees\Services\ModuleService;
+use Fisharebest\Webtrees\Services\TreeService;
+use Fisharebest\Webtrees\Services\UserService;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserEditPageTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserEditPage
+ */
+class UserEditPageTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $mail_service = new EmailService();
+ $module_service = new ModuleService();
+ $tree_service = new TreeService();
+ $user_service = new UserService();
+ $message_service = new MessageService($mail_service, $user_service);
+ $user = $user_service->create('user', 'real', 'email', 'pass');
+ $handler = new UserEditPage($message_service, $module_service, $tree_service, $user_service);
+ $request = self::createRequest(RequestMethodInterface::METHOD_GET, ['user_id' => (string) $user->id()]);
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
+ }
+}
diff --git a/tests/app/Http/RequestHandlers/UserListDataTest.php b/tests/app/Http/RequestHandlers/UserListDataTest.php
new file mode 100644
index 0000000000..d4faa84a78
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserListDataTest.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Services\DatatablesService;
+use Fisharebest\Webtrees\Services\ModuleService;
+use Fisharebest\Webtrees\Services\UserService;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserEditPageTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserListData
+ */
+class UserListDataTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $datatables_service = new DatatablesService();
+ $module_service = new ModuleService();
+ $user_service = new UserService();
+ $handler = new UserListData($datatables_service, $module_service, $user_service);
+ $request = self::createRequest();
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
+ }
+}
diff --git a/tests/app/Http/RequestHandlers/UserListTest.php b/tests/app/Http/RequestHandlers/UserListTest.php
new file mode 100644
index 0000000000..728d7eab9a
--- /dev/null
+++ b/tests/app/Http/RequestHandlers/UserListTest.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2020 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Auth;
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test UserListTest class.
+ *
+ * @covers \Fisharebest\Webtrees\Http\RequestHandlers\UserListPage
+ */
+class UserListTest extends TestCase
+{
+ protected static $uses_database = true;
+
+ /**
+ * @return void
+ */
+ public function testHandler(): void
+ {
+ $handler = new UserListPage();
+ $request = self::createRequest()
+ ->withAttribute('user', Auth::user());
+ $response = $handler->handle($request);
+
+ self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
+ }
+}