xref: /webtrees/tests/feature/RelationshipNamesTest.php (revision b72623fe90bc26fec6728adcea680bb1dca08618)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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;
21
22use Fisharebest\Webtrees\Factories\FamilyFactory;
23use Fisharebest\Webtrees\Factories\IndividualFactory;
24use Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates;
25use Fisharebest\Webtrees\Services\RelationshipService;
26
27/**
28 * Test the user functions
29 *
30 * @covers \Fisharebest\Webtrees\Relationship
31 * @covers \Fisharebest\Webtrees\Services\RelationshipService
32 * @covers \Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain
33 * @covers \Fisharebest\Webtrees\Module\ModuleLanguageTrait
34 */
35class RelationshipNamesTest extends TestCase
36{
37    /**
38     * @return void
39     */
40    public function testRelationshipNames(): void
41    {
42        //                                            i22m===f10===i23f
43        //                                                    |
44        //                                              +-----+-----+
45        //                                              |
46        //                                i20m===f9===i21f
47        //                                        |
48        //                           i19f===f8===i18m
49        //                                   |
50        //                     i16m===f7===i17f
51        //                            |
52        //              i12f===f4m===i11m  i13m===f5m===i14f
53        //                      |                  |
54        //                     i1m===f1m==========i2f===f2d===i6m
55        //                            |                  |
56        //                        +---+---+          +---+---+
57        //                        |   |   |          |   |   |
58        //          i10f===f3e===i3m i4f i5u       i7ma i8f i9u===f6===i15u
59        //
60        // Individual suffixes - m(ale), f(emale), u(nknown), a(dopted)
61        // Family suffixes - m(arried), d(ivorced), e(ngaged)
62        //
63        $tree = $this->createMock(Tree::class);
64
65        $individual_factory = $this->createStub(IndividualFactory::class);
66        $family_factory     = $this->createStub(FamilyFactory::class);
67
68        Registry::familyFactory($family_factory);
69        Registry::individualFactory($individual_factory);
70
71        $i1m  = new Individual('i1m', "0 @i1m@ INDI\n1 SEX M\n1 FAMS @f1m@\n1 FAMC @f4m@", null, $tree);
72        $i2f  = new Individual('i2f', "0 @i2f@ INDI\n1 SEX F\n1 FAMS @f1m@\n1 FAMS @f2d@\n2 FAMC @f5m@", null, $tree);
73        $i3m  = new Individual('i3m', "0 @i3m@ INDI\n1 SEX M\n1 FAMC @f1m@\n1 FAMS @f3e@\n1 BIRT\n2 DATE 2000", null, $tree);
74        $i4f  = new Individual('i4f', "0 @i4f@ INDI\n1 SEX F\n1 FAMC @f1m@\n1 BIRT\n2 DATE 2001", null, $tree);
75        $i5u  = new Individual('i5u', "0 @i5u@ INDI\n1 SEX U\n1 FAMC @f1m@\n1 BIRT\n2 DATE 2002", null, $tree);
76        $i6m  = new Individual('i6m', "0 @i6m@ INDI\n1 SEX M\n1 FAMS @f2d@", null, $tree);
77        $i7ma = new Individual('i7ma', "0 @i7ma@ INDI\n1 SEX M\n1 FAMC @f2d@\n2 PEDI adopted", null, $tree);
78        $i8f  = new Individual('i8f', "0 @i8f@ INDI\n1 SEX F\n1 FAMC @f2d@", null, $tree);
79        $i9u  = new Individual('i9u', "0 @i9u@ INDI\n1 SEX U\n1 FAMC @f2d@\n1 FAMS @f6@", null, $tree);
80        $i10f = new Individual('i10f', "0 @i10f@ INDI\n1 SEX F\n1 FAMS @f3e@", null, $tree);
81        $i11m = new Individual('i11m', "0 @i11f@ INDI\n1 SEX M\n1 FAMS @f4m@\n1 FAMC @f7@", null, $tree);
82        $i12f = new Individual('i12f', "0 @i12f@ INDI\n1 SEX F\n1 FAMS @f4m@", null, $tree);
83        $i13m = new Individual('i13m', "0 @i13f@ INDI\n1 SEX M\n1 FAMS @f5m@", null, $tree);
84        $i14f = new Individual('i14f', "0 @i14f@ INDI\n1 SEX F\n1 FAMS @f5m@", null, $tree);
85        $i15u = new Individual('i15u', "0 @i15u@ INDI\n1 SEX U\n1 FAMS @f6@", null, $tree);
86        $i16m = new Individual('i16m', "0 @i16m@ INDI\n1 SEX M\n1 FAMS @f7@", null, $tree);
87        $i17f = new Individual('i17f', "0 @i17f@ INDI\n1 SEX F\n1 FAMS @f7@\n1 FAMC @f8@", null, $tree);
88        $i18m = new Individual('i18m', "0 @i18m@ INDI\n1 SEX M\n1 FAMS @f8@\n1 FAMC @f9@", null, $tree);
89        $i19f = new Individual('i19f', "0 @i19f@ INDI\n1 SEX F\n1 FAMS @f8@", null, $tree);
90        $i20m = new Individual('i20m', "0 @i20m@ INDI\n1 SEX M\n1 FAMS @f9@", null, $tree);
91        $i21f = new Individual('i21f', "0 @i21f@ INDI\n1 SEX F\n1 FAMS @f9@\n1 FAMC @f10@", null, $tree);
92        $i22m = new Individual('i22m', "0 @i22m@ INDI\n1 SEX M\n1 FAMS @f10@", null, $tree);
93        $i23f = new Individual('i23f', "0 @i23f@ INDI\n1 SEX F\n1 FAMS @f10@", null, $tree);
94
95        $individual_factory->method('make')->will($this->returnValueMap([
96            'i1m'  => $i1m,
97            'i2f'  => $i2f,
98            'i3m'  => $i3m,
99            'i4f'  => $i4f,
100            'i5u'  => $i5u,
101            'i6m'  => $i6m,
102            'i7ma'  => $i7ma,
103            'i8f'  => $i8f,
104            'i9u'  => $i9u,
105            'i10f' => $i10f,
106            'i11m' => $i11m,
107            'i12f' => $i12f,
108            'i13m' => $i13m,
109            'i14f' => $i14f,
110            'i15u' => $i15u,
111            'i16m' => $i16m,
112            'i17f' => $i17f,
113            'i18m' => $i18m,
114            'i19f' => $i19f,
115            'i20m' => $i20m,
116            'i21f' => $i21f,
117        ]));
118
119        $f1m = new Family('f1m', "0 @f1m@ FAM\n1 MARR Y\n1 HUSB @i1m@\n1 WIFE @i2f@\n1 CHIL @i3m@\n1 CHIL @i4f@\n1 CHIL @i5u@", null, $tree);
120        $f2d = new Family('f2d', "0 @f2d@ FAM\n1 DIV Y\n1 HUSB @i6m@\n1 WIFE @i2f@\n1 CHIL @i7ma@\n1 CHIL @i8f@\n1 CHIL @i9u@", null, $tree);
121        $f3e = new Family('f3e', "0 @f3e@ FAM\n1 ENGA Y\n1 HUSB @i3m@\n1 WIFE @i10f@", null, $tree);
122        $f4m = new Family('f4m', "0 @f4m@ FAM\n1 MARR Y\n1 HUSB @i11m@\n1 WIFE @i12f@\n1 CHIL @i1m@", null, $tree);
123        $f5m = new Family('f5m', "0 @f5m@ FAM\n1 MARR Y\n1 HUSB @i13m@\n1 WIFE @i14f@\n1 CHIL @i2f@", null, $tree);
124        $f6  = new Family('f6', "0 @f6@ FAM\n1 HUSB @i9u@\n1 WIFE @i15u@", null, $tree);
125        $f7  = new Family('f7', "0 @f7@ FAM\n1 HUSB @i16m@\n1 WIFE @i17f@\n1 CHIL @i11m@", null, $tree);
126        $f8  = new Family('f8', "0 @f8@ FAM\n1 HUSB @i18m@\n1 WIFE @i19f@\n1 CHIL @i17f@", null, $tree);
127        $f9  = new Family('f9', "0 @f9@ FAM\n1 HUSB @i20m@\n1 WIFE @i21f@\n1 CHIL @i18m@", null, $tree);
128        $f10 = new Family('f10', "0 @f10@ FAM\n1 HUSB @i22m@\n1 WIFE @i23f@\n1 CHIL @i21f@", null, $tree);
129
130        $family_factory->method('make')->will($this->returnValueMap([
131            'f1m' => $f1m,
132            'f2d' => $f2d,
133            'f3e' => $f3e,
134            'f4m' => $f4m,
135            'f5m' => $f5m,
136            'f6'  => $f6,
137            'f7'  => $f7,
138            'f8'  => $f8,
139            'f9'  => $f9,
140            'f10'  => $f10,
141        ]));
142
143        $service = new RelationshipService();
144
145        // ENGLISH
146        $en_gb = new LanguageEnglishUnitedStates();
147        // Static relationships
148        self::assertSame('wife', $service->nameFromPath([$i1m, $f1m, $i2f], $en_gb));
149        self::assertSame('husband', $service->nameFromPath([$i2f, $f1m, $i1m], $en_gb));
150        self::assertSame('partner', $service->nameFromPath([$i9u, $f6, $i15u], $en_gb));
151        self::assertSame('ex-husband', $service->nameFromPath([$i2f, $f2d, $i6m], $en_gb));
152        self::assertSame('ex-wife', $service->nameFromPath([$i6m, $f2d, $i2f], $en_gb));
153        self::assertSame('fiancé', $service->nameFromPath([$i10f, $f3e, $i3m], $en_gb));
154        self::assertSame('fiancée', $service->nameFromPath([$i3m, $f3e, $i10f], $en_gb));
155        self::assertSame('son', $service->nameFromPath([$i1m, $f1m, $i3m], $en_gb));
156        self::assertSame('daughter', $service->nameFromPath([$i1m, $f1m, $i4f], $en_gb));
157        self::assertSame('child', $service->nameFromPath([$i1m, $f1m, $i5u], $en_gb));
158        self::assertSame('younger brother', $service->nameFromPath([$i4f, $f1m, $i3m], $en_gb));
159        self::assertSame('elder sister', $service->nameFromPath([$i3m, $f1m, $i4f], $en_gb));
160        self::assertSame('elder sibling', $service->nameFromPath([$i3m, $f1m, $i5u], $en_gb));
161        self::assertSame('brother', $service->nameFromPath([$i8f, $f2d, $i7ma], $en_gb));
162        self::assertSame('sister', $service->nameFromPath([$i7ma, $f2d, $i8f], $en_gb));
163        self::assertSame('sibling', $service->nameFromPath([$i7ma, $f2d, $i9u], $en_gb));
164        self::assertSame('adoptive-mother', $service->nameFromPath([$i7ma, $f2d, $i2f], $en_gb));
165        self::assertSame('adoptive-father', $service->nameFromPath([$i7ma, $f2d, $i6m], $en_gb));
166        self::assertSame('adopted-son', $service->nameFromPath([$i6m, $f2d, $i7ma], $en_gb));
167        self::assertSame('paternal-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m], $en_gb));
168        self::assertSame('paternal-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i12f], $en_gb));
169        self::assertSame('maternal-grandfather', $service->nameFromPath([$i3m, $f1m, $i2f, $f5m, $i13m], $en_gb));
170        self::assertSame('maternal-grandmother', $service->nameFromPath([$i3m, $f1m, $i2f, $f5m, $i14f], $en_gb));
171        // Dynamic relationships
172        self::assertSame('paternal great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i16m], $en_gb));
173        self::assertSame('paternal great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f], $en_gb));
174        self::assertSame('paternal great-great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m], $en_gb));
175        self::assertSame('paternal great-great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i19f], $en_gb));
176        self::assertSame('paternal great-great-great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i20m], $en_gb));
177        self::assertSame('paternal great-great-great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f], $en_gb));
178        self::assertSame('paternal great ×4 grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f, $f10, $i22m], $en_gb));
179        self::assertSame('paternal great ×4 grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f, $f10, $i23f], $en_gb));
180        // Compound relationships
181        self::assertSame('wife’s ex-husband', $service->nameFromPath([$i1m, $f1m, $i2f, $f2d, $i6m], $en_gb));
182
183        // SLOVAK
184    }
185}
186