. */ 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($place): Place { $placeMock = $this->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 = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('Deutschland'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('Deutsch', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testPlaceCountry(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('Australia', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testBritish(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('British', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testEmigrated(): void { $place1 = $this->createMock(Place::class); $place1->method('gedcomName')->willReturn('United States'); $fact1 = $this->createMock(Fact::class); $fact1->method('place')->willReturn($place1); $fact1->method('date')->willReturn(new Date('1855')); $place2 = $this->createMock(Place::class); $place2->method('gedcomName')->willReturn('Australia'); $fact2 = $this->createMock(Fact::class); $fact2->method('place')->willReturn($place2); $fact2->method('date')->willReturn(new Date('1865')); $individual = $this->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 = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('England'); $census->method('censusDate')->willReturn('01 JUN 1860'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('United States', $column->generate($individual, $individual)); } }