. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Place; use Fisharebest\Webtrees\TestCase; use Illuminate\Support\Collection; /** * Test harness for the class CensusColumnNationality */ class CensusColumnNationalityTest extends TestCase { /** * Get place mock. * * @param string $place Gedcom Place * * @return Place */ private function getPlaceMock(string $place): Place { $placeMock = self::createMock(Place::class); $placeMock->method('gedcomName')->willReturn($place); return $placeMock; } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testNoBirthPlace(): void { $individual = self::createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = self::createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('Deutschland'); $column = new CensusColumnNationality($census, '', ''); self::assertSame('Deutsch', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testPlaceCountry(): void { $individual = self::createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = self::createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $column = new CensusColumnNationality($census, '', ''); self::assertSame('Australia', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testBritish(): void { $individual = self::createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = self::createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $column = new CensusColumnNationality($census, '', ''); self::assertSame('British', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testEmigrated(): void { $place1 = self::createMock(Place::class); $place1->method('gedcomName')->willReturn('United States'); $fact1 = self::createMock(Fact::class); $fact1->method('place')->willReturn($place1); $fact1->method('date')->willReturn(new Date('1855')); $place2 = self::createMock(Place::class); $place2->method('gedcomName')->willReturn('Australia'); $fact2 = self::createMock(Fact::class); $fact2->method('place')->willReturn($place2); $fact2->method('date')->willReturn(new Date('1865')); $individual = self::createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([ $fact1, $fact2, ])); $census = self::createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $census->method('censusDate')->willReturn('01 JUN 1860'); $column = new CensusColumnNationality($census, '', ''); self::assertSame('United States', $column->generate($individual, $individual)); } }