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; 27*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartAge; 28*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartBirth; 29*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartChildren; 30*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartCommonGiven; 31*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartCommonSurname; 32*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartDeath; 33*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartDistribution; 34*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartDivorce; 35*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartFamilyLargest; 36*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartFamilyWithSources; 37*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartIndividualWithSources; 38*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartMarriage; 39*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartMarriageAge; 40*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartMedia; 41*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartMortality; 42*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartNoChildrenFamilies; 43*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Google\ChartSex; 44*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\BrowserRepository; 45*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\ContactRepository; 46*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\EventRepository; 47*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository; 48*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\FamilyRepository; 49*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository; 50*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\GedcomRepository; 51*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\HitCountRepository; 52*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\IndividualRepository; 53*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository; 54*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\MediaRepository; 55*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\MessageRepository; 56*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\NewsRepository; 57*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\PlaceRepository; 58*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\ServerRepository; 59*202c018bSGreg Roachuse Fisharebest\Webtrees\Statistics\Repository\UserRepository; 60f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CenturyService; 61f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\ColorService; 624c78e066SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CountryService; 63*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 64cd94ca66SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 65e5a6b4d4SGreg Roach 66*202c018bSGreg Roach#[CoversClass(Statistics::class)] 67*202c018bSGreg Roach#[CoversClass(BrowserRepository::class)] 68*202c018bSGreg Roach#[CoversClass(ServerRepository::class)] 69*202c018bSGreg Roach#[CoversClass(LatestUserRepository::class)] 70*202c018bSGreg Roach#[CoversClass(FamilyDatesRepository::class)] 71*202c018bSGreg Roach#[CoversClass(HitCountRepository::class)] 72*202c018bSGreg Roach#[CoversClass(NewsRepository::class)] 73*202c018bSGreg Roach#[CoversClass(FavoritesRepository::class)] 74*202c018bSGreg Roach#[CoversClass(IndividualRepository::class)] 75*202c018bSGreg Roach#[CoversClass(MediaRepository::class)] 76*202c018bSGreg Roach#[CoversClass(MessageRepository::class)] 77*202c018bSGreg Roach#[CoversClass(ContactRepository::class)] 78*202c018bSGreg Roach#[CoversClass(GedcomRepository::class)] 79*202c018bSGreg Roach#[CoversClass(FamilyRepository::class)] 80*202c018bSGreg Roach#[CoversClass(EventRepository::class)] 81*202c018bSGreg Roach#[CoversClass(PlaceRepository::class)] 82*202c018bSGreg Roach#[CoversClass(UserRepository::class)] 83*202c018bSGreg Roach#[CoversClass(ChartChildren::class)] 84*202c018bSGreg Roach#[CoversClass(ChartAge::class)] 85*202c018bSGreg Roach#[CoversClass(ChartCommonGiven::class)] 86*202c018bSGreg Roach#[CoversClass(ChartMarriageAge::class)] 87*202c018bSGreg Roach#[CoversClass(ChartCommonSurname::class)] 88*202c018bSGreg Roach#[CoversClass(ChartDistribution::class)] 89*202c018bSGreg Roach#[CoversClass(ChartFamilyLargest::class)] 90*202c018bSGreg Roach#[CoversClass(ChartNoChildrenFamilies::class)] 91*202c018bSGreg Roach#[CoversClass(ChartSex::class)] 92*202c018bSGreg Roach#[CoversClass(ChartMedia::class)] 93*202c018bSGreg Roach#[CoversClass(ChartMarriage::class)] 94*202c018bSGreg Roach#[CoversClass(ChartFamilyWithSources::class)] 95*202c018bSGreg Roach#[CoversClass(ChartMortality::class)] 96*202c018bSGreg Roach#[CoversClass(ChartDeath::class)] 97*202c018bSGreg Roach#[CoversClass(ChartIndividualWithSources::class)] 98*202c018bSGreg Roach#[CoversClass(ChartBirth::class)] 99*202c018bSGreg Roach#[CoversClass(ChartDivorce::class)] 100*202c018bSGreg Roach#[CoversClass(CountryService::class)] 101*202c018bSGreg Roach#[CoversClass(CenturyService::class)] 10294caf646SGreg Roachclass EmbeddedVariablesTest extends TestCase 10394caf646SGreg Roach{ 104cd94ca66SGreg Roach protected static bool $uses_database = true; 10594caf646SGreg Roach 106e5a6b4d4SGreg Roach public function testAllEmbeddedVariables(): void 107fd9aba47SGreg Roach { 108cd94ca66SGreg Roach $user_service = new UserService(); 109e5a6b4d4SGreg Roach 110cd94ca66SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 1111fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 112945057aeSGreg Roach Auth::login($user); 113e5a6b4d4SGreg Roach 114cd94ca66SGreg Roach $tree = $this->importTree('demo.ged'); 115cd94ca66SGreg Roach $request = self::createRequest()->withAttribute('tree', $tree); 116d35568b4SGreg Roach Registry::container()->set(ServerRequestInterface::class, $request); 117cd94ca66SGreg Roach 118f78da678SGreg Roach $statistics = new Statistics( 119f78da678SGreg Roach new CenturyService(), 120f78da678SGreg Roach new ColorService(), 121f78da678SGreg Roach new CountryService(), 122f78da678SGreg Roach new ModuleService(), 123f78da678SGreg Roach $tree, 124f78da678SGreg Roach $user_service 125f78da678SGreg Roach ); 126cd94ca66SGreg Roach 127cd94ca66SGreg Roach // As member 128cd94ca66SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 129cd94ca66SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 130cd94ca66SGreg Roach 131cd94ca66SGreg Roach // As visitor 13238ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1335e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 134e5a6b4d4SGreg Roach } 135e5a6b4d4SGreg Roach 136e5a6b4d4SGreg Roach public function testAllEmbeddedVariablesWithEmptyTree(): void 137e5a6b4d4SGreg Roach { 1382c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1392c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1401e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 141f78da678SGreg Roach $statistics = new Statistics( 142f78da678SGreg Roach new CenturyService(), 143f78da678SGreg Roach new ColorService(), 144f78da678SGreg Roach new CountryService(), 145f78da678SGreg Roach new ModuleService(), 146f78da678SGreg Roach $tree, 147f78da678SGreg Roach new UserService() 148f78da678SGreg Roach ); 149e5a6b4d4SGreg Roach 150945057aeSGreg Roach // As visitor 1514a520496SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1525e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 153945057aeSGreg Roach 154945057aeSGreg Roach // As member 155945057aeSGreg Roach $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret'); 1561fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 157945057aeSGreg Roach Auth::login($user); 158e5a6b4d4SGreg Roach 15938ef8377SGreg Roach $text = $statistics->embedTags('#getAllTagsTable#'); 1605e933c21SGreg Roach self::assertNotEquals('#getAllTagsTable#', $text); 161fd9aba47SGreg Roach } 162fd9aba47SGreg Roach} 163