xref: /webtrees/tests/app/Http/RequestHandlers/LoginPageTest.php (revision 5fb051e95bc3d8a26af94d588bd85bf2d37f583c)
1d403609dSGreg Roach<?php
2d403609dSGreg Roach
3d403609dSGreg Roach/**
4d403609dSGreg Roach * webtrees: online genealogy
5d403609dSGreg Roach * Copyright (C) 2019 webtrees development team
6d403609dSGreg Roach * This program is free software: you can redistribute it and/or modify
7d403609dSGreg Roach * it under the terms of the GNU General Public License as published by
8d403609dSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9d403609dSGreg Roach * (at your option) any later version.
10d403609dSGreg Roach * This program is distributed in the hope that it will be useful,
11d403609dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12d403609dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13d403609dSGreg Roach * GNU General Public License for more details.
14d403609dSGreg Roach * You should have received a copy of the GNU General Public License
15d403609dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16d403609dSGreg Roach */
17fcfa147eSGreg Roach
18d403609dSGreg Roachdeclare(strict_types=1);
19d403609dSGreg Roach
20d403609dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21d403609dSGreg Roach
2271378461SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
23*5fb051e9SGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
24d403609dSGreg Roachuse Fisharebest\Webtrees\TestCase;
25d403609dSGreg Roachuse Fisharebest\Webtrees\User;
26d403609dSGreg Roachuse Fisharebest\Webtrees\View;
27d403609dSGreg Roach
28d403609dSGreg Roach/**
29d403609dSGreg Roach * @covers \Fisharebest\Webtrees\Http\RequestHandlers\LoginPage
30d403609dSGreg Roach */
31d403609dSGreg Roachclass LoginPageTest extends TestCase
32d403609dSGreg Roach{
33d403609dSGreg Roach    /**
34d403609dSGreg Roach     * @return void
35d403609dSGreg Roach     */
36d403609dSGreg Roach    public function testLoginPage(): void
37d403609dSGreg Roach    {
38*5fb051e9SGreg Roach        $tree_service = new TreeService();
39d403609dSGreg Roach        View::share('tree', null);
40d403609dSGreg Roach        $request  = self::createRequest();
41*5fb051e9SGreg Roach        $handler  = new LoginPage($tree_service);
42d403609dSGreg Roach        $response = $handler->handle($request);
43d403609dSGreg Roach
4471378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
45d403609dSGreg Roach    }
46d403609dSGreg Roach
47d403609dSGreg Roach    /**
48d403609dSGreg Roach     * @return void
49d403609dSGreg Roach     */
50d403609dSGreg Roach    public function testLoginPageAlreadyLoggedIn(): void
51d403609dSGreg Roach    {
52*5fb051e9SGreg Roach        $tree_service = new TreeService();
53d403609dSGreg Roach        $user     = $this->createMock(User::class);
54d403609dSGreg Roach        $request  = self::createRequest()->withAttribute('user', $user);
55*5fb051e9SGreg Roach        $handler  = new LoginPage($tree_service);
56d403609dSGreg Roach        $response = $handler->handle($request);
57d403609dSGreg Roach
5871378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
59d403609dSGreg Roach    }
60d403609dSGreg Roach}
61