xref: /webtrees/tests/app/Services/GedcomEditServiceTest.php (revision a92a07c79bdf61915fb2107b92a9eaae1d2f2d04)
1cb62cb3cSGreg Roach<?php
2cb62cb3cSGreg Roach
3cb62cb3cSGreg Roach/**
4cb62cb3cSGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
6cb62cb3cSGreg Roach * This program is free software: you can redistribute it and/or modify
7cb62cb3cSGreg Roach * it under the terms of the GNU General Public License as published by
8cb62cb3cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9cb62cb3cSGreg Roach * (at your option) any later version.
10cb62cb3cSGreg Roach * This program is distributed in the hope that it will be useful,
11cb62cb3cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12cb62cb3cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13cb62cb3cSGreg Roach * GNU General Public License for more details.
14cb62cb3cSGreg Roach * You should have received a copy of the GNU General Public License
15cb62cb3cSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16cb62cb3cSGreg Roach */
17cb62cb3cSGreg Roach
18cb62cb3cSGreg Roachdeclare(strict_types=1);
19cb62cb3cSGreg Roach
20cb62cb3cSGreg Roachnamespace Fisharebest\Webtrees\Services;
21cb62cb3cSGreg Roach
22cb62cb3cSGreg Roachuse Fisharebest\Webtrees\TestCase;
23cb62cb3cSGreg Roach
24cb62cb3cSGreg Roach/**
25cb62cb3cSGreg Roach * Test harness for the class GedcomEditService
26cb62cb3cSGreg Roach *
27cb62cb3cSGreg Roach * @covers \Fisharebest\Webtrees\Services\GedcomEditService
28cb62cb3cSGreg Roach */
29cb62cb3cSGreg Roachclass GedcomEditServiceTest extends TestCase
30cb62cb3cSGreg Roach{
3100c92694SGreg Roach    protected static bool $uses_database = true;
3200c92694SGreg Roach
33cb62cb3cSGreg Roach    /**
34cb62cb3cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\GedcomEditService::editLinesToGedcom
35cb62cb3cSGreg Roach     */
36cb62cb3cSGreg Roach    public function testEditLinesToGedcom(): void
37cb62cb3cSGreg Roach    {
38cb62cb3cSGreg Roach        $gedcom_edit_service = new GedcomEditService();
39cb62cb3cSGreg Roach
40f01ab4acSGreg Roach        static::assertSame(
416e60786aSGreg Roach            '1 BIRT Y',
42cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
43cb62cb3cSGreg Roach                'INDI',
44cb62cb3cSGreg Roach                ['1'],
45cb62cb3cSGreg Roach                ['BIRT'],
46*a92a07c7SGreg Roach                ['Y'],
47*a92a07c7SGreg Roach                false
48cb62cb3cSGreg Roach            )
49cb62cb3cSGreg Roach        );
50cb62cb3cSGreg Roach
51f01ab4acSGreg Roach        static::assertSame(
52*a92a07c7SGreg Roach            "\n1 BIRT Y\n2 ADDR England",
53cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
54cb62cb3cSGreg Roach                'INDI',
55cb62cb3cSGreg Roach                ['1', '2'],
56cb62cb3cSGreg Roach                ['BIRT', 'ADDR'],
57cb62cb3cSGreg Roach                ['Y', 'England']
58cb62cb3cSGreg Roach            )
59cb62cb3cSGreg Roach        );
60cb62cb3cSGreg Roach
61f01ab4acSGreg Roach        static::assertSame(
62*a92a07c7SGreg Roach            "\n1 BIRT\n2 PLAC England",
63cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
64cb62cb3cSGreg Roach                'INDI',
65cb62cb3cSGreg Roach                ['1', '2'],
66cb62cb3cSGreg Roach                ['BIRT', 'PLAC'],
67cb62cb3cSGreg Roach                ['Y', 'England']
68cb62cb3cSGreg Roach            )
69cb62cb3cSGreg Roach        );
70cb62cb3cSGreg Roach
71f01ab4acSGreg Roach        static::assertSame(
72*a92a07c7SGreg Roach            "\n1 BIRT\n2 PLAC England\n2 SOUR @S1@\n3 PAGE 123",
73cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
74cb62cb3cSGreg Roach                'INDI',
75cb62cb3cSGreg Roach                ['1', '2', '2', '3'],
76cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
77cb62cb3cSGreg Roach                ['Y', 'England', '@S1@', '123']
78cb62cb3cSGreg Roach            )
79cb62cb3cSGreg Roach        );
80cb62cb3cSGreg Roach
81cefd719cSGreg Roach        // Missing SOUR, so ignore PAGE
82f01ab4acSGreg Roach        static::assertSame(
83*a92a07c7SGreg Roach            "\n1 BIRT\n2 PLAC England",
84cefd719cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
85cefd719cSGreg Roach                'INDI',
86cefd719cSGreg Roach                ['1', '2', '2', '3'],
87cefd719cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
88cefd719cSGreg Roach                ['Y', 'England', '', '123']
89cefd719cSGreg Roach            )
90cefd719cSGreg Roach        );
91cefd719cSGreg Roach
92f01ab4acSGreg Roach        static::assertSame(
93*a92a07c7SGreg Roach            "\n1 BIRT\n2 PLAC England",
94cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
95cb62cb3cSGreg Roach                'INDI',
96cb62cb3cSGreg Roach                ['1', '2', '2', '3'],
97cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
98cb62cb3cSGreg Roach                ['Y', 'England', '', '123']
99cb62cb3cSGreg Roach            )
100cb62cb3cSGreg Roach        );
101cb62cb3cSGreg Roach
102f01ab4acSGreg Roach        static::assertSame(
103*a92a07c7SGreg Roach            "\n1 BIRT\n2 PLAC England\n1 DEAT\n2 PLAC Scotland",
104cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
105cb62cb3cSGreg Roach                'INDI',
106cb62cb3cSGreg Roach                ['1', '2', '2', '3', '1', '2', '2', '3'],
107cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE', 'DEAT', 'PLAC', 'SOUR', 'PAGE'],
108cb62cb3cSGreg Roach                ['Y', 'England', '', '123', 'Y', 'Scotland', '', '123']
109cb62cb3cSGreg Roach            )
110cb62cb3cSGreg Roach        );
111cb62cb3cSGreg Roach    }
112cb62cb3cSGreg Roach}
113