1fd9aba47SGreg Roach<?php 23976b470SGreg Roach 3fd9aba47SGreg Roach/** 4fd9aba47SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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; 232c685d76SGreg Roachuse Fisharebest\Webtrees\Services\GedcomImportService; 24e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 251e653452SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 26e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 27f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CenturyService; 28f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\ColorService; 294c78e066SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CountryService; 30cd94ca66SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 31e5a6b4d4SGreg Roach 32fd9aba47SGreg Roach/** 33fd9aba47SGreg Roach * Test the user functions 3494caf646SGreg Roach * 3527701ab0SGreg Roach * @covers \Fisharebest\Webtrees\Statistics 36f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\BrowserRepository 37f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\ServerRepository 38f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository 39f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository 40f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\HitCountRepository 41f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\NewsRepository 42f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository 43f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\IndividualRepository 44f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\MediaRepository 45f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\MessageRepository 46f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\ContactRepository 47f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\GedcomRepository 48f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\FamilyRepository 49f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\EventRepository 50f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\PlaceRepository 51f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Repository\UserRepository 52f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartChildren 53f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartAge 54f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonGiven 55f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriageAge 56f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartCommonSurname 57f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDistribution 58f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyLargest 59f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartNoChildrenFamilies 60f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartSex 61f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMedia 62f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMarriage 63f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartFamilyWithSources 64f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartMortality 65f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDeath 66f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartIndividualWithSources 67f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartBirth 68f389d81eSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Google\ChartDivorce 69d12c87dfSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Service\CountryService 70d12c87dfSGreg Roach * @covers \Fisharebest\Webtrees\Statistics\Service\CenturyService 7194caf646SGreg Roach */ 7294caf646SGreg Roachclass EmbeddedVariablesTest extends TestCase 7394caf646SGreg Roach{ 74cd94ca66SGreg Roach protected static bool $uses_database = true; 7594caf646SGreg Roach 7694caf646SGreg Roach /** 77fd9aba47SGreg Roach * @return void 78fd9aba47SGreg Roach */ 79e5a6b4d4SGreg Roach public function testAllEmbeddedVariables(): void 80fd9aba47SGreg Roach { 81cd94ca66SGreg Roach $user_service = new UserService(); 82e5a6b4d4SGreg Roach 83cd94ca66SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 841fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 85945057aeSGreg Roach Auth::login($user); 86e5a6b4d4SGreg Roach 87cd94ca66SGreg Roach $tree = $this->importTree('demo.ged'); 88cd94ca66SGreg Roach $request = self::createRequest()->withAttribute('tree', $tree); 89*d35568b4SGreg Roach Registry::container()->set(ServerRequestInterface::class, $request); 90cd94ca66SGreg Roach 91f78da678SGreg Roach $statistics = new Statistics( 92f78da678SGreg Roach new CenturyService(), 93f78da678SGreg Roach new ColorService(), 94f78da678SGreg Roach new CountryService(), 95f78da678SGreg Roach new ModuleService(), 96f78da678SGreg Roach $tree, 97f78da678SGreg Roach $user_service 98f78da678SGreg Roach ); 99cd94ca66SGreg Roach 100cd94ca66SGreg Roach // As member 101cd94ca66SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 102cd94ca66SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 103cd94ca66SGreg Roach 104cd94ca66SGreg Roach // As visitor 10538ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1065e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 107e5a6b4d4SGreg Roach } 108e5a6b4d4SGreg Roach 109e5a6b4d4SGreg Roach /** 110e5a6b4d4SGreg Roach * @return void 111e5a6b4d4SGreg Roach */ 112e5a6b4d4SGreg Roach public function testAllEmbeddedVariablesWithEmptyTree(): void 113e5a6b4d4SGreg Roach { 1142c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1152c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1161e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 117f78da678SGreg Roach $statistics = new Statistics( 118f78da678SGreg Roach new CenturyService(), 119f78da678SGreg Roach new ColorService(), 120f78da678SGreg Roach new CountryService(), 121f78da678SGreg Roach new ModuleService(), 122f78da678SGreg Roach $tree, 123f78da678SGreg Roach new UserService() 124f78da678SGreg Roach ); 125e5a6b4d4SGreg Roach 126945057aeSGreg Roach // As visitor 1274a520496SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1285e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 129945057aeSGreg Roach 130945057aeSGreg Roach // As member 131945057aeSGreg Roach $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret'); 1321fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 133945057aeSGreg Roach Auth::login($user); 134e5a6b4d4SGreg Roach 13538ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1365e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 137fd9aba47SGreg Roach } 138fd9aba47SGreg Roach} 139