xref: /webtrees/tests/app/Census/CensusColumnMotherBirthPlaceSimpleTest.php (revision e9e853987811e8bd423dccf26f6ef57571f393eb)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Webtrees\Family;
21use Fisharebest\Webtrees\Individual;
22use Fisharebest\Webtrees\Place;
23use Mockery;
24
25/**
26 * Test harness for the class CensusColumnMotherBirthPlaceSimple
27 */
28class CensusColumnMotherBirthPlaceSimpleTest extends \Fisharebest\Webtrees\TestCase
29{
30    /**
31     * Delete mock objects
32     *
33     * @return void
34     */
35    public function tearDown()
36    {
37        Mockery::close();
38    }
39
40    /**
41     * Get place mock.
42     *
43     * @param string $place Gedcom Place
44     *
45     * @return Place
46     */
47    private function getPlaceMock($place): Place
48    {
49        $placeParts = explode(', ', $place);
50
51        $placeMock = Mockery::mock(Place::class);
52        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
53        $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts));
54
55        return $placeMock;
56    }
57
58    /**
59     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlaceSimple
60     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
61     *
62     * @return void
63     */
64    public function testKnownStateAndTown(): void
65    {
66        $father = Mockery::mock(Individual::class);
67        $father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Miami, Florida, United States'));
68
69        $family = Mockery::mock(Family::class);
70        $family->shouldReceive('getWife')->andReturn($father);
71
72        $individual = Mockery::mock(Individual::class);
73        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
74
75        $census = Mockery::mock(CensusInterface::class);
76        $census->shouldReceive('censusPlace')->andReturn('United States');
77
78        $column = new CensusColumnMotherBirthPlaceSimple($census, '', '');
79
80        $this->assertSame('Florida', $column->generate($individual, $individual));
81    }
82}
83