xref: /webtrees/tests/app/Http/RequestHandlers/BroadcastPageTest.php (revision 62ff2f188c699b1144fb2ca2d6da1358d5e1a745)
124f79581SGreg Roach<?php
224f79581SGreg Roach
324f79581SGreg Roach/**
424f79581SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
624f79581SGreg Roach * This program is free software: you can redistribute it and/or modify
724f79581SGreg Roach * it under the terms of the GNU General Public License as published by
824f79581SGreg Roach * the Free Software Foundation, either version 3 of the License, or
924f79581SGreg Roach * (at your option) any later version.
1024f79581SGreg Roach * This program is distributed in the hope that it will be useful,
1124f79581SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1224f79581SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1324f79581SGreg Roach * GNU General Public License for more details.
1424f79581SGreg Roach * You should have received a copy of the GNU General Public License
1524f79581SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
1624f79581SGreg Roach */
1724f79581SGreg Roach
1824f79581SGreg Roachdeclare(strict_types=1);
1924f79581SGreg Roach
2024f79581SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
2124f79581SGreg Roach
2224f79581SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
2324f79581SGreg Roachuse Fisharebest\Webtrees\Http\Exceptions\HttpBadRequestException;
2424f79581SGreg Roachuse Fisharebest\Webtrees\Services\MessageService;
2524f79581SGreg Roachuse Fisharebest\Webtrees\TestCase;
2624f79581SGreg Roachuse Illuminate\Support\Collection;
27202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
2824f79581SGreg Roach
29202c018bSGreg Roach#[CoversClass(BroadcastPage::class)]
3024f79581SGreg Roachclass BroadcastPageTest extends TestCase
3124f79581SGreg Roach{
3224f79581SGreg Roach    protected static bool $uses_database = true;
3324f79581SGreg Roach
3424f79581SGreg Roach    public function testMissingParameterTo(): void
3524f79581SGreg Roach    {
36*62ff2f18SGreg Roach        $message_service = $this->createMock(MessageService::class);
3724f79581SGreg Roach        $message_service->method('recipientTypes')->willReturn(['foo' => 'FOO']);
3824f79581SGreg Roach
3924f79581SGreg Roach        $request = self::createRequest()
4024f79581SGreg Roach            ->withAttribute('to', 'bar');
4124f79581SGreg Roach
4224f79581SGreg Roach        $handler = new BroadcastPage($message_service);
4324f79581SGreg Roach
4424f79581SGreg Roach        $this->expectException(HttpBadRequestException::class);
4524f79581SGreg Roach
4624f79581SGreg Roach        $handler->handle($request);
4724f79581SGreg Roach    }
4824f79581SGreg Roach    public function testHandler(): void
4924f79581SGreg Roach    {
50*62ff2f18SGreg Roach        $message_service = $this->createMock(MessageService::class);
5124f79581SGreg Roach        $message_service->method('recipientTypes')->willReturn(['foo' => 'FOO', 'bar' => 'BAR']);
5224f79581SGreg Roach        $message_service->method('recipientUsers')->willReturn(new Collection());
5324f79581SGreg Roach
5424f79581SGreg Roach        $request = self::createRequest()
5524f79581SGreg Roach            ->withAttribute('to', 'foo');
5624f79581SGreg Roach
5724f79581SGreg Roach        $handler  = new BroadcastPage($message_service);
5824f79581SGreg Roach        $response = $handler->handle($request);
5924f79581SGreg Roach
6024f79581SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
6124f79581SGreg Roach    }
6224f79581SGreg Roach}
63