diff options
24 files changed, 1397 insertions, 1191 deletions
diff --git a/app/Http/RequestHandlers/AddChildToFamilyPage.php b/app/Http/RequestHandlers/AddChildToFamilyPage.php index f1eb504726..ee3dc3645f 100644 --- a/app/Http/RequestHandlers/AddChildToFamilyPage.php +++ b/app/Http/RequestHandlers/AddChildToFamilyPage.php @@ -24,6 +24,7 @@ use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -62,9 +63,16 @@ class AddChildToFamilyPage implements RequestHandlerInterface // Create a dummy individual, so that we can create new/empty facts. $element = Registry::elementFactory()->make('INDI:NAME'); $dummy = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); - $facts = [ + + // Default names facts. + $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); + $names = $surname_tradition->newChildNames($family->husband(), $family->wife(), $sex); + $name_facts = array_map(fn (string $gedcom): Fact => new Fact($gedcom, $dummy, ''), $names); + + $facts = [ 'i' => [ new Fact('1 SEX ' . $sex, $dummy, ''), + ...$name_facts, new Fact('1 NAME ' . $element->default($tree), $dummy, ''), new Fact('1 BIRT', $dummy, ''), new Fact('1 DEAT', $dummy, ''), diff --git a/app/Http/RequestHandlers/AddChildToIndividualPage.php b/app/Http/RequestHandlers/AddChildToIndividualPage.php index 662d165b87..09e2fa43b5 100644 --- a/app/Http/RequestHandlers/AddChildToIndividualPage.php +++ b/app/Http/RequestHandlers/AddChildToIndividualPage.php @@ -24,11 +24,13 @@ use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use function array_map; use function assert; use function is_string; use function route; @@ -57,12 +59,31 @@ class AddChildToIndividualPage implements RequestHandlerInterface $individual = Auth::checkIndividualAccess($individual, true); // Create a dummy individual, so that we can create new/empty facts. - $element = Registry::elementFactory()->make('INDI:NAME'); - $dummy = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); - $facts = [ + $dummy = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); + + // Default names facts. + $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); + + switch ($individual->sex()) { + case 'M': + $names = $surname_tradition->newChildNames($individual, null, 'U'); + break; + + case 'F': + $names = $surname_tradition->newChildNames(null, $individual, 'U'); + break; + + default: + $names = $surname_tradition->newChildNames(null, null, 'U'); + break; + } + + $name_facts = array_map(fn (string $gedcom): Fact => new Fact($gedcom, $dummy, ''), $names); + + $facts = [ 'i' => [ new Fact('1 SEX ', $dummy, ''), - new Fact('1 NAME ' . $element->default($tree), $dummy, ''), + ...$name_facts, new Fact('1 BIRT', $dummy, ''), new Fact('1 DEAT', $dummy, ''), ], diff --git a/app/Http/RequestHandlers/AddParentToIndividualPage.php b/app/Http/RequestHandlers/AddParentToIndividualPage.php index d44f29ebea..9b8e6d4f28 100644 --- a/app/Http/RequestHandlers/AddParentToIndividualPage.php +++ b/app/Http/RequestHandlers/AddParentToIndividualPage.php @@ -24,11 +24,13 @@ use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use function array_map; use function assert; use function is_string; use function route; @@ -60,12 +62,17 @@ class AddParentToIndividualPage implements RequestHandlerInterface $individual = Auth::checkIndividualAccess($individual, true); // Create a dummy individual, so that we can create new/empty facts. - $element = Registry::elementFactory()->make('INDI:NAME'); $dummy = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); + + // Default names facts. + $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); + $names = $surname_tradition->newParentNames($individual, $sex); + $name_facts = array_map(fn (string $gedcom): Fact => new Fact($gedcom, $dummy, ''), $names); + $facts = [ 'i' => [ new Fact('1 SEX ' . $sex, $dummy, ''), - new Fact('1 NAME ' . $element->default($tree), $dummy, ''), + ...$name_facts, new Fact('1 BIRT', $dummy, ''), new Fact('1 DEAT', $dummy, ''), ], diff --git a/app/Http/RequestHandlers/AddSpouseToFamilyPage.php b/app/Http/RequestHandlers/AddSpouseToFamilyPage.php index 9086fa6e69..9442e3119e 100644 --- a/app/Http/RequestHandlers/AddSpouseToFamilyPage.php +++ b/app/Http/RequestHandlers/AddSpouseToFamilyPage.php @@ -23,12 +23,15 @@ use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use function array_map; use function assert; use function is_string; use function route; @@ -63,10 +66,18 @@ class AddSpouseToFamilyPage implements RequestHandlerInterface $element = Registry::elementFactory()->make('INDI:NAME'); $dummyi = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); $dummyf = Registry::familyFactory()->new('', '0 @@ FAM', null, $tree); - $facts = [ + + // Default names facts. + $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); + $spouse = $family->spouses()->first(); + assert($spouse instanceof Individual); + $names = $surname_tradition->newSpouseNames($spouse, $sex); + $name_facts = array_map(fn (string $gedcom): Fact => new Fact($gedcom, $dummyi, ''), $names); + + $facts = [ 'i' => [ new Fact('1 SEX ' . $sex, $dummyi, ''), - new Fact('1 NAME ' . $element->default($tree), $dummyi, ''), + ...$name_facts, new Fact('1 BIRT', $dummyi, ''), new Fact('1 DEAT', $dummyi, ''), ], diff --git a/app/Http/RequestHandlers/AddSpouseToIndividualPage.php b/app/Http/RequestHandlers/AddSpouseToIndividualPage.php index 09ecedfa6a..80d61b5907 100644 --- a/app/Http/RequestHandlers/AddSpouseToIndividualPage.php +++ b/app/Http/RequestHandlers/AddSpouseToIndividualPage.php @@ -24,11 +24,13 @@ use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use function array_map; use function assert; use function is_string; use function route; @@ -64,13 +66,18 @@ class AddSpouseToIndividualPage implements RequestHandlerInterface // Create a dummy individual, so that we can create new/empty facts. $sex = self::OPPOSITE_SEX[$individual->sex()] ?? 'U'; - $element = Registry::elementFactory()->make('INDI:NAME'); $dummyi = Registry::individualFactory()->new('', '0 @@ INDI', null, $tree); $dummyf = Registry::familyFactory()->new('', '0 @@ FAM', null, $tree); + + // Default names facts. + $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); + $names = $surname_tradition->newSpouseNames($individual, $sex); + $name_facts = array_map(fn (string $gedcom): Fact => new Fact($gedcom, $dummyi, ''), $names); + $facts = [ 'i' => [ new Fact('1 SEX ' . $sex, $dummyi, ''), - new Fact('1 NAME ' . $element->default($tree), $dummyi, ''), + ...$name_facts, new Fact('1 BIRT', $dummyi, ''), new Fact('1 DEAT', $dummyi, ''), ], diff --git a/app/SurnameTradition/DefaultSurnameTradition.php b/app/SurnameTradition/DefaultSurnameTradition.php index 01e10a0696..a812f8a752 100644 --- a/app/SurnameTradition/DefaultSurnameTradition.php +++ b/app/SurnameTradition/DefaultSurnameTradition.php @@ -19,6 +19,15 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; + +use function array_filter; +use function array_keys; +use function array_map; +use function implode; +use function in_array; + /** * All family members keep their original surname */ @@ -57,48 +66,95 @@ class DefaultSurnameTradition implements SurnameTraditionInterface } /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } + + /** + * Build a GEDCOM name record + * + * @param string $name + * @param array<string,string> $parts + * + * @return string + */ + protected function buildName(string $name, array $parts): string + { + $parts = array_filter($parts); + + $parts = array_map( + fn (string $tag, string $value): string => "\n2 " . $tag . ' ' . $value, + array_keys($parts), + $parts + ); + + if ($name === '') { + return '1 NAME' . implode($parts); + } + + return '1 NAME ' . $name . implode($parts); + } + + /** + * Extract an individual's name. + * + * @param Individual|null $individual + * + * @return string + */ + protected function extractName(?Individual $individual): string + { + if ($individual instanceof Individual) { + $fact = $individual + ->facts(['NAME']) + ->first(fn (Fact $fact): bool => in_array($fact->attribute('TYPE'), ['', 'birth', 'change'], true)); + + if ($fact instanceof Fact) { + return $fact->value(); + } + } + + return ''; + } } diff --git a/app/SurnameTradition/IcelandicSurnameTradition.php b/app/SurnameTradition/IcelandicSurnameTradition.php index 6b02b46ea9..ffe3b2aaa1 100644 --- a/app/SurnameTradition/IcelandicSurnameTradition.php +++ b/app/SurnameTradition/IcelandicSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take a patronym instead of a surname. * @@ -38,62 +40,78 @@ class IcelandicSurnameTradition extends DefaultSurnameTradition } /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) { - switch ($child_sex) { + if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) { + switch ($sex) { case 'M': + $givn = $match['GIVN'] . 'sson'; + return [ - 'NAME' => $father_match['GIVN'] . 'sson', + $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]), ]; + case 'F': + $givn = $match['GIVN'] . 'sdottir'; + return [ - 'NAME' => $father_match['GIVN'] . 'sdottir', + $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]), ]; } } - return []; + return [ + $this->buildName('', ['TYPE' => 'birth']), + ]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) { + if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) { + return [ + $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]), + ]; + } + + if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) { return [ - 'NAME' => $child_match['GIVN'], - 'GIVN' => $child_match['GIVN'], + $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]), ]; } - return []; + return [ + $this->buildName('', ['TYPE' => 'birth']), + ]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { - return []; + return [ + $this->buildName('', ['TYPE' => 'birth']), + ]; } } diff --git a/app/SurnameTradition/LithuanianSurnameTradition.php b/app/SurnameTradition/LithuanianSurnameTradition.php index ebecd52b31..fb01920a89 100644 --- a/app/SurnameTradition/LithuanianSurnameTradition.php +++ b/app/SurnameTradition/LithuanianSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Lithuanian — Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex and marital status. */ @@ -51,76 +53,81 @@ class LithuanianSurnameTradition extends PaternalSurnameTradition ]; /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURN, $father_name, $match)) { - if ($child_sex === 'F') { - return array_filter([ - 'NAME' => $this->inflect($match['NAME'], self::INFLECT_DAUGHTER), - 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), - ]); + if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { + if ($sex === 'F') { + $name = $this->inflect($match['NAME'], self::INFLECT_DAUGHTER); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + } else { + $name = $match['NAME']; + $surn = $match['SURN']; } - return array_filter([ - 'NAME' => $match['NAME'], - 'SURN' => $match['SURN'], - ]); + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]), + ]; } return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { - return array_filter([ - 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), - 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), - ]); + if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { + $name = $this->inflect($match['NAME'], self::INFLECT_MALE); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]), + ]; } return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { - if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { + $name = $this->inflect($match['NAME'], self::INFLECT_WIFE); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + return [ - 'NAME' => '//', - '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_WIFE), + $this->buildName('//', ['TYPE' => 'birth']), + $this->buildName($name, ['TYPE' => 'married', 'SURN' => $surn]), ]; } return [ - 'NAME' => '//', + $this->buildName('//', ['TYPE' => 'birth']), ]; } } diff --git a/app/SurnameTradition/MatrilinealSurnameTradition.php b/app/SurnameTradition/MatrilinealSurnameTradition.php index 3f69957dce..7737facb94 100644 --- a/app/SurnameTradition/MatrilinealSurnameTradition.php +++ b/app/SurnameTradition/MatrilinealSurnameTradition.php @@ -19,55 +19,57 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take their mother’s surname. */ class MatrilinealSurnameTradition extends DefaultSurnameTradition { /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SPFX_SURN, $mother_name, $match)) { - return array_filter([ - 'NAME' => $match['NAME'], - 'SPFX' => $match['SPFX'], - 'SURN' => $match['SURN'], - ]); + if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return parent::newChildNames($father, $mother, $sex); } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if ($parent_sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) { - return array_filter([ - 'NAME' => $match['NAME'], - 'SPFX' => $match['SPFX'], - 'SURN' => $match['SURN'], - ]); + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return parent::newParentNames($child, $sex); } } diff --git a/app/SurnameTradition/PaternalSurnameTradition.php b/app/SurnameTradition/PaternalSurnameTradition.php index 232d96eaf5..a1297ce199 100644 --- a/app/SurnameTradition/PaternalSurnameTradition.php +++ b/app/SurnameTradition/PaternalSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take their father’s surname. Wives take their husband’s surname. */ @@ -35,55 +37,50 @@ class PaternalSurnameTradition extends PatrilinealSurnameTradition } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if (preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) { - switch ($parent_sex) { - case 'M': - return array_filter([ - 'NAME' => $match['NAME'], - 'SPFX' => $match['SPFX'], - 'SURN' => $match['SURN'], - ]); - case 'F': - return [ - 'NAME' => '//', - '_MARNM' => '/' . trim($match['SPFX'] . ' ' . $match['SURN']) . '/', - ]; - } + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + + return [ + $this->buildName('//', ['TYPE' => 'birth']), + $this->buildName($name, ['TYPE' => 'married', 'SPFX' => $spfx, 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return parent::newParentNames($child, $sex); } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { - if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($spouse), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + return [ - 'NAME' => '//', - '_MARNM' => $match['NAME'], + $this->buildName('//', ['TYPE' => 'birth']), + $this->buildName($name, ['TYPE' => 'married', 'SPFX' => $spfx, 'SURN' => $surn]), ]; } - return [ - 'NAME' => '//', - ]; + return parent::newSpouseNames($spouse, $sex); } } diff --git a/app/SurnameTradition/PatrilinealSurnameTradition.php b/app/SurnameTradition/PatrilinealSurnameTradition.php index 0eebd0f556..5f436e747b 100644 --- a/app/SurnameTradition/PatrilinealSurnameTradition.php +++ b/app/SurnameTradition/PatrilinealSurnameTradition.php @@ -19,56 +19,58 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take their father’s surname. */ class PatrilinealSurnameTradition extends DefaultSurnameTradition { /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SPFX_SURN, $father_name, $match)) { - return array_filter([ - 'NAME' => $match['NAME'], - 'SPFX' => $match['SPFX'], - 'SURN' => $match['SURN'], - ]); + if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($father), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return parent::newChildNames($father, $mother, $sex); } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if ($parent_sex === 'M' && preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) { - return array_filter([ - 'NAME' => $match['NAME'], - 'SPFX' => $match['SPFX'], - 'SURN' => $match['SURN'], - ]); + if ($sex === 'M' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + $name = $match['NAME']; + $spfx = $match['SPFX']; + $surn = $match['SURN']; + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return parent::newParentNames($child, $sex); } /** diff --git a/app/SurnameTradition/PolishSurnameTradition.php b/app/SurnameTradition/PolishSurnameTradition.php index e48224e7cc..ffcd211ce1 100644 --- a/app/SurnameTradition/PolishSurnameTradition.php +++ b/app/SurnameTradition/PolishSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. */ @@ -41,76 +43,73 @@ class PolishSurnameTradition extends PaternalSurnameTradition ]; /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURN, $father_name, $match)) { - if ($child_sex === 'F') { - return array_filter([ - 'NAME' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), - 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), - ]); + if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { + if ($sex === 'F') { + $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); + } else { + $name = $this->inflect($match['NAME'], self::INFLECT_MALE); } - return array_filter([ - 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), - 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), - ]); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + + return [$this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn])]; } - return [ - 'NAME' => '//', - ]; + return [$this->buildName('//', ['TYPE' => 'birth'])]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { - return array_filter([ - 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), - 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), - ]); + if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { + $name = $this->inflect($match['NAME'], self::INFLECT_MALE); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + + return [ + $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]), + ]; } - return [ - 'NAME' => '//', - ]; + return [$this->buildName('//', ['TYPE' => 'birth'])]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { - if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { + $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); + $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); + return [ - 'NAME' => '//', - '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), + $this->buildName('//', ['TYPE' => 'birth']), + $this->buildName($name, ['TYPE' => 'married', 'SURN' => $surn]), ]; } - return [ - 'NAME' => '//', - ]; + return [$this->buildName('//', ['TYPE' => 'birth'])]; } } diff --git a/app/SurnameTradition/PortugueseSurnameTradition.php b/app/SurnameTradition/PortugueseSurnameTradition.php index ebc40f8d33..f78a428ff0 100644 --- a/app/SurnameTradition/PortugueseSurnameTradition.php +++ b/app/SurnameTradition/PortugueseSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take one surname from the mother and one surname from the father. * @@ -29,76 +31,83 @@ namespace Fisharebest\Webtrees\SurnameTradition; class PortugueseSurnameTradition extends DefaultSurnameTradition { /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { $father_surname = $match_father['SURN2']; } else { $father_surname = ''; } - if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { $mother_surname = $match_mother['SURN2']; } else { $mother_surname = ''; } return [ - 'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/', - 'SURN' => trim($father_surname . ',' . $mother_surname, ','), + $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [ + 'TYPE' => 'birth', + 'SURN' => trim($father_surname . ',' . $mother_surname, ','), + ]), ]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if (preg_match(self::REGEX_SURNS, $child_name, $match)) { - switch ($parent_sex) { + if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { + switch ($sex) { case 'M': return [ - 'NAME' => '// /' . $match['SURN1'] . '/', - 'SURN' => $match['SURN1'], + $this->buildName('// /' . $match['SURN1'] . '/', [ + 'TYPE' => 'birth', + 'SURN' => $match['SURN1'], + ]), ]; + case 'F': return [ - 'NAME' => '// /' . $match['SURN2'] . '/', - 'SURN' => $match['SURN2'], + $this->buildName('// /' . $match['SURN2'] . '/', [ + 'TYPE' => 'birth', + 'SURN' => $match['SURN2'], + ]), ]; } } return [ - 'NAME' => '// //', + $this->buildName('// //', ['TYPE' => 'birth']), ]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { return [ - 'NAME' => '// //', + $this->buildName('// //', ['TYPE' => 'birth']), ]; } } diff --git a/app/SurnameTradition/SpanishSurnameTradition.php b/app/SurnameTradition/SpanishSurnameTradition.php index b732cde395..81780b2533 100644 --- a/app/SurnameTradition/SpanishSurnameTradition.php +++ b/app/SurnameTradition/SpanishSurnameTradition.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Children take one surname from the father and one surname from the mother. * @@ -29,76 +31,83 @@ namespace Fisharebest\Webtrees\SurnameTradition; class SpanishSurnameTradition extends DefaultSurnameTradition { /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { $father_surname = $match_father['SURN1']; } else { $father_surname = ''; } - if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { $mother_surname = $match_mother['SURN1']; } else { $mother_surname = ''; } return [ - 'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/', - 'SURN' => trim($father_surname . ',' . $mother_surname, ','), + $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [ + 'TYPE' => 'birth', + 'SURN' => trim($father_surname . ',' . $mother_surname, ','), + ]), ]; } /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array + public function newParentNames(Individual $child, string $sex): array { - if (preg_match(self::REGEX_SURNS, $child_name, $match)) { - switch ($parent_sex) { + if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { + switch ($sex) { case 'M': return [ - 'NAME' => '/' . $match['SURN1'] . '/ //', - 'SURN' => $match['SURN1'], + $this->buildName('/' . $match['SURN1'] . '/ //', [ + 'TYPE' => 'birth', + 'SURN' => $match['SURN1'], + ]), ]; + case 'F': return [ - 'NAME' => '/' . $match['SURN2'] . '/ //', - 'SURN' => $match['SURN2'], + $this->buildName('/' . $match['SURN2'] . '/ //', [ + 'TYPE' => 'birth', + 'SURN' => $match['SURN2'], + ]), ]; } } return [ - 'NAME' => '// //', + $this->buildName('// //', ['TYPE' => 'birth']), ]; } /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array + public function newSpouseNames(Individual $spouse, string $sex): array { return [ - 'NAME' => '// //', + $this->buildName('// //', ['TYPE' => 'birth']), ]; } } diff --git a/app/SurnameTradition/SurnameTraditionInterface.php b/app/SurnameTradition/SurnameTraditionInterface.php index 92a9ef6191..a36647b05e 100644 --- a/app/SurnameTradition/SurnameTraditionInterface.php +++ b/app/SurnameTradition/SurnameTraditionInterface.php @@ -19,6 +19,8 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Individual; + /** * Various cultures have different traditions for the use of surnames within families. * By providing defaults for new individuals, we can speed up data entry and reduce errors. @@ -40,33 +42,33 @@ interface SurnameTraditionInterface public function hasSurnames(): bool; /** - * What names are given to a new child + * What name is given to a new child * - * @param string $father_name A GEDCOM NAME - * @param string $mother_name A GEDCOM NAME - * @param string $child_sex M, F or U + * @param Individual|null $father + * @param Individual|null $mother + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newChildNames(string $father_name, string $mother_name, string $child_sex): array; + public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array; /** - * What names are given to a new parent + * What name is given to a new parent * - * @param string $child_name A GEDCOM NAME - * @param string $parent_sex M, F or U + * @param Individual $child + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newParentNames(string $child_name, string $parent_sex): array; + public function newParentNames(Individual $child, string $sex): array; /** * What names are given to a new spouse * - * @param string $spouse_name A GEDCOM NAME - * @param string $spouse_sex M, F or U + * @param Individual $spouse + * @param string $sex * - * @return array<string,string> Associative array of GEDCOM name parts (SURN, _MARNM, etc.) + * @return array<string> */ - public function newSpouseNames(string $spouse_name, string $spouse_sex): array; + public function newSpouseNames(Individual $spouse, string $sex): array; } diff --git a/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php b/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php index 00cc5f1bbc..3ea605107c 100644 --- a/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class DefaultSurnameTradition @@ -29,18 +32,6 @@ class DefaultSurnameTraditionTest extends TestCase private SurnameTraditionInterface $surname_tradition; /** - * Prepare the environment for these tests - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->surname_tradition = new DefaultSurnameTradition(); - } - - /** * Test whether married surnames are used * * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition @@ -65,137 +56,113 @@ class DefaultSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } /** - * Test new father names + * Test new parent names * * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition * * @return void */ - public function testNewFatherNames(): void + public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'M') ); - } - /** - * Test new mother names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition - * - * @return void - */ - public function testNewMotherNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'F') ); - } - /** - * Test new parent names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition - * - * @return void - */ - public function testNewParentNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') + ); + + self::assertSame( + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition + * Prepare the environment for these tests * * @return void */ - public function testNewSpouseNames(): void + protected function setUp(): void { - self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') - ); + parent::setUp(); + + $this->surname_tradition = new DefaultSurnameTradition(); } } diff --git a/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php b/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php index b42375899f..9b5ee9141e 100644 --- a/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class IcelandicSurnameTradition @@ -29,18 +32,6 @@ class IcelandicSurnameTraditionTest extends TestCase private SurnameTraditionInterface $surname_tradition; /** - * Prepare the environment for these tests - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->surname_tradition = new IcelandicSurnameTradition(); - } - - /** * Test whether married surnames are used * * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition @@ -73,9 +64,21 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewSonNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - ['NAME' => 'Jonsson'], - $this->surname_tradition->newChildNames('Jon Einarsson', 'Eva Stefansdottir', 'M') + ["1 NAME Jonsson\n2 TYPE birth\n2 GIVN Jonsson"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); } @@ -88,9 +91,21 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewDaughterNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - ['NAME' => 'Jonsdottir'], - $this->surname_tradition->newChildNames('Jon Einarsson', 'Eva Stefansdottir', 'F') + ["1 NAME Jonsdottir\n2 TYPE birth\n2 GIVN Jonsdottir"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); } @@ -103,9 +118,21 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [], - $this->surname_tradition->newChildNames('Jon Einarsson', 'Eva Stefansdottir', 'U') + ["1 NAME\n2 TYPE birth"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -118,12 +145,15 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewFatherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => 'Einar', - 'GIVN' => 'Einar', - ], - $this->surname_tradition->newParentNames('Jon Einarsson', 'M') + ["1 NAME Einar\n2 TYPE birth\n2 GIVN Einar"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -136,9 +166,15 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewMotherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Jon Evasdottir'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [], - $this->surname_tradition->newParentNames('Jon Einarsson', 'F') + ["1 NAME Eva\n2 TYPE birth\n2 GIVN Eva"], + $this->surname_tradition->newParentNames($individual, 'F') ); } @@ -151,54 +187,58 @@ class IcelandicSurnameTraditionTest extends TestCase */ public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [], - $this->surname_tradition->newParentNames('Jon Einarsson', 'U') + ["1 NAME\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [], - $this->surname_tradition->newSpouseNames('Eva Stefansdottir', 'M') + ["1 NAME\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - [], - $this->surname_tradition->newSpouseNames('Jon Einarsson', 'F') + ["1 NAME\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') + ); + + self::assertSame( + ["1 NAME\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition + * Prepare the environment for these tests * * @return void */ - public function testNewSpouseNames(): void + protected function setUp(): void { - self::assertSame( - [], - $this->surname_tradition->newSpouseNames('Jon Einarsson', 'U') - ); + parent::setUp(); + + $this->surname_tradition = new IcelandicSurnameTradition(); } } diff --git a/tests/app/SurnameTradition/LithuanianSurnameTraditionTest.php b/tests/app/SurnameTradition/LithuanianSurnameTraditionTest.php index 41acceda7e..f229eba96d 100644 --- a/tests/app/SurnameTradition/LithuanianSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/LithuanianSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class LithuanianSurnameTraditionTest @@ -76,12 +79,21 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewSonNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); } @@ -95,12 +107,21 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewDaughterNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); } @@ -114,47 +135,76 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewDaughterNamesInflected(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whita/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Whitaitė/', - 'SURN' => 'Whita', - ], - $this->surname_tradition->newChildNames('John /Whita/', 'Mary /Black/', 'F') + ["1 NAME /Whitaitė/\n2 TYPE birth\n2 SURN Whita"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitas/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + self::assertSame( - [ - 'NAME' => '/Whitaitė/', - 'SURN' => 'Whitas', - ], - $this->surname_tradition->newChildNames('John /Whitas/', 'Mary /Black/', 'F') + ["1 NAME /Whitaitė/\n2 TYPE birth\n2 SURN Whitas"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitis/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + self::assertSame( - [ - 'NAME' => '/Whitytė/', - 'SURN' => 'Whitis', - ], - $this->surname_tradition->newChildNames('John /Whitis/', 'Mary /Black/', 'F') + ["1 NAME /Whitytė/\n2 TYPE birth\n2 SURN Whitis"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitys/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + self::assertSame( - [ - 'NAME' => '/Whitytė/', - 'SURN' => 'Whitys', - ], - $this->surname_tradition->newChildNames('John /Whitys/', 'Mary /Black/', 'F') + ["1 NAME /Whitytė/\n2 TYPE birth\n2 SURN Whitys"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitius/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + self::assertSame( - [ - 'NAME' => '/Whitiūtė/', - 'SURN' => 'Whitius', - ], - $this->surname_tradition->newChildNames('John /Whitius/', 'Mary /Black/', 'F') + ["1 NAME /Whitiūtė/\n2 TYPE birth\n2 SURN Whitius"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitus/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + self::assertSame( - [ - 'NAME' => '/Whitutė/', - 'SURN' => 'Whitus', - ], - $this->surname_tradition->newChildNames('John /Whitus/', 'Mary /Black/', 'F') + ["1 NAME /Whitutė/\n2 TYPE birth\n2 SURN Whitus"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); } @@ -168,12 +218,21 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -188,8 +247,8 @@ class LithuanianSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } @@ -203,12 +262,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewFatherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -222,33 +284,48 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewFatherNamesInflected(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Mary /Whitaitė/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitas/', - 'SURN' => 'Whitas', - ], - $this->surname_tradition->newParentNames('Mary /Whitaitė/', 'M') + ["1 NAME /Whitas/\n2 TYPE birth\n2 SURN Whitas"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Mary /Whitytė/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitis/', - 'SURN' => 'Whitis', - ], - $this->surname_tradition->newParentNames('Mary /Whitytė/', 'M') + ["1 NAME /Whitis/\n2 TYPE birth\n2 SURN Whitis"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Mary /Whitiūtė/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitius/', - 'SURN' => 'Whitius', - ], - $this->surname_tradition->newParentNames('Mary /Whitiūtė/', 'M') + ["1 NAME /Whitius/\n2 TYPE birth\n2 SURN Whitius"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Mary /Whitutė/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitus/', - 'SURN' => 'Whitus', - ], - $this->surname_tradition->newParentNames('Mary /Whitutė/', 'M') + ["1 NAME /Whitus/\n2 TYPE birth\n2 SURN Whitus"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -262,9 +339,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewMotherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'F') ); } @@ -278,9 +361,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } @@ -294,9 +383,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewHusbandNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); } @@ -310,12 +405,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewWifeNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '//', - '_MARNM' => '/White/', - ], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); } @@ -329,9 +427,15 @@ class LithuanianSurnameTraditionTest extends TestCase */ public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } } diff --git a/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php b/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php index 91bbb92c44..0ec0e67ef7 100644 --- a/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class MatrilinenalSurnameTradition @@ -65,56 +68,39 @@ class MatrilinealSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Black/', - 'SURN' => 'Black', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME /Black/\n2 TYPE birth\n2 SURN Black"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - [ - 'NAME' => '/Black/', - 'SURN' => 'Black', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME /Black/\n2 TYPE birth\n2 SURN Black"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - [ - 'NAME' => '/Black/', - 'SURN' => 'Black', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME /Black/\n2 TYPE birth\n2 SURN Black"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -127,13 +113,21 @@ class MatrilinealSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /de White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/van Black/', - 'SPFX' => 'van', - 'SURN' => 'Black', - ], - $this->surname_tradition->newChildNames('John /de White/', 'Mary /van Black/', 'U') + ["1 NAME /van Black/\n2 TYPE birth\n2 SPFX van\n2 SURN Black"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -147,101 +141,71 @@ class MatrilinealSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } /** - * Test new father names + * Test new parent names * * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition * * @return void */ - public function testNewFatherNames(): void + public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'M') ); - } - /** - * Test new mother names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewMotherNames(): void - { self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'F') ); - } - /** - * Test new parent names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewParentNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); - } - /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition - * - * @return void - */ - public function testNewSpouseNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } } diff --git a/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php b/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php index 998c8fb42a..c4efe279bc 100644 --- a/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class PaternalSurnameTradition @@ -29,18 +32,6 @@ class PaternalSurnameTraditionTest extends TestCase private SurnameTraditionInterface $surname_tradition; /** - * Prepare the environment for these tests - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->surname_tradition = new PaternalSurnameTradition(); - } - - /** * Test whether married surnames are used * * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition @@ -65,56 +56,39 @@ class PaternalSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -127,13 +101,21 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /de White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/de White/', - 'SPFX' => 'de', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /de White/', 'Mary /van Black/', 'U') + ["1 NAME /de White/\n2 TYPE birth\n2 SPFX de\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -146,13 +128,21 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithMultipleSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /van der White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/van der White/', - 'SPFX' => 'van der', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /van der White/', 'Mary /van Black/', 'U') + ["1 NAME /van der White/\n2 TYPE birth\n2 SPFX van der\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -165,21 +155,21 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithDutchSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /\'t White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/\'t White/', - 'SPFX' => '\'t', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /\'t White/', 'Mary /van Black/', 'U') - ); - self::assertSame( - [ - 'NAME' => '/’t White/', - 'SPFX' => '’t', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /’t White/', 'Mary /van Black/', 'U') + ["1 NAME /'t White/\n2 TYPE birth\n2 SPFX 't\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -192,21 +182,21 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithMultipleDutchSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /van \'t White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/van \'t White/', - 'SPFX' => 'van \'t', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /van \'t White/', 'Mary /van Black/', 'U') - ); - self::assertSame( - [ - 'NAME' => '/van ’t White/', - 'SPFX' => 'van ’t', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /van ’t White/', 'Mary /van Black/', 'U') + ["1 NAME /van 't White/\n2 TYPE birth\n2 SPFX van 't\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -219,12 +209,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewFatherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -237,12 +230,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewMotherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '//', - '_MARNM' => '/White/', - ], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'F') ); } @@ -255,9 +251,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } @@ -270,9 +272,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewHusbandNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); } @@ -285,12 +293,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewWifeNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '//', - '_MARNM' => '/White/', - ], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); } @@ -303,12 +314,15 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewWifeNamesWithSpfx(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /van der White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '//', - '_MARNM' => '/van der White/', - ], - $this->surname_tradition->newSpouseNames('John /van der White/', 'F') + ["1 NAME //\n2 TYPE birth", "1 NAME /van der White/\n2 TYPE married\n2 SPFX van der\n2 SURN White"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); } @@ -321,9 +335,27 @@ class PaternalSurnameTraditionTest extends TestCase */ public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } + + /** + * Prepare the environment for these tests + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->surname_tradition = new PaternalSurnameTradition(); + } } diff --git a/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php b/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php index f21e14b6eb..51be302986 100644 --- a/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class PatrilinenalSurnameTradition @@ -65,56 +68,39 @@ class PatrilinealSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -127,13 +113,21 @@ class PatrilinealSurnameTraditionTest extends TestCase */ public function testNewChildNamesWithSpfx(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /de White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/de White/', - 'SPFX' => 'de', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /de White/', 'Mary /van Black/', 'U') + ["1 NAME /de White/\n2 TYPE birth\n2 SPFX de\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -147,101 +141,70 @@ class PatrilinealSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } /** - * Test new father names + * Test new parent names * * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition * * @return void */ - public function testNewFatherNames(): void + public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'M') ); - } - /** - * Test new mother names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewMotherNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'F') ); - } - /** - * Test new parent names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewParentNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); - } - /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewSpouseNames(): void - { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } } diff --git a/tests/app/SurnameTradition/PolishSurnameTraditionTest.php b/tests/app/SurnameTradition/PolishSurnameTraditionTest.php index e219bdd2b8..f49b884836 100644 --- a/tests/app/SurnameTradition/PolishSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/PolishSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class PolishSurnameTradition @@ -29,18 +32,6 @@ class PolishSurnameTraditionTest extends TestCase private SurnameTraditionInterface $surname_tradition; /** - * Prepare the environment for these tests - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->surname_tradition = new PolishSurnameTradition(); - } - - /** * Test whether married surnames are used * * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition @@ -76,12 +67,21 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewSonNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); } @@ -95,12 +95,21 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewDaughterNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'F') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); } @@ -114,33 +123,72 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewDaughterNamesInflected(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitecki/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Whitecka/', - 'SURN' => 'Whitecki', - ], - $this->surname_tradition->newChildNames('John /Whitecki/', 'Mary /Black/', 'F') + ["1 NAME /Whitecka/\n2 TYPE birth\n2 SURN Whitecki"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whitedzki/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Whitedzka/', - 'SURN' => 'Whitedzki', - ], - $this->surname_tradition->newChildNames('John /Whitedzki/', 'Mary /Black/', 'F') + ["1 NAME /Whitedzka/\n2 TYPE birth\n2 SURN Whitedzki"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whiteski/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Whiteska/', - 'SURN' => 'Whiteski', - ], - $this->surname_tradition->newChildNames('John /Whiteski/', 'Mary /Black/', 'F') + ["1 NAME /Whiteska/\n2 TYPE birth\n2 SURN Whiteski"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); + + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /Whiteżki/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Whiteżka/', - 'SURN' => 'Whiteżki', - ], - $this->surname_tradition->newChildNames('John /Whiteżki/', 'Mary /Black/', 'F') + ["1 NAME /Whiteżka/\n2 TYPE birth\n2 SURN Whiteżki"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); } @@ -154,12 +202,21 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newChildNames('John /White/', 'Mary /Black/', 'U') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -174,8 +231,8 @@ class PolishSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } @@ -189,12 +246,15 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewFatherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/White/', - 'SURN' => 'White', - ], - $this->surname_tradition->newParentNames('John /White/', 'M') + ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -208,33 +268,48 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewFatherNamesInflected(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /Whitecka/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitecki/', - 'SURN' => 'Whitecki', - ], - $this->surname_tradition->newParentNames('Mary /Whitecka/', 'M') + ["1 NAME /Whitecki/\n2 TYPE birth\n2 SURN Whitecki"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /Whitedzka/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whitedzki/', - 'SURN' => 'Whitedzki', - ], - $this->surname_tradition->newParentNames('Mary /Whitedzka/', 'M') + ["1 NAME /Whitedzki/\n2 TYPE birth\n2 SURN Whitedzki"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /Whiteska/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whiteski/', - 'SURN' => 'Whiteski', - ], - $this->surname_tradition->newParentNames('Mary /Whiteska/', 'M') + ["1 NAME /Whiteski/\n2 TYPE birth\n2 SURN Whiteski"], + $this->surname_tradition->newParentNames($individual, 'M') ); + + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /Whiteżka/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Whiteżki/', - 'SURN' => 'Whiteżki', - ], - $this->surname_tradition->newParentNames('Mary /Whiteżka/', 'M') + ["1 NAME /Whiteżki/\n2 TYPE birth\n2 SURN Whiteżki"], + $this->surname_tradition->newParentNames($individual, 'M') ); } @@ -248,9 +323,15 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewMotherNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'F') ); } @@ -264,60 +345,59 @@ class PolishSurnameTraditionTest extends TestCase */ public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newParentNames('John /White/', 'U') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Mary /Black/', 'M') + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - [ - 'NAME' => '//', - '_MARNM' => '/White/', - ], - $this->surname_tradition->newSpouseNames('John /White/', 'F') + ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], + $this->surname_tradition->newSpouseNames($individual, 'F') + ); + + self::assertSame( + ["1 NAME //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition - * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition + * Prepare the environment for these tests * * @return void */ - public function testNewSpouseNames(): void + protected function setUp(): void { - self::assertSame( - ['NAME' => '//'], - $this->surname_tradition->newSpouseNames('Chris /Green/', 'U') - ); + parent::setUp(); + + $this->surname_tradition = new PolishSurnameTradition(); } } diff --git a/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php b/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php index 80d997a8c1..51d8d3752f 100644 --- a/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class PortugueseSurnameTradition @@ -65,56 +68,39 @@ class PortugueseSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Maria /Ruiz/ /Lorca/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Iglesias/ /Lorca/', - 'SURN' => 'Iglesias,Lorca', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - [ - 'NAME' => '/Iglesias/ /Lorca/', - 'SURN' => 'Iglesias,Lorca', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - [ - 'NAME' => '/Iglesias/ /Lorca/', - 'SURN' => 'Iglesias,Lorca', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -128,11 +114,8 @@ class PortugueseSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - [ - 'NAME' => '// //', - 'SURN' => '', - ], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } @@ -145,55 +128,21 @@ class PortugueseSurnameTraditionTest extends TestCase */ public function testNewChildNamesCompunds(): void { - self::assertSame( - [ - 'NAME' => '/Iglesias/ /Lorca/', - 'SURN' => 'Iglesias,Lorca', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia Iglesias/', 'Maria /Ruiz Lorca/', 'M') - ); - self::assertSame( - [ - 'NAME' => '/Iglesias/ /Lorca/', - 'SURN' => 'Iglesias,Lorca', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia y Iglesias/', 'Maria /Ruiz y Lorca/', 'M') - ); - } + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); - /** - * Test new father names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewFatherNames(): void - { - self::assertSame( - [ - 'NAME' => '// /Garcia/', - 'SURN' => 'Garcia', - ], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'M') - ); - } + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Maria /Ruiz/ y /Lorca/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); - /** - * Test new mother names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewMotherNames(): void - { self::assertSame( - [ - 'NAME' => '// /Iglesias/', - 'SURN' => 'Iglesias', - ], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'F') + ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); } @@ -206,39 +155,24 @@ class PortugueseSurnameTraditionTest extends TestCase */ public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'U') + ["1 NAME // /Garcia/\n2 TYPE birth\n2 SURN Garcia"], + $this->surname_tradition->newParentNames($individual, 'M') ); - } - - /** - * Test new husband names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewHusbandNames(): void - { self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME // /Iglesias/\n2 TYPE birth\n2 SURN Iglesias"], + $this->surname_tradition->newParentNames($individual, 'F') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Gabriel /Garcia/ /Iglesias/', 'F') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } @@ -251,9 +185,25 @@ class PortugueseSurnameTraditionTest extends TestCase */ public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + + self::assertSame( + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') + ); + + self::assertSame( + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') + ); + self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Gabriel /Garcia/ /Iglesias/', 'U') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } } diff --git a/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php b/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php index ac2f2937c0..ae867c03fa 100644 --- a/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php +++ b/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php @@ -19,7 +19,10 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; +use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\TestCase; +use Illuminate\Support\Collection; /** * Test harness for the class SpanishSurnameTradition @@ -29,18 +32,6 @@ class SpanishSurnameTraditionTest extends TestCase private SurnameTraditionInterface $surname_tradition; /** - * Prepare the environment for these tests - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->surname_tradition = new SpanishSurnameTradition(); - } - - /** * Test whether married surnames are used * * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition @@ -65,56 +56,39 @@ class SpanishSurnameTraditionTest extends TestCase } /** - * Test new son names + * Test new child names * * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition * * @return void */ - public function testNewSonNames(): void + public function testNewChildNames(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Garcia/ /Ruiz/', - 'SURN' => 'Garcia,Ruiz', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); - } - /** - * Test new daughter names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition - * - * @return void - */ - public function testNewDaughterNames(): void - { self::assertSame( - [ - 'NAME' => '/Garcia/ /Ruiz/', - 'SURN' => 'Garcia,Ruiz', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"], + $this->surname_tradition->newChildNames($father, $mother, 'F') ); - } - /** - * Test new child names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition - * - * @return void - */ - public function testNewChildNames(): void - { self::assertSame( - [ - 'NAME' => '/Garcia/ /Ruiz/', - 'SURN' => 'Garcia,Ruiz', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia/ /Iglesias/', 'Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"], + $this->surname_tradition->newChildNames($father, $mother, 'U') ); } @@ -128,11 +102,8 @@ class SpanishSurnameTraditionTest extends TestCase public function testNewChildNamesWithNoParentsNames(): void { self::assertSame( - [ - 'NAME' => '// //', - 'SURN' => '', - ], - $this->surname_tradition->newChildNames('', '', 'U') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newChildNames(null, null, 'U') ); } @@ -143,117 +114,97 @@ class SpanishSurnameTraditionTest extends TestCase * * @return void */ - public function testNewChildNamesCompunds(): void + public function testNewChildNamesCompound(): void { + $father_fact = $this->createStub(Fact::class); + $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); + + $father = $this->createStub(Individual::class); + $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); + + $mother_fact = $this->createStub(Fact::class); + $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/'); + + $mother = $this->createStub(Individual::class); + $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); + self::assertSame( - [ - 'NAME' => '/Garcia/ /Ruiz/', - 'SURN' => 'Garcia,Ruiz', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia Iglesias/', 'Maria /Ruiz Lorca/', 'M') - ); - self::assertSame( - [ - 'NAME' => '/Garcia/ /Ruiz/', - 'SURN' => 'Garcia,Ruiz', - ], - $this->surname_tradition->newChildNames('Gabriel /Garcia y Iglesias/', 'Maria /Ruiz y Lorca/', 'M') + ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"], + $this->surname_tradition->newChildNames($father, $mother, 'M') ); } /** - * Test new father names + * Test new parent names * * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition * * @return void */ - public function testNewFatherNames(): void + public function testNewParentNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - [ - 'NAME' => '/Garcia/ //', - 'SURN' => 'Garcia', - ], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'M') + ["1 NAME /Garcia/ //\n2 TYPE birth\n2 SURN Garcia"], + $this->surname_tradition->newParentNames($individual, 'M') ); - } - /** - * Test new mother names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition - * - * @return void - */ - public function testNewMotherNames(): void - { self::assertSame( - [ - 'NAME' => '/Iglesias/ //', - 'SURN' => 'Iglesias', - ], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'F') + ["1 NAME /Iglesias/ //\n2 TYPE birth\n2 SURN Iglesias"], + $this->surname_tradition->newParentNames($individual, 'F') ); - } - /** - * Test new parent names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition - * - * @return void - */ - public function testNewParentNames(): void - { self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newParentNames('Gabriel /Garcia/ /Iglesias/', 'U') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newParentNames($individual, 'U') ); } /** - * Test new husband names + * Test new spouse names * * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition * * @return void */ - public function testNewHusbandNames(): void + public function testNewSpouseNames(): void { + $fact = $this->createStub(Fact::class); + $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); + + $individual = $this->createStub(Individual::class); + $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); + self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Maria /Ruiz/ /Lorca/', 'M') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'M') + ); + + self::assertSame( + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'F') ); - } - /** - * Test new wife names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition - * - * @return void - */ - public function testNewWifeNames(): void - { self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Gabriel /Garcia/ /Iglesias/', 'F') + ["1 NAME // //\n2 TYPE birth"], + $this->surname_tradition->newSpouseNames($individual, 'U') ); } /** - * Test new spouse names - * - * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition + * Prepare the environment for these tests * * @return void */ - public function testNewSpouseNames(): void + protected function setUp(): void { - self::assertSame( - ['NAME' => '// //'], - $this->surname_tradition->newSpouseNames('Gabriel /Garcia/ /Iglesias/', 'U') - ); + parent::setUp(); + + $this->surname_tradition = new SpanishSurnameTradition(); } } |
