diff --git a/src/Cache/Context/SitePrefixCacheContext.php b/src/Cache/Context/SitePrefixCacheContext.php index e497ac6..727b6a2 100644 --- a/src/Cache/Context/SitePrefixCacheContext.php +++ b/src/Cache/Context/SitePrefixCacheContext.php @@ -35,21 +35,21 @@ public static function getLabel() : string { /** * {@inheritdoc} */ - public function getContext($prefix = NULL) : string { + public function getContext($parameter = NULL) : string { $prefixes = $this->sitePrefix->getPrefixes(); - if ($prefix === NULL) { + if ($parameter === NULL) { return implode(',', $prefixes); } - return isset($prefixes[$prefix]) ? '1' : '0'; + return isset($prefixes[$parameter]) ? '1' : '0'; } /** * {@inheritdoc} */ - public function getCacheableMetadata($prefix = NULL) : CacheableMetadata { - return (new CacheableMetadata())->setCacheTags(['site_prefix:' . $prefix]); + public function getCacheableMetadata($parameter = NULL) : CacheableMetadata { + return (new CacheableMetadata())->setCacheTags(['site_prefix:' . $parameter]); } } diff --git a/tests/src/Kernel/Controller/FrontControllerTest.php b/tests/src/Kernel/Controller/FrontControllerTest.php new file mode 100644 index 0000000..6473a49 --- /dev/null +++ b/tests/src/Kernel/Controller/FrontControllerTest.php @@ -0,0 +1,61 @@ +getMockedRequest('/front'); + $response = $this->processRequest($request); + $this->assertEquals(200, $response->getStatusCode()); + } + + /** + * Tests build cache tags. + */ + public function testBuildCacheTags() : void { + $sut = FrontController::create($this->container); + $build = $sut->index(); + $this->assertArrayHasKey('content', $build); + $this->assertEquals(['config:helfi_proxy.settings'], $build['content']['#cache']['tags']); + } + + /** + * Tests page title. + */ + public function testTitle() : void { + $sut = FrontController::create($this->container); + $this->assertEquals('Front', $sut->title()); + + $this->config('helfi_proxy.settings') + ->set(ProxyManagerInterface::FRONT_PAGE_TITLE, 'Title test') + ->save(); + $this->assertEquals('Title test', $sut->title()); + } + +} diff --git a/tests/src/Kernel/Plugin/DebugDataItem/RobotsTest.php b/tests/src/Kernel/Plugin/DebugDataItem/RobotsTest.php new file mode 100644 index 0000000..e305cec --- /dev/null +++ b/tests/src/Kernel/Plugin/DebugDataItem/RobotsTest.php @@ -0,0 +1,44 @@ +container, [], 'robots', []); + $this->assertEquals(['DRUPAL_X_ROBOTS_TAG_HEADER' => FALSE], $sut->collect()); + } + + /** + * Tests plugin when robot header setting is enabled. + */ + public function testHeader() : void { + $this->config('helfi_proxy.settings') + ->set('robots_header_enabled', TRUE) + ->save(); + $sut = Robots::create($this->container, [], 'robots', []); + $this->assertEquals(['DRUPAL_X_ROBOTS_TAG_HEADER' => TRUE], $sut->collect()); + } + +} diff --git a/tests/src/Kernel/SitePrefixCacheContextTest.php b/tests/src/Kernel/SitePrefixCacheContextTest.php new file mode 100644 index 0000000..41d94a9 --- /dev/null +++ b/tests/src/Kernel/SitePrefixCacheContextTest.php @@ -0,0 +1,57 @@ +container->get('helfi_proxy.active_prefix')); + $this->assertEquals('', $sut->getContext(NULL)); + $this->assertEquals('0', $sut->getContext('en')); + $this->assertEquals(['site_prefix:'], $sut->getCacheableMetadata(NULL)->getCacheTags()); + $this->assertEquals(['site_prefix:en'], $sut->getCacheableMetadata('en')->getCacheTags()); + } + + /** + * Tests with configured proxy prefixes. + */ + public function testWithActivePrefix() : void { + $this->config('helfi_proxy.settings') + ->set('prefixes', [ + 'sv' => 'sv', + 'en' => 'en', + 'fi' => 'fi', + ]) + ->save(); + $this->container->get('kernel')->rebuildContainer(); + + $sut = new SitePrefixCacheContext($this->container->get('helfi_proxy.active_prefix')); + $this->assertEquals('sv,en,fi', $sut->getContext(NULL)); + $this->assertEquals('1', $sut->getContext('en')); + $this->assertEquals(['site_prefix:'], $sut->getCacheableMetadata(NULL)->getCacheTags()); + $this->assertEquals(['site_prefix:en'], $sut->getCacheableMetadata('en')->getCacheTags()); + } + +}