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