xref: /webtrees/tests/app/Http/RequestHandlers/AccountUpdateTest.php (revision b6017f990d38d8c56e04c0096ce9a7e8745ad4ba)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Http\Controllers\Admin;
21
22use Fig\Http\Message\StatusCodeInterface;
23use Fisharebest\Webtrees\Contracts\UserInterface;
24use Fisharebest\Webtrees\Http\RequestHandlers\AccountUpdate;
25use Fisharebest\Webtrees\Services\UserService;
26use Fisharebest\Webtrees\TestCase;
27use Fisharebest\Webtrees\Tree;
28use Fisharebest\Webtrees\User;
29
30/**
31 * Test the AccountUpdate request handler.
32 *
33 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\AccountUpdate
34 */
35class AccountUpdateTest extends TestCase
36{
37    /**
38     * @return void
39     */
40    public function testHandler(): void
41    {
42        $user_service = self::createMock(UserService::class);
43
44        $user = self::createMock(User::class);
45        $user->expects(self::once())->method('setEmail')->with('b');
46        $user->expects(self::once())->method('setPassword')->with('e');
47        $user->expects(self::once())->method('setRealName')->with('d');
48        $user->expects(self::once())->method('setUserName')->with('h');
49        $user->expects(self::exactly(4))
50            ->method('setPreference')
51            ->withConsecutive(
52                [UserInterface::PREF_CONTACT_METHOD, 'a'],
53                [UserInterface::PREF_LANGUAGE, 'c'],
54                [UserInterface::PREF_TIME_ZONE, 'g'],
55                [UserInterface::PREF_IS_VISIBLE_ONLINE, 'i']
56            );
57
58        $tree = self::createMock(Tree::class);
59        $tree->expects(self::once())->method('setUserPreference')->with($user, UserInterface::PREF_TREE_DEFAULT_XREF, 'f');
60
61        $handler  = new AccountUpdate($user_service);
62        $request  = self::createRequest()
63            ->withAttribute('tree', $tree)
64            ->withAttribute('user', $user)
65            ->withParsedBody([
66                'contact-method' => 'a',
67                'email'          => 'b',
68                'language'       => 'c',
69                'real_name'      => 'd',
70                'password'       => 'e',
71                'default-xref'   => 'f',
72                'timezone'       => 'g',
73                'user_name'      => 'h',
74                'visible-online' => 'i',
75            ]);
76        $response = $handler->handle($request);
77
78        self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
79    }
80}
81