xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 36de22acf6348b1059dac63e3cd19589574906ac)
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\MediaFileService;
26use Fisharebest\Webtrees\Services\TreeService;
27use Fisharebest\Webtrees\TestCase;
28use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
29
30/**
31 * Test ManageMediaData class.
32 *
33 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaData
34 */
35class ManageMediaDataTest extends TestCase
36{
37    protected static $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        $tree_service       = new TreeService();
47        $handler            = new ManageMediaData($datatables_service, $media_file_service, $tree_service);
48        $request            = self::createRequest(RequestMethodInterface::METHOD_GET, [
49            'files'        => 'local',
50            'media_folder' => '',
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    /**
62     * @return void
63     */
64    public function testDataExternal(): void
65    {
66        $datatables_service = new DatatablesService();
67        $media_file_service = new MediaFileService();
68        $tree_service       = new TreeService();
69        $handler            = new ManageMediaData($datatables_service, $media_file_service, $tree_service);
70        $request            = self::createRequest(RequestMethodInterface::METHOD_GET, [
71            'files'        => 'local',
72            'media_folder' => '',
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    /**
84     * @return void
85     */
86    public function testDataUnused(): void
87    {
88        $datatables_service = new DatatablesService();
89        $media_file_service = new MediaFileService();
90        $tree_service       = new TreeService();
91        $handler            = new ManageMediaData($datatables_service, $media_file_service, $tree_service);
92        $request            = self::createRequest(RequestMethodInterface::METHOD_GET, [
93            'files'        => 'local',
94            'media_folder' => '',
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