xref: /webtrees/tests/app/Http/RequestHandlers/AccountUpdateTest.php (revision 00ef1d3af59aba99c1ae5c92c7e655525c97797b)
17c4add84SGreg Roach<?php
27c4add84SGreg Roach
37c4add84SGreg Roach/**
47c4add84SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
67c4add84SGreg Roach * This program is free software: you can redistribute it and/or modify
77c4add84SGreg Roach * it under the terms of the GNU General Public License as published by
87c4add84SGreg Roach * the Free Software Foundation, either version 3 of the License, or
97c4add84SGreg Roach * (at your option) any later version.
107c4add84SGreg Roach * This program is distributed in the hope that it will be useful,
117c4add84SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
127c4add84SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137c4add84SGreg Roach * GNU General Public License for more details.
147c4add84SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
167c4add84SGreg Roach */
177c4add84SGreg Roach
187c4add84SGreg Roachdeclare(strict_types=1);
197c4add84SGreg Roach
20110d87e5SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
217c4add84SGreg Roach
227c4add84SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
231fe542e9SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
247c4add84SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
257c4add84SGreg Roachuse Fisharebest\Webtrees\TestCase;
267c4add84SGreg Roachuse Fisharebest\Webtrees\Tree;
277c4add84SGreg Roachuse Fisharebest\Webtrees\User;
28202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
297c4add84SGreg Roach
30202c018bSGreg Roach#[CoversClass(AccountUpdate::class)]
317c4add84SGreg Roachclass AccountUpdateTest extends TestCase
327c4add84SGreg Roach{
337c4add84SGreg Roach    public function testHandler(): void
347c4add84SGreg Roach    {
35cd94ca66SGreg Roach        $user_service = $this->createMock(UserService::class);
367c4add84SGreg Roach
37cd94ca66SGreg Roach        $user = $this->createMock(User::class);
38*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setEmail')->with('b');
39*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setPassword')->with('e');
40*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setRealName')->with('d');
41*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setUserName')->with('h');
42109b3e30SGreg Roach        $user->expects(self::exactly(4))
43109b3e30SGreg Roach            ->method('setPreference')
449aef375dSGreg Roach            ->with(
459aef375dSGreg Roach                self::withConsecutive([UserInterface::PREF_CONTACT_METHOD, UserInterface::PREF_LANGUAGE, UserInterface::PREF_TIME_ZONE, UserInterface::PREF_IS_VISIBLE_ONLINE]),
469aef375dSGreg Roach                self::withConsecutive(['a', 'c', 'g', ''])
47109b3e30SGreg Roach            );
487c4add84SGreg Roach
49cd94ca66SGreg Roach        $tree = $this->createMock(Tree::class);
50*00ef1d3aSGreg Roach        $tree->expects($this->once())->method('setUserPreference')->with($user, UserInterface::PREF_TREE_DEFAULT_XREF, 'f');
517c4add84SGreg Roach
527c4add84SGreg Roach        $handler  = new AccountUpdate($user_service);
537c4add84SGreg Roach        $request  = self::createRequest()
547c4add84SGreg Roach            ->withAttribute('tree', $tree)
557c4add84SGreg Roach            ->withAttribute('user', $user)
567c4add84SGreg Roach            ->withParsedBody([
577c4add84SGreg Roach                'contact-method' => 'a',
587c4add84SGreg Roach                'email'          => 'b',
597c4add84SGreg Roach                'language'       => 'c',
607c4add84SGreg Roach                'real_name'      => 'd',
617c4add84SGreg Roach                'password'       => 'e',
627c4add84SGreg Roach                'default-xref'   => 'f',
637c4add84SGreg Roach                'timezone'       => 'g',
647c4add84SGreg Roach                'user_name'      => 'h',
657c4add84SGreg Roach                'visible-online' => 'i',
667c4add84SGreg Roach            ]);
677c4add84SGreg Roach        $response = $handler->handle($request);
687c4add84SGreg Roach
695e933c21SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
707c4add84SGreg Roach    }
717c4add84SGreg Roach}
72