xref: /webtrees/tests/app/Services/GedcomEditServiceTest.php (revision a6faacba1b18a38dad8f857aff08ab497dffa74b)
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            )
48        );
49
50        static::assertSame(
51            "1 BIRT Y\n2 ADDR England",
52            $gedcom_edit_service->editLinesToGedcom(
53                'INDI',
54                ['1', '2'],
55                ['BIRT', 'ADDR'],
56                ['Y', 'England']
57            )
58        );
59
60        static::assertSame(
61            "1 BIRT\n2 PLAC England",
62            $gedcom_edit_service->editLinesToGedcom(
63                'INDI',
64                ['1', '2'],
65                ['BIRT', 'PLAC'],
66                ['Y', 'England']
67            )
68        );
69
70        static::assertSame(
71            "1 BIRT\n2 PLAC England\n2 SOUR @S1@\n3 PAGE 123",
72            $gedcom_edit_service->editLinesToGedcom(
73                'INDI',
74                ['1', '2', '2', '3'],
75                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
76                ['Y', 'England', '@S1@', '123']
77            )
78        );
79
80        // Missing SOUR, so ignore PAGE
81        static::assertSame(
82            "1 BIRT\n2 PLAC England",
83            $gedcom_edit_service->editLinesToGedcom(
84                'INDI',
85                ['1', '2', '2', '3'],
86                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
87                ['Y', 'England', '', '123']
88            )
89        );
90
91        static::assertSame(
92            "1 BIRT\n2 PLAC England",
93            $gedcom_edit_service->editLinesToGedcom(
94                'INDI',
95                ['1', '2', '2', '3'],
96                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
97                ['Y', 'England', '', '123']
98            )
99        );
100
101        static::assertSame(
102            "1 BIRT\n2 PLAC England\n1 DEAT\n2 PLAC Scotland",
103            $gedcom_edit_service->editLinesToGedcom(
104                'INDI',
105                ['1', '2', '2', '3', '1', '2', '2', '3'],
106                ['BIRT', 'PLAC', 'SOUR', 'PAGE', 'DEAT', 'PLAC', 'SOUR', 'PAGE'],
107                ['Y', 'England', '', '123', 'Y', 'Scotland', '', '123']
108            )
109        );
110
111        static::assertSame(
112            "0 NOTE @N1@\n1 CONC foo\n1 CONT bar\n1 RESN locked",
113            $gedcom_edit_service->editLinesToGedcom(
114                'NOTE',
115                ['0', '1', '1'],
116                ['NOTE', 'CONC', 'RESN'],
117                ['@N1@', "foo\nbar", 'locked']
118            )
119        );
120    }
121}
122