xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
18ce3bd73SGreg Roach<?php
28ce3bd73SGreg Roach
38ce3bd73SGreg Roach/**
48ce3bd73SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
68ce3bd73SGreg Roach * This program is free software: you can redistribute it and/or modify
78ce3bd73SGreg Roach * it under the terms of the GNU General Public License as published by
88ce3bd73SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98ce3bd73SGreg Roach * (at your option) any later version.
108ce3bd73SGreg Roach * This program is distributed in the hope that it will be useful,
118ce3bd73SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128ce3bd73SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138ce3bd73SGreg Roach * GNU General Public License for more details.
148ce3bd73SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168ce3bd73SGreg Roach */
178ce3bd73SGreg Roach
188ce3bd73SGreg Roachdeclare(strict_types=1);
198ce3bd73SGreg Roach
208ce3bd73SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
218ce3bd73SGreg Roach
228ce3bd73SGreg Roachuse Fig\Http\Message\RequestMethodInterface;
238ce3bd73SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
248ce3bd73SGreg Roachuse Fisharebest\Webtrees\Services\DatatablesService;
252c685d76SGreg Roachuse Fisharebest\Webtrees\Services\GedcomImportService;
264991f205SGreg Roachuse Fisharebest\Webtrees\Services\LinkedRecordService;
278ce3bd73SGreg Roachuse Fisharebest\Webtrees\Services\MediaFileService;
288ce3bd73SGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
298ce3bd73SGreg Roachuse Fisharebest\Webtrees\TestCase;
3096126da4SGreg Roachuse Illuminate\Support\Collection;
31*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
328ce3bd73SGreg Roach
33*202c018bSGreg Roach
34*202c018bSGreg Roach#[CoversClass(ManageMediaData::class)]
358ce3bd73SGreg Roachclass ManageMediaDataTest extends TestCase
368ce3bd73SGreg Roach{
37cd94ca66SGreg Roach    protected static bool $uses_database = true;
388ce3bd73SGreg Roach
398ce3bd73SGreg Roach    public function testDataLocal(): void
408ce3bd73SGreg Roach    {
418ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
422c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
434991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
4496126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
4596126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
462c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
474991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
488ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
498ce3bd73SGreg Roach            'files'        => 'local',
5096126da4SGreg Roach            'media_folder' => 'media/',
518ce3bd73SGreg Roach            'subfolders'   => 'include',
528ce3bd73SGreg Roach            'search'       => ['value' => ''],
538ce3bd73SGreg Roach            'start'        => '0',
548ce3bd73SGreg Roach            'length'       => '10',
558ce3bd73SGreg Roach        ]);
568ce3bd73SGreg Roach        $response              = $handler->handle($request);
578ce3bd73SGreg Roach
588ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
598ce3bd73SGreg Roach    }
608ce3bd73SGreg Roach
618ce3bd73SGreg Roach    public function testDataExternal(): void
628ce3bd73SGreg Roach    {
638ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
642c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
654991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
6696126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
6796126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
682c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
694991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
708ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
718ce3bd73SGreg Roach            'files'        => 'local',
7296126da4SGreg Roach            'media_folder' => 'media/',
738ce3bd73SGreg Roach            'subfolders'   => 'include',
748ce3bd73SGreg Roach            'search'       => ['value' => ''],
758ce3bd73SGreg Roach            'start'        => '0',
768ce3bd73SGreg Roach            'length'       => '10',
778ce3bd73SGreg Roach        ]);
788ce3bd73SGreg Roach        $response              = $handler->handle($request);
798ce3bd73SGreg Roach
808ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
818ce3bd73SGreg Roach    }
828ce3bd73SGreg Roach
838ce3bd73SGreg Roach    public function testDataUnused(): void
848ce3bd73SGreg Roach    {
858ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
862c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
874991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
8896126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
8996126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
902c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
914991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
928ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
938ce3bd73SGreg Roach            'files'        => 'local',
9496126da4SGreg Roach            'media_folder' => 'media/',
958ce3bd73SGreg Roach            'subfolders'   => 'include',
968ce3bd73SGreg Roach            'search'       => ['value' => ''],
978ce3bd73SGreg Roach            'start'        => '0',
988ce3bd73SGreg Roach            'length'       => '10',
998ce3bd73SGreg Roach        ]);
1008ce3bd73SGreg Roach        $response              = $handler->handle($request);
1018ce3bd73SGreg Roach
1028ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
1038ce3bd73SGreg Roach    }
1048ce3bd73SGreg Roach}
105