xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision e7f56f2af615447ab1a7646851f88b465ace9e04)
17338314fSGreg Roach<?php
27338314fSGreg Roach/**
37338314fSGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
57338314fSGreg Roach * This program is free software: you can redistribute it and/or modify
67338314fSGreg Roach * it under the terms of the GNU General Public License as published by
77338314fSGreg Roach * the Free Software Foundation, either version 3 of the License, or
87338314fSGreg Roach * (at your option) any later version.
97338314fSGreg Roach * This program is distributed in the hope that it will be useful,
107338314fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
117338314fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127338314fSGreg Roach * GNU General Public License for more details.
137338314fSGreg Roach * You should have received a copy of the GNU General Public License
147338314fSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
157338314fSGreg Roach */
16*e7f56f2aSGreg Roachdeclare(strict_types=1);
17*e7f56f2aSGreg Roach
187338314fSGreg Roachnamespace Fisharebest\Webtrees\Census;
197338314fSGreg Roach
207338314fSGreg Roachuse Fisharebest\Webtrees\Date;
2152348eb8SGreg Roachuse Fisharebest\Webtrees\Place;
227338314fSGreg Roachuse Mockery;
237338314fSGreg Roach
247338314fSGreg Roach/**
257338314fSGreg Roach * Test harness for the class CensusColumnNationality
267338314fSGreg Roach */
2784e2cf4eSGreg Roachclass CensusColumnNationalityTest extends \Fisharebest\Webtrees\TestCase
28c1010edaSGreg Roach{
297338314fSGreg Roach    /**
307338314fSGreg Roach     * Delete mock objects
3152348eb8SGreg Roach     *
3252348eb8SGreg Roach     * @return void
337338314fSGreg Roach     */
34c1010edaSGreg Roach    public function tearDown()
35c1010edaSGreg Roach    {
367338314fSGreg Roach        Mockery::close();
377338314fSGreg Roach    }
387338314fSGreg Roach
397338314fSGreg Roach    /**
4016d0b7f7SRico Sonntag     * Get place mock.
4116d0b7f7SRico Sonntag     *
4216d0b7f7SRico Sonntag     * @param string $place Gedcom Place
4316d0b7f7SRico Sonntag     *
4452348eb8SGreg Roach     * @return Place
4516d0b7f7SRico Sonntag     */
4652348eb8SGreg Roach    private function getPlaceMock($place): Place
47c1010edaSGreg Roach    {
4816d0b7f7SRico Sonntag        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
4916d0b7f7SRico Sonntag        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
5016d0b7f7SRico Sonntag
5116d0b7f7SRico Sonntag        return $placeMock;
5216d0b7f7SRico Sonntag    }
5316d0b7f7SRico Sonntag
5416d0b7f7SRico Sonntag    /**
5515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
5615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
5752348eb8SGreg Roach     *
5852348eb8SGreg Roach     * @return void
597338314fSGreg Roach     */
60c1010edaSGreg Roach    public function testNoBirthPlace()
61c1010edaSGreg Roach    {
6252f14e58SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
6316d0b7f7SRico Sonntag        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock(''));
642a6fda60SGreg Roach        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
6552f14e58SGreg Roach
6652f14e58SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
6752f14e58SGreg Roach        $census->shouldReceive('censusPlace')->andReturn('Deutschland');
6852f14e58SGreg Roach
6952f14e58SGreg Roach        $column = new CensusColumnNationality($census, '', '');
7052f14e58SGreg Roach
71342dcecdSGreg Roach        $this->assertSame('Deutsch', $column->generate($individual, $individual));
7252f14e58SGreg Roach    }
7352f14e58SGreg Roach
7452f14e58SGreg Roach    /**
7515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
7615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
7752348eb8SGreg Roach     *
7852348eb8SGreg Roach     * @return void
7952f14e58SGreg Roach     */
80c1010edaSGreg Roach    public function testPlaceCountry()
81c1010edaSGreg Roach    {
82c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
8316d0b7f7SRico Sonntag        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia'));
842a6fda60SGreg Roach        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
857338314fSGreg Roach
86c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
877338314fSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
887338314fSGreg Roach
897338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
907338314fSGreg Roach
91342dcecdSGreg Roach        $this->assertSame('Australia', $column->generate($individual, $individual));
927338314fSGreg Roach    }
937338314fSGreg Roach
947338314fSGreg Roach    /**
9515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
9615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
9752348eb8SGreg Roach     *
9852348eb8SGreg Roach     * @return void
997338314fSGreg Roach     */
100c1010edaSGreg Roach    public function testBritish()
101c1010edaSGreg Roach    {
102c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
10316d0b7f7SRico Sonntag        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
1042a6fda60SGreg Roach        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
1057338314fSGreg Roach
106c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
1077338314fSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
1087338314fSGreg Roach
1097338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
1107338314fSGreg Roach
111342dcecdSGreg Roach        $this->assertSame('British', $column->generate($individual, $individual));
1127338314fSGreg Roach    }
1137338314fSGreg Roach
1147338314fSGreg Roach    /**
11515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
11615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
11752348eb8SGreg Roach     *
11852348eb8SGreg Roach     * @return void
1197338314fSGreg Roach     */
120c1010edaSGreg Roach    public function testEmigrated()
121c1010edaSGreg Roach    {
122c314ecc9SGreg Roach        $place1 = Mockery::mock('Fisharebest\Webtrees\Place');
1237338314fSGreg Roach        $place1->shouldReceive('getGedcomName')->andReturn('United States');
1247338314fSGreg Roach
125c314ecc9SGreg Roach        $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact');
1267338314fSGreg Roach        $fact1->shouldReceive('getPlace')->andReturn($place1);
1277338314fSGreg Roach        $fact1->shouldReceive('getDate')->andReturn(new Date('1855'));
1287338314fSGreg Roach
129c314ecc9SGreg Roach        $place2 = Mockery::mock('Fisharebest\Webtrees\Place');
1307338314fSGreg Roach        $place2->shouldReceive('getGedcomName')->andReturn('Australia');
1317338314fSGreg Roach
132c314ecc9SGreg Roach        $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact');
1337338314fSGreg Roach        $fact2->shouldReceive('getPlace')->andReturn($place2);
1347338314fSGreg Roach        $fact2->shouldReceive('getDate')->andReturn(new Date('1865'));
1357338314fSGreg Roach
136c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
13716d0b7f7SRico Sonntag        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
1382a6fda60SGreg Roach        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([
13952f14e58SGreg Roach            $fact1,
14052f14e58SGreg Roach            $fact2,
14113abd6f3SGreg Roach        ]);
1427338314fSGreg Roach
143c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
1447338314fSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
1457338314fSGreg Roach        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
1467338314fSGreg Roach
1477338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
1487338314fSGreg Roach
149342dcecdSGreg Roach        $this->assertSame('United States', $column->generate($individual, $individual));
1507338314fSGreg Roach    }
1517338314fSGreg Roach}
152