16c21f8beSGreg Roach<?php 26c21f8beSGreg Roach 36c21f8beSGreg Roach/** 46c21f8beSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 66c21f8beSGreg Roach * This program is free software: you can redistribute it and/or modify 76c21f8beSGreg Roach * it under the terms of the GNU General Public License as published by 86c21f8beSGreg Roach * the Free Software Foundation, either version 3 of the License, or 96c21f8beSGreg Roach * (at your option) any later version. 106c21f8beSGreg Roach * This program is distributed in the hope that it will be useful, 116c21f8beSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126c21f8beSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136c21f8beSGreg Roach * GNU General Public License for more details. 146c21f8beSGreg Roach * You should have received a copy of the GNU General Public License 156c21f8beSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 166c21f8beSGreg Roach */ 176c21f8beSGreg Roach 186c21f8beSGreg Roachdeclare(strict_types=1); 196c21f8beSGreg Roach 206c21f8beSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 216c21f8beSGreg Roach 226c21f8beSGreg Roachuse Fig\Http\Message\StatusCodeInterface; 236c21f8beSGreg Roachuse Fisharebest\Webtrees\Services\SiteLogsService; 246c21f8beSGreg Roachuse Fisharebest\Webtrees\TestCase; 256c21f8beSGreg Roachuse Illuminate\Database\Query\Builder; 266c21f8beSGreg Roachuse Illuminate\Support\Collection; 27202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 286c21f8beSGreg Roach 29202c018bSGreg Roach#[CoversClass(SiteLogsDownload::class)] 306c21f8beSGreg Roachclass SiteLogsDownloadTest extends TestCase 316c21f8beSGreg Roach{ 326c21f8beSGreg Roach public function testResponse(): void 336c21f8beSGreg Roach { 346c21f8beSGreg Roach $request = self::createRequest(); 356c21f8beSGreg Roach 36*62ff2f18SGreg Roach $query1 = $this->createMock(Builder::class); 37*62ff2f18SGreg Roach $query2 = $this->createMock(Builder::class); 38*62ff2f18SGreg Roach $rows1 = $this->createMock(Collection::class); 39*62ff2f18SGreg Roach $rows2 = $this->createMock(Collection::class); 406c21f8beSGreg Roach $query1->method('orderBy')->willReturn($query2); 416c21f8beSGreg Roach $query2->method('get')->willReturn($rows1); 426c21f8beSGreg Roach $rows1->method('map')->willReturn($rows2); 436c21f8beSGreg Roach $rows2->method('implode')->willReturn('foo,bar'); 446c21f8beSGreg Roach 45*62ff2f18SGreg Roach $site_logs_service = $this->createMock(SiteLogsService::class); 466c21f8beSGreg Roach $site_logs_service->method('logsQuery')->willReturn($query1); 476c21f8beSGreg Roach 486c21f8beSGreg Roach $handler = new SiteLogsDownload($site_logs_service); 496c21f8beSGreg Roach $response = $handler->handle($request); 506c21f8beSGreg Roach 516172e7f6SGreg Roach static::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); 526172e7f6SGreg Roach static::assertSame('text/csv; charset=UTF-8', $response->getHeaderLine('content-type')); 536172e7f6SGreg Roach static::assertSame('attachment; filename="webtrees-logs.csv"', $response->getHeaderLine('content-disposition')); 546c21f8beSGreg Roach } 556c21f8beSGreg Roach} 56