xref: /webtrees/tests/app/Services/GedcomEditServiceTest.php (revision 75ed689eddcf20bfb18d1b792102452dce07ffd5)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 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\Services;
21
22use Fisharebest\Webtrees\TestCase;
23
24/**
25 * Test harness for the class GedcomEditService
26 *
27 * @covers \Fisharebest\Webtrees\Services\GedcomEditService
28 */
29class GedcomEditServiceTest extends TestCase
30{
31    protected static bool $uses_database = true;
32
33    /**
34     * @covers \Fisharebest\Webtrees\Services\GedcomEditService::editLinesToGedcom
35     */
36    public function testEditLinesToGedcom(): void
37    {
38        $gedcom_edit_service = new GedcomEditService();
39
40        static::assertSame(
41            '1 BIRT Y',
42            $gedcom_edit_service->editLinesToGedcom(
43                'INDI',
44                ['1'],
45                ['BIRT'],
46                ['Y'],
47                false
48            )
49        );
50
51        static::assertSame(
52            "\n1 BIRT Y\n2 ADDR England",
53            $gedcom_edit_service->editLinesToGedcom(
54                'INDI',
55                ['1', '2'],
56                ['BIRT', 'ADDR'],
57                ['Y', 'England']
58            )
59        );
60
61        static::assertSame(
62            "\n1 BIRT\n2 PLAC England",
63            $gedcom_edit_service->editLinesToGedcom(
64                'INDI',
65                ['1', '2'],
66                ['BIRT', 'PLAC'],
67                ['Y', 'England']
68            )
69        );
70
71        static::assertSame(
72            "\n1 BIRT\n2 PLAC England\n2 SOUR @S1@\n3 PAGE 123",
73            $gedcom_edit_service->editLinesToGedcom(
74                'INDI',
75                ['1', '2', '2', '3'],
76                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
77                ['Y', 'England', '@S1@', '123']
78            )
79        );
80
81        // Missing SOUR, so ignore PAGE
82        static::assertSame(
83            "\n1 BIRT\n2 PLAC England",
84            $gedcom_edit_service->editLinesToGedcom(
85                'INDI',
86                ['1', '2', '2', '3'],
87                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
88                ['Y', 'England', '', '123']
89            )
90        );
91
92        static::assertSame(
93            "\n1 BIRT\n2 PLAC England",
94            $gedcom_edit_service->editLinesToGedcom(
95                'INDI',
96                ['1', '2', '2', '3'],
97                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
98                ['Y', 'England', '', '123']
99            )
100        );
101
102        static::assertSame(
103            "\n1 BIRT\n2 PLAC England\n1 DEAT\n2 PLAC Scotland",
104            $gedcom_edit_service->editLinesToGedcom(
105                'INDI',
106                ['1', '2', '2', '3', '1', '2', '2', '3'],
107                ['BIRT', 'PLAC', 'SOUR', 'PAGE', 'DEAT', 'PLAC', 'SOUR', 'PAGE'],
108                ['Y', 'England', '', '123', 'Y', 'Scotland', '', '123']
109            )
110        );
111    }
112}
113