xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 54c1426ef019dee75f3e7bd3fa3ca06d5420591a)
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;
31
32/**
33 * Test ManageMediaData class.
34 *
35 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaData
36 */
37class ManageMediaDataTest extends TestCase
38{
39    protected static bool $uses_database = true;
40
41    public function testDataLocal(): void
42    {
43        $datatables_service    = new DatatablesService();
44        $gedcom_import_service = new GedcomImportService();
45        $linked_record_service = new LinkedRecordService();
46        $media_file_service    = $this->createMock(MediaFileService::class);
47        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
48        $tree_service          = new TreeService($gedcom_import_service);
49        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
50        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
51            'files'        => 'local',
52            'media_folder' => 'media/',
53            'subfolders'   => 'include',
54            'search'       => ['value' => ''],
55            'start'        => '0',
56            'length'       => '10',
57        ]);
58        $response              = $handler->handle($request);
59
60        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
61    }
62
63    public function testDataExternal(): void
64    {
65        $datatables_service    = new DatatablesService();
66        $gedcom_import_service = new GedcomImportService();
67        $linked_record_service = new LinkedRecordService();
68        $media_file_service    = $this->createMock(MediaFileService::class);
69        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
70        $tree_service          = new TreeService($gedcom_import_service);
71        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
72        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
73            'files'        => 'local',
74            'media_folder' => 'media/',
75            'subfolders'   => 'include',
76            'search'       => ['value' => ''],
77            'start'        => '0',
78            'length'       => '10',
79        ]);
80        $response              = $handler->handle($request);
81
82        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
83    }
84
85    public function testDataUnused(): void
86    {
87        $datatables_service    = new DatatablesService();
88        $gedcom_import_service = new GedcomImportService();
89        $linked_record_service = new LinkedRecordService();
90        $media_file_service    = $this->createMock(MediaFileService::class);
91        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
92        $tree_service          = new TreeService($gedcom_import_service);
93        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
94        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
95            'files'        => 'local',
96            'media_folder' => 'media/',
97            'subfolders'   => 'include',
98            'search'       => ['value' => ''],
99            'start'        => '0',
100            'length'       => '10',
101        ]);
102        $response              = $handler->handle($request);
103
104        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
105    }
106}
107