xref: /webtrees/tests/app/Http/RequestHandlers/ManageMediaDataTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
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#[CoversClass(ManageMediaData::class)]
348ce3bd73SGreg Roachclass ManageMediaDataTest extends TestCase
358ce3bd73SGreg Roach{
36cd94ca66SGreg Roach    protected static bool $uses_database = true;
378ce3bd73SGreg Roach
388ce3bd73SGreg Roach    public function testDataLocal(): void
398ce3bd73SGreg Roach    {
408ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
412c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
424991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
4396126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
4496126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
452c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
464991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
478ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
488ce3bd73SGreg Roach            'files'        => 'local',
4996126da4SGreg Roach            'media_folder' => 'media/',
508ce3bd73SGreg Roach            'subfolders'   => 'include',
518ce3bd73SGreg Roach            'search'       => ['value' => ''],
528ce3bd73SGreg Roach            'start'        => '0',
538ce3bd73SGreg Roach            'length'       => '10',
548ce3bd73SGreg Roach        ]);
558ce3bd73SGreg Roach        $response              = $handler->handle($request);
568ce3bd73SGreg Roach
578ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
588ce3bd73SGreg Roach    }
598ce3bd73SGreg Roach
608ce3bd73SGreg Roach    public function testDataExternal(): void
618ce3bd73SGreg Roach    {
628ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
632c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
644991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
6596126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
6696126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
672c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
684991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
698ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
708ce3bd73SGreg Roach            'files'        => 'local',
7196126da4SGreg Roach            'media_folder' => 'media/',
728ce3bd73SGreg Roach            'subfolders'   => 'include',
738ce3bd73SGreg Roach            'search'       => ['value' => ''],
748ce3bd73SGreg Roach            'start'        => '0',
758ce3bd73SGreg Roach            'length'       => '10',
768ce3bd73SGreg Roach        ]);
778ce3bd73SGreg Roach        $response              = $handler->handle($request);
788ce3bd73SGreg Roach
798ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
808ce3bd73SGreg Roach    }
818ce3bd73SGreg Roach
828ce3bd73SGreg Roach    public function testDataUnused(): void
838ce3bd73SGreg Roach    {
848ce3bd73SGreg Roach        $datatables_service    = new DatatablesService();
852c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
864991f205SGreg Roach        $linked_record_service = new LinkedRecordService();
8796126da4SGreg Roach        $media_file_service    = $this->createMock(MediaFileService::class);
8896126da4SGreg Roach        $media_file_service->method('allMediaFolders')->willReturn(new Collection(['media/']));
892c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
904991f205SGreg Roach        $handler               = new ManageMediaData($datatables_service, $linked_record_service, $media_file_service, $tree_service);
918ce3bd73SGreg Roach        $request               = self::createRequest(RequestMethodInterface::METHOD_GET, [
928ce3bd73SGreg Roach            'files'        => 'local',
9396126da4SGreg Roach            'media_folder' => 'media/',
948ce3bd73SGreg Roach            'subfolders'   => 'include',
958ce3bd73SGreg Roach            'search'       => ['value' => ''],
968ce3bd73SGreg Roach            'start'        => '0',
978ce3bd73SGreg Roach            'length'       => '10',
988ce3bd73SGreg Roach        ]);
998ce3bd73SGreg Roach        $response              = $handler->handle($request);
1008ce3bd73SGreg Roach
1018ce3bd73SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
1028ce3bd73SGreg Roach    }
1038ce3bd73SGreg Roach}
104