-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from City-of-Helsinki/UHF-8570
UHF-8570: Improve test coverage
- Loading branch information
Showing
4 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_proxy\Kernel\Controller; | ||
|
||
use Drupal\helfi_proxy\Controller\FrontController; | ||
use Drupal\helfi_proxy\ProxyManagerInterface; | ||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\Tests\helfi_api_base\Traits\ApiTestTrait; | ||
|
||
/** | ||
* Tests Front controller. | ||
* | ||
* @group helfi_proxy | ||
*/ | ||
class FrontControllerTest extends KernelTestBase { | ||
|
||
use ApiTestTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'path_alias', | ||
'helfi_proxy', | ||
]; | ||
|
||
/** | ||
* Tests access. | ||
*/ | ||
public function testControllerAccess() : void { | ||
$request = $this->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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_proxy\Kernel\Plugin\DebugDataItem; | ||
|
||
use Drupal\helfi_proxy\Plugin\DebugDataItem\Robots; | ||
use Drupal\KernelTests\KernelTestBase; | ||
|
||
/** | ||
* Tests Robots debug data. | ||
* | ||
* @group helfi_proxy | ||
*/ | ||
class RobotsTest extends KernelTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'path_alias', | ||
'helfi_proxy', | ||
]; | ||
|
||
/** | ||
* Tests plugin when robot header setting is not enabled. | ||
*/ | ||
public function testDisabledHeader() : void { | ||
$sut = Robots::create($this->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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\helfi_proxy\Kernel; | ||
|
||
use Drupal\helfi_proxy\Cache\Context\SitePrefixCacheContext; | ||
use Drupal\KernelTests\KernelTestBase; | ||
|
||
/** | ||
* Tests Site prefix cache context. | ||
* | ||
* @group helfi_proxy | ||
*/ | ||
class SitePrefixCacheContextTest extends KernelTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'path_alias', | ||
'language', | ||
'helfi_proxy', | ||
]; | ||
|
||
/** | ||
* Tests without configured proxy prefixes. | ||
*/ | ||
public function testEmptyPrefix() : void { | ||
$sut = new SitePrefixCacheContext($this->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()); | ||
} | ||
|
||
} |