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