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