xref: /webtrees/tests/app/Http/RequestHandlers/SelectLanguageTest.php (revision d11be7027e34e3121be11cc025421873364403f9)
1a0801ffbSGreg Roach<?php
23976b470SGreg Roach
3a0801ffbSGreg Roach/**
4a0801ffbSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6a0801ffbSGreg Roach * This program is free software: you can redistribute it and/or modify
7a0801ffbSGreg Roach * it under the terms of the GNU General Public License as published by
8a0801ffbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a0801ffbSGreg Roach * (at your option) any later version.
10a0801ffbSGreg Roach * This program is distributed in the hope that it will be useful,
11a0801ffbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a0801ffbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a0801ffbSGreg Roach * GNU General Public License for more details.
14a0801ffbSGreg 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/>.
16a0801ffbSGreg Roach */
17fcfa147eSGreg Roach
18a0801ffbSGreg Roachdeclare(strict_types=1);
19a0801ffbSGreg Roach
2074d6dc0eSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
2174d6dc0eSGreg Roach
2271378461SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
23a0801ffbSGreg Roachuse Fisharebest\Webtrees\GuestUser;
24a0801ffbSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
25a0801ffbSGreg Roachuse Fisharebest\Webtrees\TestCase;
26a0801ffbSGreg Roach
27a0801ffbSGreg Roach/**
28a0801ffbSGreg Roach * @covers \Fisharebest\Webtrees\Http\RequestHandlers\SelectLanguage
29a0801ffbSGreg Roach */
30a0801ffbSGreg Roachclass SelectLanguageTest extends TestCase
31a0801ffbSGreg Roach{
32a0801ffbSGreg Roach    /**
33a0801ffbSGreg Roach     * @return void
34a0801ffbSGreg Roach     */
35a0801ffbSGreg Roach    public function testSelectLanguageForGuest(): void
36a0801ffbSGreg Roach    {
37a0801ffbSGreg Roach        $user     = new GuestUser();
387adfb8e5SGreg Roach        $handler  = new SelectLanguage();
397adfb8e5SGreg Roach        $request  = self::createRequest()
407adfb8e5SGreg Roach            ->withAttribute('user', $user)
417adfb8e5SGreg Roach            ->withAttribute('language', 'fr');
42a0801ffbSGreg Roach        $response = $handler->handle($request);
43a0801ffbSGreg Roach
4471378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
45a0801ffbSGreg Roach    }
46a0801ffbSGreg Roach
47a0801ffbSGreg Roach    /**
48a0801ffbSGreg Roach     * @return void
49a0801ffbSGreg Roach     */
50a0801ffbSGreg Roach    public function testSelectLanguageForUser(): void
51a0801ffbSGreg Roach    {
52a0801ffbSGreg Roach        $user_service = new UserService();
53a0801ffbSGreg Roach        $user         = $user_service->create('user', 'real', 'email', 'pass');
547adfb8e5SGreg Roach        $handler      = new SelectLanguage();
557adfb8e5SGreg Roach        $request      = self::createRequest()
567adfb8e5SGreg Roach            ->withAttribute('user', $user)
577adfb8e5SGreg Roach            ->withAttribute('language', 'fr');
58a0801ffbSGreg Roach        $response     = $handler->handle($request);
59a0801ffbSGreg Roach
6071378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
61a0801ffbSGreg Roach    }
62a0801ffbSGreg Roach}
63