xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 090a06287954f43677f06ea778b3f67c029de8fe)
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\Filesystem;
29use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
30
31/**
32 * Test ManageMediaData class.
33 *
34 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaData
35 */
36class ManageMediaDataTest extends TestCase
37{
38    protected static $uses_database = true;
39
40    /**
41     * @return void
42     */
43    public function testDataLocal(): void
44    {
45        $datatables_service = new DatatablesService();
46        $media_file_service = new MediaFileService();
47        $tree_service       = new TreeService();
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        $tree_service       = new TreeService();
70        $handler            = new ManageMediaData($datatables_service, $media_file_service, $tree_service);
71        $request            = self::createRequest(RequestMethodInterface::METHOD_GET, [
72            'files'        => 'local',
73            'media_folder' => '',
74            'subfolders'   => 'include',
75            'search'       => ['value' => ''],
76            'start'        => '0',
77            'length'       => '10',
78        ]);
79        $response           = $handler->handle($request);
80
81        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
82    }
83
84    /**
85     * @return void
86     */
87    public function testDataUnused(): void
88    {
89        $datatables_service = new DatatablesService();
90        $media_file_service = new MediaFileService();
91        $tree_service       = new TreeService();
92        $handler            = new ManageMediaData($datatables_service, $media_file_service, $tree_service);
93        $request            = self::createRequest(RequestMethodInterface::METHOD_GET, [
94            'files'        => 'local',
95            'media_folder' => '',
96            'subfolders'   => 'include',
97            'search'       => ['value' => ''],
98            'start'        => '0',
99            'length'       => '10',
100        ]);
101        $response           = $handler->handle($request);
102
103        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
104    }
105}
106