xref: /webtrees/tests/feature/EmbeddedVariablesTest.php (revision f70bcff589628705e50ed72a6fc6cbad68558677)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees;
21
22use Fisharebest\Webtrees\Contracts\UserInterface;
23use Fisharebest\Webtrees\Services\ModuleService;
24use Fisharebest\Webtrees\Services\TreeService;
25use Fisharebest\Webtrees\Services\UserService;
26use Fisharebest\Webtrees\Statistics\Service\CountryService;
27use Psr\Http\Message\ServerRequestInterface;
28
29/**
30 * Test the user functions
31 *
32 * @covers \Fisharebest\Webtrees\Statistics
33 * @covers \Fisharebest\Webtrees\Statistics\Repository\BrowserRepository
34 * @covers \Fisharebest\Webtrees\Statistics\Repository\ServerRepository
35 * @covers \Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository
36 * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository
37 * @covers \Fisharebest\Webtrees\Statistics\Repository\HitCountRepository
38 * @covers \Fisharebest\Webtrees\Statistics\Repository\NewsRepository
39 * @covers \Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository
40 * @covers \Fisharebest\Webtrees\Statistics\Repository\IndividualRepository
41 * @covers \Fisharebest\Webtrees\Statistics\Repository\MediaRepository
42 * @covers \Fisharebest\Webtrees\Statistics\Repository\MessageRepository
43 * @covers \Fisharebest\Webtrees\Statistics\Repository\ContactRepository
44 * @covers \Fisharebest\Webtrees\Statistics\Repository\GedcomRepository
45 * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyRepository
46 * @covers \Fisharebest\Webtrees\Statistics\Repository\EventRepository
47 * @covers \Fisharebest\Webtrees\Statistics\Repository\PlaceRepository
48 * @covers \Fisharebest\Webtrees\Statistics\Repository\UserRepository
49 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartChildren
50 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartAge
51 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonGiven
52 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriageAge
53 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonSurname
54 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDistribution
55 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyLargest
56 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartNoChildrenFamilies
57 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartSex
58 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMedia
59 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriage
60 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyWithSources
61 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMortality
62 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDeath
63 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartIndividualWithSources
64 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartBirth
65 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDivorce
66 * @covers \Fisharebest\Webtrees\Statistics\Service\CountryService
67 * @covers \Fisharebest\Webtrees\Statistics\Service\CenturyService
68 */
69class EmbeddedVariablesTest extends TestCase
70{
71    protected static bool $uses_database = true;
72
73    /**
74     * @return void
75     */
76    public function testAllEmbeddedVariables(): void
77    {
78        $user_service = new UserService();
79
80        $user = $user_service->create('user', 'User', 'user@example.com', 'secret');
81        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
82        Auth::login($user);
83
84        $tree       = $this->importTree('demo.ged');
85        $request    = self::createRequest()->withAttribute('tree', $tree);
86        Webtrees::set(ServerRequestInterface::class, $request);
87
88        $statistics = new Statistics(new CountryService(), new ModuleService(), $tree, $user_service);
89
90        // As member
91        $text = $statistics->embedTags('#getAllTagsTable#');
92        self::assertNotEquals('#getAllTagsTable#', $text);
93
94        // As visitor
95        $text = $statistics->embedTags('#getAllTagsTable#');
96        self::assertNotEquals('#getAllTagsTable#', $text);
97    }
98
99    /**
100     * @return void
101     */
102    public function testAllEmbeddedVariablesWithEmptyTree(): void
103    {
104        $tree_service = new TreeService();
105        $tree         = $tree_service->create('name', 'title');
106        $statistics   = new Statistics(new CountryService(), new ModuleService(), $tree, new UserService());
107
108        // As visitor
109        $text = $statistics->embedTags('#getAllTagsTable#');
110        self::assertNotEquals('#getAllTagsTable#', $text);
111
112        // As member
113        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
114        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
115        Auth::login($user);
116
117        $text = $statistics->embedTags('#getAllTagsTable#');
118        self::assertNotEquals('#getAllTagsTable#', $text);
119    }
120}
121