xref: /webtrees/tests/app/Http/RequestHandlers/SelectThemeTest.php (revision 00ef1d3af59aba99c1ae5c92c7e655525c97797b)
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\TestCase;
25d403609dSGreg Roachuse Fisharebest\Webtrees\User;
26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
27a0801ffbSGreg Roach
28202c018bSGreg Roach#[CoversClass(SelectTheme::class)]
29a0801ffbSGreg Roachclass SelectThemeTest extends TestCase
30a0801ffbSGreg Roach{
31a0801ffbSGreg Roach    public function testSelectThemeForGuest(): void
32a0801ffbSGreg Roach    {
33cd94ca66SGreg Roach        $user = $this->createMock(GuestUser::class);
34*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setPreference')->with('theme', 'FOO');
35d403609dSGreg Roach
367adfb8e5SGreg Roach        $request = self::createRequest()
377adfb8e5SGreg Roach            ->withAttribute('theme', 'FOO')
38d403609dSGreg Roach            ->withAttribute('user', $user);
39d403609dSGreg Roach
40d403609dSGreg Roach        $handler  = new SelectTheme();
41a0801ffbSGreg Roach        $response = $handler->handle($request);
42a0801ffbSGreg Roach
4371378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
44a0801ffbSGreg Roach    }
45a0801ffbSGreg Roach
46a0801ffbSGreg Roach    public function testSelectThemeForUser(): void
47a0801ffbSGreg Roach    {
48cd94ca66SGreg Roach        $user = $this->createMock(User::class);
49*00ef1d3aSGreg Roach        $user->expects($this->once())->method('setPreference')->with('theme', 'FOO');
50d403609dSGreg Roach
517adfb8e5SGreg Roach        $request = self::createRequest()
527adfb8e5SGreg Roach            ->withAttribute('user', $user)
537adfb8e5SGreg Roach            ->withAttribute('theme', 'FOO');
54d403609dSGreg Roach
55d403609dSGreg Roach        $handler  = new SelectTheme();
56a0801ffbSGreg Roach        $response = $handler->handle($request);
57a0801ffbSGreg Roach
5871378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_NO_CONTENT, $response->getStatusCode());
59a0801ffbSGreg Roach    }
60a0801ffbSGreg Roach}
61