xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 234e0863a607ff8e5f8e78a7fefe5366f39f8ebf)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22use Fig\Http\Message\RequestMethodInterface;
23use Fig\Http\Message\StatusCodeInterface;
24use Fisharebest\Webtrees\Services\DatatablesService;
25use Fisharebest\Webtrees\Services\GedcomImportService;
26use Fisharebest\Webtrees\Services\LinkedRecordService;
27use Fisharebest\Webtrees\Services\MediaFileService;
28use Fisharebest\Webtrees\Services\TreeService;
29use Fisharebest\Webtrees\TestCase;
30use Illuminate\Support\Collection;
31use PHPUnit\Framework\Attributes\CoversClass;
32
33
34#[CoversClass(ManageMediaData::class)]
35class ManageMediaDataTest extends TestCase
36{
37    protected static bool $uses_database = true;
38
39    public function testDataLocal(): void
40    {
41        $datatables_service    = new DatatablesService();
42        $gedcom_import_service = new GedcomImportService();
43        $linked_record_service = new LinkedRecordService();
44        $media_file_service    = $this->createMock(MediaFileService::class);
45        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
46        $tree_service          = new TreeService($gedcom_import_service);
47        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
48        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
49            'files'        => 'local',
50            'media_folder' => 'media/',
51            'subfolders'   => 'include',
52            'search'       => ['value' => ''],
53            'start'        => '0',
54            'length'       => '10',
55        ]);
56        $response              = $handler->handle($request);
57
58        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
59    }
60
61    public function testDataExternal(): void
62    {
63        $datatables_service    = new DatatablesService();
64        $gedcom_import_service = new GedcomImportService();
65        $linked_record_service = new LinkedRecordService();
66        $media_file_service    = $this->createMock(MediaFileService::class);
67        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
68        $tree_service          = new TreeService($gedcom_import_service);
69        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
70        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
71            'files'        => 'local',
72            'media_folder' => 'media/',
73            'subfolders'   => 'include',
74            'search'       => ['value' => ''],
75            'start'        => '0',
76            'length'       => '10',
77        ]);
78        $response              = $handler->handle($request);
79
80        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
81    }
82
83    public function testDataUnused(): void
84    {
85        $datatables_service    = new DatatablesService();
86        $gedcom_import_service = new GedcomImportService();
87        $linked_record_service = new LinkedRecordService();
88        $media_file_service    = $this->createMock(MediaFileService::class);
89        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
90        $tree_service          = new TreeService($gedcom_import_service);
91        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
92        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
93            'files'        => 'local',
94            'media_folder' => 'media/',
95            'subfolders'   => 'include',
96            'search'       => ['value' => ''],
97            'start'        => '0',
98            'length'       => '10',
99        ]);
100        $response              = $handler->handle($request);
101
102        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
103    }
104}
105