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