xref: /webtrees/tests/app/Services/GedcomEditServiceTest.php (revision cefd719cbe1294fc6d2ccd78d511950b7752b873)
1cb62cb3cSGreg Roach<?php
2cb62cb3cSGreg Roach
3cb62cb3cSGreg Roach/**
4cb62cb3cSGreg Roach * webtrees: online genealogy
5cb62cb3cSGreg Roach * Copyright (C) 2021 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{
31cb62cb3cSGreg Roach    /**
32cb62cb3cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\GedcomEditService::editLinesToGedcom
33cb62cb3cSGreg Roach     */
34cb62cb3cSGreg Roach    public function testEditLinesToGedcom(): void
35cb62cb3cSGreg Roach    {
36cb62cb3cSGreg Roach        $gedcom_edit_service = new GedcomEditService();
37cb62cb3cSGreg Roach
38cb62cb3cSGreg Roach        $this->assertSame(
39cb62cb3cSGreg Roach            "1 BIRT Y",
40cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
41cb62cb3cSGreg Roach                'INDI',
42cb62cb3cSGreg Roach                ['1'],
43cb62cb3cSGreg Roach                ['BIRT'],
44cb62cb3cSGreg Roach                ['Y']
45cb62cb3cSGreg Roach            )
46cb62cb3cSGreg Roach        );
47cb62cb3cSGreg Roach
48cb62cb3cSGreg Roach        $this->assertSame(
49cb62cb3cSGreg Roach            "1 BIRT Y\n2 ADDR England",
50cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
51cb62cb3cSGreg Roach                'INDI',
52cb62cb3cSGreg Roach                ['1', '2'],
53cb62cb3cSGreg Roach                ['BIRT', 'ADDR'],
54cb62cb3cSGreg Roach                ['Y', 'England']
55cb62cb3cSGreg Roach            )
56cb62cb3cSGreg Roach        );
57cb62cb3cSGreg Roach
58cb62cb3cSGreg Roach        $this->assertSame(
59cb62cb3cSGreg Roach            "1 BIRT\n2 PLAC England",
60cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
61cb62cb3cSGreg Roach                'INDI',
62cb62cb3cSGreg Roach                ['1', '2'],
63cb62cb3cSGreg Roach                ['BIRT', 'PLAC'],
64cb62cb3cSGreg Roach                ['Y', 'England']
65cb62cb3cSGreg Roach            )
66cb62cb3cSGreg Roach        );
67cb62cb3cSGreg Roach
68cb62cb3cSGreg Roach        $this->assertSame(
69cb62cb3cSGreg Roach            "1 BIRT\n2 PLAC England\n2 SOUR @S1@\n3 PAGE 123",
70cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
71cb62cb3cSGreg Roach                'INDI',
72cb62cb3cSGreg Roach                ['1', '2', '2', '3'],
73cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
74cb62cb3cSGreg Roach                ['Y', 'England', '@S1@', '123']
75cb62cb3cSGreg Roach            )
76cb62cb3cSGreg Roach        );
77cb62cb3cSGreg Roach
78*cefd719cSGreg Roach        // Missing SOUR, so ignore PAGE
79*cefd719cSGreg Roach        $this->assertSame(
80*cefd719cSGreg Roach            "1 BIRT\n2 PLAC England",
81*cefd719cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
82*cefd719cSGreg Roach                'INDI',
83*cefd719cSGreg Roach                ['1', '2', '2', '3'],
84*cefd719cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
85*cefd719cSGreg Roach                ['Y', 'England', '', '123']
86*cefd719cSGreg Roach            )
87*cefd719cSGreg Roach        );
88*cefd719cSGreg Roach
89cb62cb3cSGreg Roach        $this->assertSame(
90cb62cb3cSGreg Roach            "1 BIRT\n2 PLAC England",
91cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
92cb62cb3cSGreg Roach                'INDI',
93cb62cb3cSGreg Roach                ['1', '2', '2', '3'],
94cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE'],
95cb62cb3cSGreg Roach                ['Y', 'England', '', '123']
96cb62cb3cSGreg Roach            )
97cb62cb3cSGreg Roach        );
98cb62cb3cSGreg Roach
99cb62cb3cSGreg Roach        $this->assertSame(
100cb62cb3cSGreg Roach            "1 BIRT\n2 PLAC England\n1 DEAT\n2 PLAC Scotland",
101cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
102cb62cb3cSGreg Roach                'INDI',
103cb62cb3cSGreg Roach                ['1', '2', '2', '3', '1', '2', '2', '3'],
104cb62cb3cSGreg Roach                ['BIRT', 'PLAC', 'SOUR', 'PAGE', 'DEAT', 'PLAC', 'SOUR', 'PAGE'],
105cb62cb3cSGreg Roach                ['Y', 'England', '', '123', 'Y', 'Scotland', '', '123']
106cb62cb3cSGreg Roach            )
107cb62cb3cSGreg Roach        );
108cb62cb3cSGreg Roach
109cb62cb3cSGreg Roach        $this->assertSame(
110cb62cb3cSGreg Roach            "0 NOTE @N1@\n1 CONC foo\n1 CONT bar\n1 RESN locked",
111cb62cb3cSGreg Roach            $gedcom_edit_service->editLinesToGedcom(
112cb62cb3cSGreg Roach                'NOTE',
113cb62cb3cSGreg Roach                ['0', '1', '1'],
114cb62cb3cSGreg Roach                ['NOTE', 'CONC', 'RESN'],
115cb62cb3cSGreg Roach                ['@N1@', "foo\nbar", 'locked']
116cb62cb3cSGreg Roach            )
117cb62cb3cSGreg Roach        );
118cb62cb3cSGreg Roach    }
119cb62cb3cSGreg Roach}
120