. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Place; use Fisharebest\Webtrees\TestCase; /** * Test harness for the class CensusColumnBirthPlaceSimple */ class CensusColumnBirthPlaceSimpleTest 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\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testForeignCountry(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Westminster, London, England')); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('England', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testJustCountry(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('United States')); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testKnownState(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Maryland, United States')); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('Maryland', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testKnownStateAndTown(): void { $individual = $this->createMock(Individual::class); $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Miami, Florida, United States')); $census = $this->createMock(CensusInterface::class); $census->method('censusPlace')->willReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('Florida', $column->generate($individual, $individual)); } }