xref: /webtrees/tests/feature/EmbeddedVariablesTest.php (revision d80c4b28d3dd97de13a4ad436b779827c4469651)
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 Psr\Http\Message\ServerRequestInterface;
27
28/**
29 * Test the user functions
30 *
31 * @covers \Fisharebest\Webtrees\Statistics
32 * @covers \Fisharebest\Webtrees\Statistics\Repository\BrowserRepository
33 * @covers \Fisharebest\Webtrees\Statistics\Repository\ServerRepository
34 * @covers \Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository
35 * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository
36 * @covers \Fisharebest\Webtrees\Statistics\Repository\HitCountRepository
37 * @covers \Fisharebest\Webtrees\Statistics\Repository\NewsRepository
38 * @covers \Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository
39 * @covers \Fisharebest\Webtrees\Statistics\Repository\IndividualRepository
40 * @covers \Fisharebest\Webtrees\Statistics\Repository\MediaRepository
41 * @covers \Fisharebest\Webtrees\Statistics\Repository\MessageRepository
42 * @covers \Fisharebest\Webtrees\Statistics\Repository\ContactRepository
43 * @covers \Fisharebest\Webtrees\Statistics\Repository\GedcomRepository
44 * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyRepository
45 * @covers \Fisharebest\Webtrees\Statistics\Repository\EventRepository
46 * @covers \Fisharebest\Webtrees\Statistics\Repository\PlaceRepository
47 * @covers \Fisharebest\Webtrees\Statistics\Repository\UserRepository
48 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartChildren
49 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartAge
50 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonGiven
51 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriageAge
52 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonSurname
53 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDistribution
54 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyLargest
55 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartNoChildrenFamilies
56 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartSex
57 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMedia
58 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriage
59 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyWithSources
60 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMortality
61 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDeath
62 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartIndividualWithSources
63 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartBirth
64 * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDivorce
65 * @covers \Fisharebest\Webtrees\Statistics\Service\CountryService
66 * @covers \Fisharebest\Webtrees\Statistics\Service\CenturyService
67 */
68class EmbeddedVariablesTest extends TestCase
69{
70    protected static bool $uses_database = true;
71
72    /**
73     * @return void
74     */
75    public function testAllEmbeddedVariables(): void
76    {
77        $user_service = new UserService();
78
79        $user = $user_service->create('user', 'User', 'user@example.com', 'secret');
80        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
81        Auth::login($user);
82
83        $tree       = $this->importTree('demo.ged');
84        $request    = self::createRequest()->withAttribute('tree', $tree);
85        Webtrees::set(ServerRequestInterface::class, $request);
86
87        $statistics = new Statistics(new ModuleService(), $tree, $user_service);
88
89        // As member
90        $text = $statistics->embedTags('#getAllTagsTable#');
91        self::assertNotEquals('#getAllTagsTable#', $text);
92
93        // As visitor
94        $text = $statistics->embedTags('#getAllTagsTable#');
95        self::assertNotEquals('#getAllTagsTable#', $text);
96    }
97
98    /**
99     * @return void
100     */
101    public function testAllEmbeddedVariablesWithEmptyTree(): void
102    {
103        $tree_service = new TreeService();
104        $tree         = $tree_service->create('name', 'title');
105        $statistics   = new Statistics(new ModuleService(), $tree, new UserService());
106
107        // As visitor
108        $text = $statistics->embedTags('#getAllTagsTable#');
109        self::assertNotEquals('#getAllTagsTable#', $text);
110
111        // As member
112        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
113        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
114        Auth::login($user);
115
116        $text = $statistics->embedTags('#getAllTagsTable#');
117        self::assertNotEquals('#getAllTagsTable#', $text);
118    }
119}
120