1fd9aba47SGreg Roach<?php 23976b470SGreg Roach 3fd9aba47SGreg Roach/** 4fd9aba47SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6fd9aba47SGreg Roach * This program is free software: you can redistribute it and/or modify 7fd9aba47SGreg Roach * it under the terms of the GNU General Public License as published by 8fd9aba47SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9fd9aba47SGreg Roach * (at your option) any later version. 10fd9aba47SGreg Roach * This program is distributed in the hope that it will be useful, 11fd9aba47SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12fd9aba47SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13fd9aba47SGreg Roach * GNU General Public License for more details. 14fd9aba47SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16fd9aba47SGreg Roach */ 17fcfa147eSGreg Roach 18fd9aba47SGreg Roachdeclare(strict_types=1); 19fd9aba47SGreg Roach 20fd9aba47SGreg Roachnamespace Fisharebest\Webtrees; 21fd9aba47SGreg Roach 221fe542e9SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 241e653452SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 25e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 26*cd94ca66SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 27e5a6b4d4SGreg Roach 28fd9aba47SGreg Roach/** 29fd9aba47SGreg Roach * Test the user functions 3094caf646SGreg Roach * 3127701ab0SGreg Roach * @covers \Fisharebest\Webtrees\Statistics 32f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\BrowserRepository 33f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\ServerRepository 34f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository 35f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository 36f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\HitCountRepository 37f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\NewsRepository 38f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository 39f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\IndividualRepository 40f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\MediaRepository 41f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\MessageRepository 42f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\ContactRepository 43f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\GedcomRepository 44f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyRepository 45f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\EventRepository 46f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\PlaceRepository 47f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\UserRepository 48f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartChildren 49f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartAge 50f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonGiven 51f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriageAge 52f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonSurname 53f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDistribution 54f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyLargest 55f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartNoChildrenFamilies 56f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartSex 57f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMedia 58f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriage 59f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyWithSources 60f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMortality 61f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDeath 62f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartIndividualWithSources 63f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartBirth 64f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDivorce 65d12c87dfSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Service\CountryService 66d12c87dfSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Service\CenturyService 6794caf646SGreg Roach */ 6894caf646SGreg Roachclass EmbeddedVariablesTest extends TestCase 6994caf646SGreg Roach{ 70*cd94ca66SGreg Roach protected static bool $uses_database = true; 7194caf646SGreg Roach 7294caf646SGreg Roach /** 73fd9aba47SGreg Roach * @return void 74fd9aba47SGreg Roach */ 75e5a6b4d4SGreg Roach public function testAllEmbeddedVariables(): void 76fd9aba47SGreg Roach { 77*cd94ca66SGreg Roach $user_service = new UserService(); 78e5a6b4d4SGreg Roach 79*cd94ca66SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 801fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 81945057aeSGreg Roach Auth::login($user); 82e5a6b4d4SGreg Roach 83*cd94ca66SGreg Roach $tree = $this->importTree('demo.ged'); 84*cd94ca66SGreg Roach $request = self::createRequest()->withAttribute('tree', $tree); 85*cd94ca66SGreg Roach Webtrees::set(ServerRequestInterface::class, $request); 86*cd94ca66SGreg Roach 87*cd94ca66SGreg Roach $statistics = new Statistics(new ModuleService(), $tree, $user_service); 88*cd94ca66SGreg Roach 89*cd94ca66SGreg Roach // As member 90*cd94ca66SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 91*cd94ca66SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 92*cd94ca66SGreg Roach 93*cd94ca66SGreg Roach // As visitor 9438ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 955e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 96e5a6b4d4SGreg Roach } 97e5a6b4d4SGreg Roach 98e5a6b4d4SGreg Roach /** 99e5a6b4d4SGreg Roach * @return void 100e5a6b4d4SGreg Roach */ 101e5a6b4d4SGreg Roach public function testAllEmbeddedVariablesWithEmptyTree(): void 102e5a6b4d4SGreg Roach { 1031e653452SGreg Roach $tree_service = new TreeService(); 1041e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 105e5a6b4d4SGreg Roach $statistics = new Statistics(new ModuleService(), $tree, new UserService()); 106e5a6b4d4SGreg Roach 107945057aeSGreg Roach // As visitor 1084a520496SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1095e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 110945057aeSGreg Roach 111945057aeSGreg Roach // As member 112945057aeSGreg Roach $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret'); 1131fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 114945057aeSGreg Roach Auth::login($user); 115e5a6b4d4SGreg Roach 11638ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1175e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 118fd9aba47SGreg Roach } 119fd9aba47SGreg Roach} 120