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