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