1*6fcafd02SGreg Roach<?php 2*6fcafd02SGreg Roach 3*6fcafd02SGreg Roach/** 4*6fcafd02SGreg Roach * webtrees: online genealogy 5*6fcafd02SGreg Roach * Copyright (C) 2021 webtrees development team 6*6fcafd02SGreg Roach * This program is free software: you can redistribute it and/or modify 7*6fcafd02SGreg Roach * it under the terms of the GNU General Public License as published by 8*6fcafd02SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*6fcafd02SGreg Roach * (at your option) any later version. 10*6fcafd02SGreg Roach * This program is distributed in the hope that it will be useful, 11*6fcafd02SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6fcafd02SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6fcafd02SGreg Roach * GNU General Public License for more details. 14*6fcafd02SGreg Roach * You should have received a copy of the GNU General Public License 15*6fcafd02SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16*6fcafd02SGreg Roach */ 17*6fcafd02SGreg Roach 18*6fcafd02SGreg Roachdeclare(strict_types=1); 19*6fcafd02SGreg Roach 20*6fcafd02SGreg Roachnamespace Fisharebest\Webtrees; 21*6fcafd02SGreg Roach 22*6fcafd02SGreg Roachuse Fisharebest\Webtrees\Factories\FamilyFactory; 23*6fcafd02SGreg Roachuse Fisharebest\Webtrees\Factories\IndividualFactory; 24*6fcafd02SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates; 25*6fcafd02SGreg Roachuse Fisharebest\Webtrees\Services\RelationshipService; 26*6fcafd02SGreg Roach 27*6fcafd02SGreg Roach/** 28*6fcafd02SGreg Roach * Test the user functions 29*6fcafd02SGreg Roach * 30*6fcafd02SGreg Roach * @covers \Fisharebest\Webtrees\Relationship 31*6fcafd02SGreg Roach * @covers \Fisharebest\Webtrees\Services\RelationshipService 32*6fcafd02SGreg Roach * @covers \Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain 33*6fcafd02SGreg Roach * @covers \Fisharebest\Webtrees\Module\LanguageModuleTrait 34*6fcafd02SGreg Roach */ 35*6fcafd02SGreg Roachclass RelationshipNamesTest extends TestCase 36*6fcafd02SGreg Roach{ 37*6fcafd02SGreg Roach /** 38*6fcafd02SGreg Roach * @return void 39*6fcafd02SGreg Roach */ 40*6fcafd02SGreg Roach public function testRelationshipNames(): void 41*6fcafd02SGreg Roach { 42*6fcafd02SGreg Roach // i22m===f10===i23f 43*6fcafd02SGreg Roach // | 44*6fcafd02SGreg Roach // +-----+-----+ 45*6fcafd02SGreg Roach // | 46*6fcafd02SGreg Roach // i20m===f9===i21f 47*6fcafd02SGreg Roach // | 48*6fcafd02SGreg Roach // i19f===f8===i18m 49*6fcafd02SGreg Roach // | 50*6fcafd02SGreg Roach // i16m===f7===i17f 51*6fcafd02SGreg Roach // | 52*6fcafd02SGreg Roach // i12f===f4m===i11m i13m===f5m===i14f 53*6fcafd02SGreg Roach // | | 54*6fcafd02SGreg Roach // i1m===f1m==========i2f===f2d===i6m 55*6fcafd02SGreg Roach // | | 56*6fcafd02SGreg Roach // +---+---+ +---+---+ 57*6fcafd02SGreg Roach // | | | | | | 58*6fcafd02SGreg Roach // i10f===f3e===i3m i4f i5u i7ma i8f i9u===f6===i15u 59*6fcafd02SGreg Roach // 60*6fcafd02SGreg Roach // Individual suffixes - m(ale), f(emale), u(nknown), a(dopted) 61*6fcafd02SGreg Roach // Family suffixes - m(arried), d(ivorced), e(ngaged) 62*6fcafd02SGreg Roach // 63*6fcafd02SGreg Roach $tree = $this->createMock(Tree::class); 64*6fcafd02SGreg Roach 65*6fcafd02SGreg Roach $individual_factory = $this->createStub(IndividualFactory::class); 66*6fcafd02SGreg Roach $family_factory = $this->createStub(FamilyFactory::class); 67*6fcafd02SGreg Roach 68*6fcafd02SGreg Roach Registry::familyFactory($family_factory); 69*6fcafd02SGreg Roach Registry::individualFactory($individual_factory); 70*6fcafd02SGreg Roach 71*6fcafd02SGreg Roach $i1m = new Individual('i1m', "0 @i1m@ INDI\n1 SEX M\n1 FAMS @f1m@\n1 FAMC @f4m@", null, $tree); 72*6fcafd02SGreg Roach $i2f = new Individual('i2f', "0 @i2f@ INDI\n1 SEX F\n1 FAMS @f1m@\n1 FAMS @f2d@\n2 FAMC @f5m@", null, $tree); 73*6fcafd02SGreg Roach $i3m = new Individual('i3m', "0 @i3m@ INDI\n1 SEX M\n1 FAMC @f1m@\n1 FAMS @f3e@\n1 BIRT\n2 DATE 2000", null, $tree); 74*6fcafd02SGreg Roach $i4f = new Individual('i4f', "0 @i4f@ INDI\n1 SEX F\n1 FAMC @f1m@\n1 BIRT\n2 DATE 2001", null, $tree); 75*6fcafd02SGreg Roach $i5u = new Individual('i5u', "0 @i5u@ INDI\n1 SEX U\n1 FAMC @f1m@\n1 BIRT\n2 DATE 2002", null, $tree); 76*6fcafd02SGreg Roach $i6m = new Individual('i6m', "0 @i6m@ INDI\n1 SEX M\n1 FAMS @f2d@", null, $tree); 77*6fcafd02SGreg Roach $i7ma = new Individual('i7ma', "0 @i7ma@ INDI\n1 SEX M\n1 FAMC @f2d@\n2 PEDI adopted", null, $tree); 78*6fcafd02SGreg Roach $i8f = new Individual('i8f', "0 @i8f@ INDI\n1 SEX F\n1 FAMC @f2d@", null, $tree); 79*6fcafd02SGreg Roach $i9u = new Individual('i9u', "0 @i9u@ INDI\n1 SEX U\n1 FAMC @f2d@\n1 FAMS @f6@", null, $tree); 80*6fcafd02SGreg Roach $i10f = new Individual('i10f', "0 @i10f@ INDI\n1 SEX F\n1 FAMS @f3e@", null, $tree); 81*6fcafd02SGreg Roach $i11m = new Individual('i11m', "0 @i11f@ INDI\n1 SEX M\n1 FAMS @f4m@\n1 FAMC @f7@", null, $tree); 82*6fcafd02SGreg Roach $i12f = new Individual('i12f', "0 @i12f@ INDI\n1 SEX F\n1 FAMS @f4m@", null, $tree); 83*6fcafd02SGreg Roach $i13m = new Individual('i13m', "0 @i13f@ INDI\n1 SEX M\n1 FAMS @f5m@", null, $tree); 84*6fcafd02SGreg Roach $i14f = new Individual('i14f', "0 @i14f@ INDI\n1 SEX F\n1 FAMS @f5m@", null, $tree); 85*6fcafd02SGreg Roach $i15u = new Individual('i15u', "0 @i15u@ INDI\n1 SEX U\n1 FAMS @f6@", null, $tree); 86*6fcafd02SGreg Roach $i16m = new Individual('i16m', "0 @i16m@ INDI\n1 SEX M\n1 FAMS @f7@", null, $tree); 87*6fcafd02SGreg Roach $i17f = new Individual('i17f', "0 @i17f@ INDI\n1 SEX F\n1 FAMS @f7@\n1 FAMC @f8@", null, $tree); 88*6fcafd02SGreg Roach $i18m = new Individual('i18m', "0 @i18m@ INDI\n1 SEX M\n1 FAMS @f8@\n1 FAMC @f9@", null, $tree); 89*6fcafd02SGreg Roach $i19f = new Individual('i19f', "0 @i19f@ INDI\n1 SEX F\n1 FAMS @f8@", null, $tree); 90*6fcafd02SGreg Roach $i20m = new Individual('i20m', "0 @i20m@ INDI\n1 SEX M\n1 FAMS @f9@", null, $tree); 91*6fcafd02SGreg Roach $i21f = new Individual('i21f', "0 @i21f@ INDI\n1 SEX F\n1 FAMS @f9@\n1 FAMC @f10@", null, $tree); 92*6fcafd02SGreg Roach $i22m = new Individual('i22m', "0 @i22m@ INDI\n1 SEX M\n1 FAMS @f10@", null, $tree); 93*6fcafd02SGreg Roach $i23f = new Individual('i23f', "0 @i23f@ INDI\n1 SEX F\n1 FAMS @f10@", null, $tree); 94*6fcafd02SGreg Roach 95*6fcafd02SGreg Roach $individual_factory->method('make')->will($this->returnValueMap([ 96*6fcafd02SGreg Roach 'i1m' => $i1m, 97*6fcafd02SGreg Roach 'i2f' => $i2f, 98*6fcafd02SGreg Roach 'i3m' => $i3m, 99*6fcafd02SGreg Roach 'i4f' => $i4f, 100*6fcafd02SGreg Roach 'i5u' => $i5u, 101*6fcafd02SGreg Roach 'i6m' => $i6m, 102*6fcafd02SGreg Roach 'i7ma' => $i7ma, 103*6fcafd02SGreg Roach 'i8f' => $i8f, 104*6fcafd02SGreg Roach 'i9u' => $i9u, 105*6fcafd02SGreg Roach 'i10f' => $i10f, 106*6fcafd02SGreg Roach 'i11m' => $i11m, 107*6fcafd02SGreg Roach 'i12f' => $i12f, 108*6fcafd02SGreg Roach 'i13m' => $i13m, 109*6fcafd02SGreg Roach 'i14f' => $i14f, 110*6fcafd02SGreg Roach 'i15u' => $i15u, 111*6fcafd02SGreg Roach 'i16m' => $i16m, 112*6fcafd02SGreg Roach 'i17f' => $i17f, 113*6fcafd02SGreg Roach 'i18m' => $i18m, 114*6fcafd02SGreg Roach 'i19f' => $i19f, 115*6fcafd02SGreg Roach 'i20m' => $i20m, 116*6fcafd02SGreg Roach 'i21f' => $i21f, 117*6fcafd02SGreg Roach ])); 118*6fcafd02SGreg Roach 119*6fcafd02SGreg Roach $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*6fcafd02SGreg Roach $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*6fcafd02SGreg Roach $f3e = new Family('f3e', "0 @f3e@ FAM\n1 ENGA Y\n1 HUSB @i3m@\n1 WIFE @i10f@", null, $tree); 122*6fcafd02SGreg Roach $f4m = new Family('f4m', "0 @f4m@ FAM\n1 MARR Y\n1 HUSB @i11m@\n1 WIFE @i12f@\n1 CHIL @i1m@", null, $tree); 123*6fcafd02SGreg Roach $f5m = new Family('f5m', "0 @f5m@ FAM\n1 MARR Y\n1 HUSB @i13m@\n1 WIFE @i14f@\n1 CHIL @i2f@", null, $tree); 124*6fcafd02SGreg Roach $f6 = new Family('f6', "0 @f6@ FAM\n1 HUSB @i9u@\n1 WIFE @i15u@", null, $tree); 125*6fcafd02SGreg Roach $f7 = new Family('f7', "0 @f7@ FAM\n1 HUSB @i16m@\n1 WIFE @i17f@\n1 CHIL @i11m@", null, $tree); 126*6fcafd02SGreg Roach $f8 = new Family('f8', "0 @f8@ FAM\n1 HUSB @i18m@\n1 WIFE @i19f@\n1 CHIL @i17f@", null, $tree); 127*6fcafd02SGreg Roach $f9 = new Family('f9', "0 @f9@ FAM\n1 HUSB @i20m@\n1 WIFE @i21f@\n1 CHIL @i18m@", null, $tree); 128*6fcafd02SGreg Roach $f10 = new Family('f10', "0 @f10@ FAM\n1 HUSB @i22m@\n1 WIFE @i23f@\n1 CHIL @i21f@", null, $tree); 129*6fcafd02SGreg Roach 130*6fcafd02SGreg Roach $family_factory->method('make')->will($this->returnValueMap([ 131*6fcafd02SGreg Roach 'f1m' => $f1m, 132*6fcafd02SGreg Roach 'f2d' => $f2d, 133*6fcafd02SGreg Roach 'f3e' => $f3e, 134*6fcafd02SGreg Roach 'f4m' => $f4m, 135*6fcafd02SGreg Roach 'f5m' => $f5m, 136*6fcafd02SGreg Roach 'f6' => $f6, 137*6fcafd02SGreg Roach 'f7' => $f7, 138*6fcafd02SGreg Roach 'f8' => $f8, 139*6fcafd02SGreg Roach 'f9' => $f9, 140*6fcafd02SGreg Roach 'f10' => $f10, 141*6fcafd02SGreg Roach ])); 142*6fcafd02SGreg Roach 143*6fcafd02SGreg Roach $service = new RelationshipService(); 144*6fcafd02SGreg Roach 145*6fcafd02SGreg Roach // ENGLISH 146*6fcafd02SGreg Roach $en_gb = new LanguageEnglishUnitedStates(); 147*6fcafd02SGreg Roach // Static relationships 148*6fcafd02SGreg Roach self::assertSame('wife', $service->nameFromPath([$i1m, $f1m, $i2f], $en_gb)); 149*6fcafd02SGreg Roach self::assertSame('husband', $service->nameFromPath([$i2f, $f1m, $i1m], $en_gb)); 150*6fcafd02SGreg Roach self::assertSame('partner', $service->nameFromPath([$i9u, $f6, $i15u], $en_gb)); 151*6fcafd02SGreg Roach self::assertSame('ex-husband', $service->nameFromPath([$i2f, $f2d, $i6m], $en_gb)); 152*6fcafd02SGreg Roach self::assertSame('ex-wife', $service->nameFromPath([$i6m, $f2d, $i2f], $en_gb)); 153*6fcafd02SGreg Roach self::assertSame('fiancé', $service->nameFromPath([$i10f, $f3e, $i3m], $en_gb)); 154*6fcafd02SGreg Roach self::assertSame('fiancée', $service->nameFromPath([$i3m, $f3e, $i10f], $en_gb)); 155*6fcafd02SGreg Roach self::assertSame('son', $service->nameFromPath([$i1m, $f1m, $i3m], $en_gb)); 156*6fcafd02SGreg Roach self::assertSame('daughter', $service->nameFromPath([$i1m, $f1m, $i4f], $en_gb)); 157*6fcafd02SGreg Roach self::assertSame('child', $service->nameFromPath([$i1m, $f1m, $i5u], $en_gb)); 158*6fcafd02SGreg Roach self::assertSame('younger brother', $service->nameFromPath([$i4f, $f1m, $i3m], $en_gb)); 159*6fcafd02SGreg Roach self::assertSame('elder sister', $service->nameFromPath([$i3m, $f1m, $i4f], $en_gb)); 160*6fcafd02SGreg Roach self::assertSame('elder sibling', $service->nameFromPath([$i3m, $f1m, $i5u], $en_gb)); 161*6fcafd02SGreg Roach self::assertSame('brother', $service->nameFromPath([$i8f, $f2d, $i7ma], $en_gb)); 162*6fcafd02SGreg Roach self::assertSame('sister', $service->nameFromPath([$i7ma, $f2d, $i8f], $en_gb)); 163*6fcafd02SGreg Roach self::assertSame('sibling', $service->nameFromPath([$i7ma, $f2d, $i9u], $en_gb)); 164*6fcafd02SGreg Roach self::assertSame('adoptive-mother', $service->nameFromPath([$i7ma, $f2d, $i2f], $en_gb)); 165*6fcafd02SGreg Roach self::assertSame('adoptive-father', $service->nameFromPath([$i7ma, $f2d, $i6m], $en_gb)); 166*6fcafd02SGreg Roach self::assertSame('adopted-son', $service->nameFromPath([$i6m, $f2d, $i7ma], $en_gb)); 167*6fcafd02SGreg Roach self::assertSame('paternal-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m], $en_gb)); 168*6fcafd02SGreg Roach self::assertSame('paternal-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i12f], $en_gb)); 169*6fcafd02SGreg Roach self::assertSame('maternal-grandfather', $service->nameFromPath([$i3m, $f1m, $i2f, $f5m, $i13m], $en_gb)); 170*6fcafd02SGreg Roach self::assertSame('maternal-grandmother', $service->nameFromPath([$i3m, $f1m, $i2f, $f5m, $i14f], $en_gb)); 171*6fcafd02SGreg Roach // Dynamic relationships 172*6fcafd02SGreg Roach self::assertSame('paternal great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i16m], $en_gb)); 173*6fcafd02SGreg Roach self::assertSame('paternal great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f], $en_gb)); 174*6fcafd02SGreg Roach self::assertSame('paternal great-great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m], $en_gb)); 175*6fcafd02SGreg Roach self::assertSame('paternal great-great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i19f], $en_gb)); 176*6fcafd02SGreg Roach self::assertSame('paternal great-great-great-grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i20m], $en_gb)); 177*6fcafd02SGreg Roach self::assertSame('paternal great-great-great-grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f], $en_gb)); 178*6fcafd02SGreg Roach self::assertSame('paternal great ×4 grandfather', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f, $f10, $i22m], $en_gb)); 179*6fcafd02SGreg Roach self::assertSame('paternal great ×4 grandmother', $service->nameFromPath([$i3m, $f1m, $i1m, $f4m, $i11m, $f7, $i17f, $f8, $i18m, $f9, $i21f, $f10, $i23f], $en_gb)); 180*6fcafd02SGreg Roach // Compound relationships 181*6fcafd02SGreg Roach self::assertSame('wife’s ex-husband', $service->nameFromPath([$i1m, $f1m, $i2f, $f2d, $i6m], $en_gb)); 182*6fcafd02SGreg Roach 183*6fcafd02SGreg Roach // SLOVAK 184*6fcafd02SGreg Roach } 185*6fcafd02SGreg Roach} 186