xref: /webtrees/tests/app/Http/RequestHandlers/SelectLanguageTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
1a0801ffbSGreg Roach<?php
23976b470SGreg Roach
3a0801ffbSGreg Roach/**
4a0801ffbSGreg Roach * webtrees: online genealogy
5d11be702SGreg 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;
26*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
27a0801ffbSGreg Roach
28*202c018bSGreg Roach#[CoversClass(SelectLanguage::class)]
29a0801ffbSGreg Roachclass SelectLanguageTest extends TestCase
30a0801ffbSGreg Roach{
31a26ec5edSGreg Roach    protected static bool $uses_database = true;
32a26ec5edSGreg Roach
33a0801ffbSGreg Roach    public function testSelectLanguageForGuest(): void
34a0801ffbSGreg Roach    {
35a0801ffbSGreg Roach        $user     = new GuestUser();
367adfb8e5SGreg Roach        $handler  = new SelectLanguage();
377adfb8e5SGreg Roach        $request  = self::createRequest()
387adfb8e5SGreg Roach            ->withAttribute('user', $user)
397adfb8e5SGreg Roach            ->withAttribute('language', 'fr');
40a0801ffbSGreg Roach        $response = $handler->handle($request);
41a0801ffbSGreg Roach
4271378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
43a0801ffbSGreg Roach    }
44a0801ffbSGreg Roach
45a0801ffbSGreg Roach    public function testSelectLanguageForUser(): void
46a0801ffbSGreg Roach    {
47a0801ffbSGreg Roach        $user_service = new UserService();
48a0801ffbSGreg Roach        $user         = $user_service->create('user', 'real', 'email', 'pass');
497adfb8e5SGreg Roach        $handler      = new SelectLanguage();
507adfb8e5SGreg Roach        $request      = self::createRequest()
517adfb8e5SGreg Roach            ->withAttribute('user', $user)
527adfb8e5SGreg Roach            ->withAttribute('language', 'fr');
53a0801ffbSGreg Roach        $response     = $handler->handle($request);
54a0801ffbSGreg Roach
5571378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
56a0801ffbSGreg Roach    }
57a0801ffbSGreg Roach}
58