From 5a41cc35ade5574e954eff5060297798c5aa6582 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 14 Mar 2024 10:52:28 +0200 Subject: [PATCH 01/11] UHF-9824: PHPCS fixes --- helfi_navigation.install | 2 +- helfi_navigation.module | 2 +- src/ApiAuthorization.php | 2 +- src/ApiManager.php | 2 +- src/CacheWarmer.php | 2 +- src/Event/MenuTreeBuilderLink.php | 2 +- src/EventSubscriber/RedirectEventSubscriber.php | 2 +- src/ExternalMenuBlockInterface.php | 2 +- src/ExternalMenuTreeBuilder.php | 2 +- src/HelfiNavigationServiceProvider.php | 2 +- src/MainMenuManager.php | 2 +- src/Menu/MenuTreeBuilder.php | 2 +- src/Plugin/Block/ExternalMenuBlock.php | 2 +- src/Plugin/Block/ExternalMenuBlockBase.php | 2 +- src/Plugin/Block/MobileMenuFallbackBlock.php | 2 +- src/Plugin/Derivative/ExternalMenuBlock.php | 2 +- src/Plugin/Menu/ExternalMenuLink.php | 2 +- src/Plugin/QueueWorker/MenuQueue.php | 2 +- src/Plugin/rest/resource/GlobalMobileMenu.php | 2 +- tests/src/Functional/MenuBlockTest.php | 2 +- tests/src/Functional/MenuContentTranslationStatusTest.php | 2 +- tests/src/FunctionalJavascript/JsSettingsTest.php | 2 +- tests/src/Kernel/ExternalMenuTreeBuilderTest.php | 2 +- tests/src/Kernel/MenuSyncTest.php | 2 +- tests/src/Kernel/Plugin/Block/MobileMenuFallbackTest.php | 2 +- tests/src/Kernel/Plugin/rest/resource/GlobalMobileMenuTest.php | 2 +- tests/src/Traits/MenuLinkTrait.php | 2 +- tests/src/Unit/ApiAuthorizationTest.php | 2 +- tests/src/Unit/ApiManagerTest.php | 2 +- tests/src/Unit/MenuTreeBuilderTest.php | 2 +- tests/src/Unit/Plugin/Menu/ExternalMenuLinkTest.php | 2 +- tests/src/Unit/Plugin/QueueWorker/MenuQueueTest.php | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/helfi_navigation.install b/helfi_navigation.install index 109ed46..90940c5 100755 --- a/helfi_navigation.install +++ b/helfi_navigation.install @@ -5,7 +5,7 @@ * Contains installation hooks for 'helfi_news_feed' module. */ -declare(strict_types = 1); +declare(strict_types=1); use Drupal\block\Entity\Block; use Drupal\Core\Field\BaseFieldDefinition; diff --git a/helfi_navigation.module b/helfi_navigation.module index 9c0722a..274ae3e 100644 --- a/helfi_navigation.module +++ b/helfi_navigation.module @@ -5,7 +5,7 @@ * Contains alterations for the Hel.fi navigation. */ -declare(strict_types = 1); +declare(strict_types=1); use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Entity\EntityTypeInterface; diff --git a/src/ApiAuthorization.php b/src/ApiAuthorization.php index 6bd7813..eeacc9f 100644 --- a/src/ApiAuthorization.php +++ b/src/ApiAuthorization.php @@ -1,6 +1,6 @@ Date: Tue, 19 Mar 2024 09:13:45 +0200 Subject: [PATCH 02/11] UHF-9824: Service to evaluate domain --- helfi_navigation.services.yml | 5 ++ ...soluteUrlMenuTreeBuilderLinkSubscriber.php | 81 +++++++++++++++++++ src/Menu/MenuTreeBuilder.php | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php diff --git a/helfi_navigation.services.yml b/helfi_navigation.services.yml index e741a49..5886eac 100644 --- a/helfi_navigation.services.yml +++ b/helfi_navigation.services.yml @@ -48,3 +48,8 @@ services: arguments: - '@config.factory' - '@helfi_api_base.vault_manager' + helfi_api_base.absolute_url_menu_tree_builder_subscriber: + class: Drupal\helfi_navigation\EventSubscriber\AbsoluteUrlMenuTreeBuilderLinkSubscriber + arguments: ['@helfi_api_base.environment_resolver'] + tags: + - { name: event_subscriber } diff --git a/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php b/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php new file mode 100644 index 0000000..7bbb25c --- /dev/null +++ b/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php @@ -0,0 +1,81 @@ +mustBeAbsoluteUrl !== NULL) { + return $this->mustBeAbsoluteUrl; + } + + try { + $activeEnvironment = $this->environmentResolver->getActiveEnvironment(); + $matchingEnvironment = $this->environmentResolver->getProject(Project::ETUSIVU) + ->getEnvironment($activeEnvironment->getEnvironmentName()); + + // By default, links are either absolute (external) or not. This + // should already be evaluated by MenuTreeBuilder service, so the + // only thing left for us to do here is to determine whether the + // Etusivu's domain matches instance's current domain. + return $this->mustBeAbsoluteUrl = $matchingEnvironment->getBaseUrl() !== $activeEnvironment->getBaseUrl(); + } + catch (\InvalidArgumentException) { + } + return FALSE; + } + + /** + * Responds to MenuTreeBuilderLink event. + * + * @param \Drupal\helfi_navigation\Event\MenuTreeBuilderLink $link + * The event to respond to. + */ + public function updateLink(MenuTreeBuilderLink $link) : void { + if (!$this->mustBeAbsolute()) { + return; + } + $link->url->setAbsolute(TRUE); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() : array { + return [ + MenuTreeBuilderLink::class => ['updateLink'], + ]; + } + +} diff --git a/src/Menu/MenuTreeBuilder.php b/src/Menu/MenuTreeBuilder.php index 6e28c70..d2d0605 100644 --- a/src/Menu/MenuTreeBuilder.php +++ b/src/Menu/MenuTreeBuilder.php @@ -218,7 +218,7 @@ private function processItem(MenuTreeBuilderLink $link) : array { ->dispatch($link); return array_merge([ - 'url' => $menuTreeBuilderLink->url->setAbsolute()->toString(TRUE)->getGeneratedUrl(), + 'url' => $menuTreeBuilderLink->url->toString(TRUE)->getGeneratedUrl(), ], $menuTreeBuilderLink->item); } From 7afe52116746171fa03ad70c66710358cd8fcb66 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 09:40:40 +0200 Subject: [PATCH 03/11] UHF-9824: Keep original url --- src/ExternalMenuTreeBuilder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ExternalMenuTreeBuilder.php b/src/ExternalMenuTreeBuilder.php index b303998..98b267d 100644 --- a/src/ExternalMenuTreeBuilder.php +++ b/src/ExternalMenuTreeBuilder.php @@ -140,6 +140,7 @@ private function createLink( ]; // Parse the URL. + $item->originalUrl = $item->url; $item->url = !empty($item->url) ? UrlHelper::parse($item->url) : new Url(''); $item->external = $this->domainResolver->isExternal($item->url); @@ -190,7 +191,8 @@ private function inActiveTrail(object $item): bool { throw new \LogicException('Request is not set.'); } $currentPath = parse_url($request->getUri(), PHP_URL_PATH); - $linkPath = parse_url($item->url->getUri(), PHP_URL_PATH); + + $linkPath = parse_url($item->originalUrl, PHP_URL_PATH); // We don't care about the domain when comparing URLs because the // site might be served from multiple different domains. From 47b8aced4df820e98fc942a0d44b30ad4c70e789 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 10:14:50 +0200 Subject: [PATCH 04/11] UHF-9824: Fixed test --- tests/src/Kernel/MenuSyncTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/MenuSyncTest.php b/tests/src/Kernel/MenuSyncTest.php index 2c7dd51..1e9840b 100644 --- a/tests/src/Kernel/MenuSyncTest.php +++ b/tests/src/Kernel/MenuSyncTest.php @@ -136,7 +136,7 @@ public function testConfigTranslation(string $langcode) : void { $this->assertEquals('base:site_name_' . $langcode, $data['menu_tree']['id']); $this->assertEquals($siteName, $data['menu_tree']['name']); $this->assertEquals($langcode, $data['langcode']); - $this->assertStringStartsWith('http://', $data['menu_tree']['url']); + $this->assertStringStartsWith('/' . $langcode, $data['menu_tree']['url']); return new ApiResponse((object) [ 'status' => [ From b355e7fd27404552cd997c21af0b98cd1a44f7dd Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 10:25:19 +0200 Subject: [PATCH 05/11] UHF-9824: Checkout v4 --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9b80bd..059d0a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,7 @@ jobs: - 3306:3306 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - + - uses: actions/checkout@v4 - name: Parse $MODULE_NAME from composer.json run: echo "MODULE_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV From 8d793140f3a9bedc003060c0e6a5f25986930da1 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 10:30:51 +0200 Subject: [PATCH 06/11] UHF-9824: Fetch depth 0 --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 059d0a4..e6ac67f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,9 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Parse $MODULE_NAME from composer.json run: echo "MODULE_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV From b991246cd5428c8f49e235f97a6cffe02f838504 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 10:46:31 +0200 Subject: [PATCH 07/11] UHF-9824: Added test --- .github/workflows/ci.yml | 2 - ...teUrlMenuTreeBuilderLinkSubscriberTest.php | 56 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ac67f..bff3219 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,8 +35,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Parse $MODULE_NAME from composer.json run: echo "MODULE_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV diff --git a/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php b/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php new file mode 100644 index 0000000..e4bdc4d --- /dev/null +++ b/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php @@ -0,0 +1,56 @@ +setActiveProject(Project::ASUMINEN, $environment); + $menuTree = $this->getMenuTree($langcode); + $this->assertEquals($expected, $menuTree['url']); + } + + /** + * A data provider. + * + * @return array[] + * The data. + */ + public function absoluteUrlData() : array { + return [ + // The URL should be absolute because the local environment has + // a project-specific domains. + [ + 'fi', + EnvironmentEnum::Local, + 'http://localhost/fi', + ], + // The URL should be relative because the prod environment shares + // the domain name (www.hel.fi). + [ + 'en', + EnvironmentEnum::Prod, + '/en', + ], + ]; + } + +} From 1bc15c2a0fdacaf301fe060ac7a6080efdb4ffa4 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 10:59:20 +0200 Subject: [PATCH 08/11] UHF-9824: Added more tests --- .../src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php b/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php index e4bdc4d..7e9c1c1 100644 --- a/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php +++ b/tests/src/Kernel/AbsoluteUrlMenuTreeBuilderLinkSubscriberTest.php @@ -23,6 +23,7 @@ class AbsoluteUrlMenuTreeBuilderLinkSubscriberTest extends MenuTreeBuilderTestBa * @dataProvider absoluteUrlData */ public function testAbsoluteUrl(string $langcode, EnvironmentEnum $environment, string $expected) : void { + $this->createLinks(); $this->setActiveProject(Project::ASUMINEN, $environment); $menuTree = $this->getMenuTree($langcode); $this->assertEquals($expected, $menuTree['url']); From b8588616c16b5d1629b53d71f24f2783fa977e7c Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 19 Mar 2024 20:25:34 +0200 Subject: [PATCH 09/11] UHF-9824: Update main navigation on deploy --- helfi_navigation.install | 9 +++++++++ .../AbsoluteUrlMenuTreeBuilderLinkSubscriber.php | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/helfi_navigation.install b/helfi_navigation.install index 90940c5..22b44f4 100755 --- a/helfi_navigation.install +++ b/helfi_navigation.install @@ -305,3 +305,12 @@ function helfi_navigation_update_9003() : void { function helfi_navigation_update_9004() : void { module_set_weight('helfi_navigation', 1); } + +/** + * Update global "main" navigation links. + */ +function helfi_navigation_update_9005() : void { + foreach (['fi', 'en', 'sv'] as $language) { + _helfi_navigation_queue_item('main', $language, 'update'); + } +} diff --git a/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php b/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php index 7bbb25c..8b41bf6 100644 --- a/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php +++ b/src/EventSubscriber/AbsoluteUrlMenuTreeBuilderLinkSubscriber.php @@ -35,7 +35,6 @@ public function __construct( * TRUE if the link must be absolute URL. */ private function mustBeAbsolute() : bool { - // No need to re-evaluate this since this is not link specific. if ($this->mustBeAbsoluteUrl !== NULL) { return $this->mustBeAbsoluteUrl; } @@ -45,7 +44,7 @@ private function mustBeAbsolute() : bool { $matchingEnvironment = $this->environmentResolver->getProject(Project::ETUSIVU) ->getEnvironment($activeEnvironment->getEnvironmentName()); - // By default, links are either absolute (external) or not. This + // By default, links are either absolute (external) or relative. This // should already be evaluated by MenuTreeBuilder service, so the // only thing left for us to do here is to determine whether the // Etusivu's domain matches instance's current domain. From d11cd5f085a69d6f0ad81cbf21eb55e22620f022 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 20 Mar 2024 08:40:36 +0200 Subject: [PATCH 10/11] UHF-9824: Document absolute url override setting --- README.md | 17 ++++++++++++----- helfi_navigation.services.yml | 5 ++++- src/ExternalMenuTreeBuilder.php | 6 ++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f90d3b3..6761da1 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,9 @@ Only main-navigation has syncing option. Other navigations are created in Etusiv ## Local development - Setup local Etusivu-instance. - - run `drush upwd helfi-admin 123` to update admin password. it is used as api key in other instances. + - Run `drush upwd helfi-admin 123` to update admin password. It is used as the API key in other instances. - Setup any other instance with helfi_navigation module enabled. - - Add following line to local.settings.php. Otherwise syncing global navigation won't work + - Add the following line to local.settings.php. Otherwise, syncing global navigation won't work ```php $config['helfi_api_base.api_accounts']['vault'][] = [ 'id' => 'helfi_navigation', @@ -49,17 +49,24 @@ Only main-navigation has syncing option. Other navigations are created in Etusiv ]; ``` +Local environment forces synced links always to be absolute URLs, whereas other environments allow relative URLs. + +If you wish to replicate the production setup (when testing through one domain, like `helfi-proxy.docker.so` for example). Add the following line to `local.services.yml`: +```yaml +parameters: + helfi_navigation.absolute_url_always: false +``` + ### Steps after both instances are up and running. 1. Edit and save menu on any instance with helfi_navigation module enabled. - When adding new items, make sure both the menu link and the node are enabled. disabled content won't be synced. 2. Run `drush cron`. - After that you can run `docker compose logs app` to see possible exceptions or if menu sync cron succeeded. -3. Go to Etusivu and run drush cr. The navigations should have been updated +3. Go to Etusivu and run drush cr. The navigation should have been updated based on the changes you made 4. Instances should fetch the menus from Etusivu and update the related blocks after `drush cr` and page refresh. ## Changes not updating to the global mobile menu? The global mobile navigation API can be found from `/api/v1/global-mobile-menu` path so check if your changes are -visible there. If they are, the problem is probably caused by caches. The global mobile menu is cached for 24 hours by -the browser. You can clear this cache on Chrome by opening developer tools and on the `Network` tab select the +visible there. If they are, the problem is probably caused by caches. The browser caches the global mobile menu for 24 hours. You can clear this cache on Chrome by opening developer tools and on the `Network` tab select the `Disable cache` checkbox and reload the page. diff --git a/helfi_navigation.services.yml b/helfi_navigation.services.yml index 5886eac..cf2603a 100644 --- a/helfi_navigation.services.yml +++ b/helfi_navigation.services.yml @@ -1,5 +1,6 @@ parameters: helfi_navigation.request_timeout: 15 + helfi_navigation.absolute_url_always: null services: logger.channel.helfi_navigation: parent: logger.channel_base @@ -50,6 +51,8 @@ services: - '@helfi_api_base.vault_manager' helfi_api_base.absolute_url_menu_tree_builder_subscriber: class: Drupal\helfi_navigation\EventSubscriber\AbsoluteUrlMenuTreeBuilderLinkSubscriber - arguments: ['@helfi_api_base.environment_resolver'] + arguments: + - '@helfi_api_base.environment_resolver' + - '%helfi_navigation.absolute_url_always%' tags: - { name: event_subscriber } diff --git a/src/ExternalMenuTreeBuilder.php b/src/ExternalMenuTreeBuilder.php index 98b267d..108412e 100644 --- a/src/ExternalMenuTreeBuilder.php +++ b/src/ExternalMenuTreeBuilder.php @@ -139,8 +139,7 @@ private function createLink( 'provider' => 'helfi_navigation', ]; - // Parse the URL. - $item->originalUrl = $item->url; + $item->link = $item->url; $item->url = !empty($item->url) ? UrlHelper::parse($item->url) : new Url(''); $item->external = $this->domainResolver->isExternal($item->url); @@ -191,8 +190,7 @@ private function inActiveTrail(object $item): bool { throw new \LogicException('Request is not set.'); } $currentPath = parse_url($request->getUri(), PHP_URL_PATH); - - $linkPath = parse_url($item->originalUrl, PHP_URL_PATH); + $linkPath = parse_url($item->link, PHP_URL_PATH); // We don't care about the domain when comparing URLs because the // site might be served from multiple different domains. From 3690e77e954f65ff84779d2925a62bf7775e1d3d Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 20 Mar 2024 08:59:15 +0200 Subject: [PATCH 11/11] UHF-9824: Removed unused CacheWarmer service --- helfi_navigation.services.yml | 7 --- src/CacheWarmer.php | 90 --------------------------- tests/src/Kernel/CacheWarmerTest.php | 91 ---------------------------- 3 files changed, 188 deletions(-) delete mode 100644 src/CacheWarmer.php delete mode 100644 tests/src/Kernel/CacheWarmerTest.php diff --git a/helfi_navigation.services.yml b/helfi_navigation.services.yml index cf2603a..fc6c715 100644 --- a/helfi_navigation.services.yml +++ b/helfi_navigation.services.yml @@ -37,13 +37,6 @@ services: - '@menu.link_tree' - '@plugin.manager.menu.link' - '@event_dispatcher' - helfi_navigation.cache_warmer: - class: Drupal\helfi_navigation\CacheWarmer - arguments: - - '@tempstore.shared' - - '@language_manager' - - '@cache_tags.invalidator' - - '@helfi_navigation.api_manager' helfi_navigation.api_authorization: class: Drupal\helfi_navigation\ApiAuthorization arguments: diff --git a/src/CacheWarmer.php b/src/CacheWarmer.php deleted file mode 100644 index d133fe1..0000000 --- a/src/CacheWarmer.php +++ /dev/null @@ -1,90 +0,0 @@ -tempStoreFactory->get(self::STORAGE_KEY); - - $currentHash = $storage->get($key); - $hash = hash('sha256', serialize($data)); - - // Only invalidate tags if content has actually changed. - if ($currentHash === $hash) { - return; - } - $storage->set($key, $hash); - // Invalidate menu block instances. - $this->cacheTagsInvalidator->invalidateTags(['config:system.menu.' . $menuName]); - } - - /** - * Warm caches for all available external menus. - */ - public function warm() : void { - $plugin = new ExternalMenuBlock(); - $derives = array_keys($plugin->getDerivativeDefinitions([])); - $derives[] = 'main'; - - foreach ($this->languageManager->getLanguages() as $language) { - foreach ($derives as $name) { - try { - $response = $this->apiManager - ->withBypassCache() - ->get($language->getId(), $name); - $this->invalidateTags($response, $language->getId(), $name); - } - catch (\Exception) { - } - } - } - } - -} diff --git a/tests/src/Kernel/CacheWarmerTest.php b/tests/src/Kernel/CacheWarmerTest.php deleted file mode 100644 index 90ebb2a..0000000 --- a/tests/src/Kernel/CacheWarmerTest.php +++ /dev/null @@ -1,91 +0,0 @@ -populateConfiguration('Test'); - $this->setActiveProject(Project::ASUMINEN, EnvironmentEnum::Local); - $this->sharedTempStore = $this->container->get('tempstore.shared'); - } - - /** - * Constructs a new cache warmer instance. - * - * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator - * The cache invalidator service. - * - * @return \Drupal\helfi_navigation\CacheWarmer - * The cache warmer service. - */ - private function getCacheWarmer(CacheTagsInvalidatorInterface $invalidator) : CacheWarmer { - return new CacheWarmer( - $this->sharedTempStore, - $this->container->get('language_manager'), - $invalidator, - $this->container->get('helfi_navigation.api_manager'), - ); - } - - /** - * Tests cache warmer. - */ - public function testCacheWarmer() : void { - $invalidator = $this->prophesize(CacheTagsInvalidatorInterface::class); - $invalidator->invalidateTags(Argument::cetera()) - ->shouldBeCalled(); - - // Warm caches and make sure all tags are invalidated when nothing is - // populated yet. - $this->getCacheWarmer($invalidator->reveal())->warm(); - - // Warming caches again should not invalidate anything since hash - // hasn't changed. - $invalidator = $this->prophesize(CacheTagsInvalidatorInterface::class); - $invalidator->invalidateTags(Argument::cetera()) - ->shouldNotBeCalled(); - $this->getCacheWarmer($invalidator->reveal())->warm(); - - // Reset hash for finnish main menu and make sure main menu block is - // invalidated (once). - $this->sharedTempStore->get(CacheWarmer::STORAGE_KEY)->set('fi:main', ''); - $invalidator = $this->prophesize(CacheTagsInvalidatorInterface::class); - $invalidator->invalidateTags(['config:system.menu.main']) - ->shouldBeCalledTimes(1); - $this->getCacheWarmer($invalidator->reveal())->warm(); - } - -}