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