Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D10 fixes #65

Merged
merged 8 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
"ext-dom": "*"
},
"conflict": {
"drupal/helfi_tunnistamo": "<=2.2.1"
"drupal/helfi_tunnistamo": "<=2.2.1",
"drupal/core": "<10.1"
},
"extra": {
"patches": {
"drupal/core": {
"[#3385550] Language negotiation breaks updating Drupal 9 to 10": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-module-helfi-proxy/ffbde3654e0011e237a17ea1cb3a7291685e0c30/patches/3385550.patch"
}
}
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
Expand Down
16 changes: 16 additions & 0 deletions patches/3385550.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
index 133604df1b314ef54d054fbddaf81b2fe0e4b220..917e591171fb61076e8b3236bbb77855b54ebe31 100644
--- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
@@ -130,10 +130,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
}
$languages = array_flip(array_keys($this->languageManager->getLanguages()));
// Language can be passed as an option, or we go for current URL language.
- if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && in_array($options['language']->getId(), [
- LanguageInterface::LANGCODE_NOT_SPECIFIED,
- LanguageInterface::LANGCODE_NOT_APPLICABLE,
- ]))) {
+ if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && $options['language']->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED)) {
$language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL);
$options['language'] = $language_url;
}
7 changes: 0 additions & 7 deletions tests/src/Kernel/ActiveSitePrefixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Tests Active site prefix service.
*
* @coversDefaultClass \Drupal\helfi_proxy\ActiveSitePrefix
* @group helfi_proxy
*/
class ActiveSitePrefixTest extends KernelTestBase {
Expand All @@ -38,9 +37,6 @@ private function getSut() : ActiveSitePrefix {

/**
* Tests ::getPrefix() without proxy paths.
*
* @covers ::getPrefix
* @covers ::getPrefixes
*/
public function testEmptyPrefix() : void {
$this->assertEquals(NULL, $this->getSut()->getPrefix());
Expand All @@ -49,9 +45,6 @@ public function testEmptyPrefix() : void {

/**
* Tests ::getPrefix with proxy paths.
*
* @covers ::getPrefix
* @covers ::getPrefixes
*/
public function testPrefix() : void {
$prefixes = [
Expand Down
1 change: 0 additions & 1 deletion tests/src/Kernel/CorsResponseSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
* Tests CORS response subscriber.
*
* @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\CorsResponseSubscriber
* @group helfi_proxy
*/
class CorsResponseSubscriberTest extends KernelTestBase {
Expand Down
17 changes: 0 additions & 17 deletions tests/src/Kernel/ProxyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Tests Proxy manager.
*
* @coversDefaultClass \Drupal\helfi_proxy\ProxyManager
* @group helfi_proxy
*/
class ProxyManagerTest extends KernelTestBase {
Expand All @@ -37,10 +36,6 @@ private function proxyManager() : ProxyManager {

/**
* Tests instance prefixes.
*
* @covers ::getConfig
* @covers ::isConfigured
* @covers ::__construct
*/
public function testPrefixes() : void {
$this->assertFalse($this->proxyManager()->isConfigured(ProxyManagerInterface::PREFIXES));
Expand Down Expand Up @@ -75,10 +70,6 @@ private function setAssetPath(string $path) : void {

/**
* Tests tunnistamo return url.
*
* @covers ::getConfig
* @covers ::isConfigured
* @covers ::__construct
*/
public function testTunnistamoReturnUrl() : void {
$this->assertFalse($this->proxyManager()->isConfigured(ProxyManagerInterface::TUNNISTAMO_RETURN_URL));
Expand All @@ -94,10 +85,6 @@ public function testTunnistamoReturnUrl() : void {

/**
* Tests asset path.
*
* @covers ::getConfig
* @covers ::isConfigured
* @covers ::__construct
*/
public function testAssetPath() : void {
$this->assertFalse($this->proxyManager()->isConfigured(ProxyManagerInterface::ASSET_PATH));
Expand All @@ -109,10 +96,6 @@ public function testAssetPath() : void {

/**
* Tests process path.
*
* @covers ::isLocalAsset
* @covers ::getConfig
* @covers ::processPath
*/
public function testProcessPath() : void {
// Make sure nothing is done if asset path is not configured.
Expand Down
20 changes: 0 additions & 20 deletions tests/src/Kernel/RobotsResponseSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/**
* Tests robots response headers.
*
* @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\RobotsResponseSubscriber
* @group helfi_proxy
*/
class RobotsResponseSubscriberTest extends KernelTestBase {
Expand Down Expand Up @@ -86,11 +85,6 @@ private function assertResponseEventNoHeader(ResponseEvent $event) : void {

/**
* Tests that robots header is present when configuration is set.
*
* @covers ::robotsHeaderEnabled
* @covers ::onResponse
* @covers ::__construct
* @covers ::addRobotHeader
*/
public function testConfig() : void {
$this->config('helfi_proxy.settings')
Expand All @@ -111,10 +105,6 @@ public function testConfig() : void {

/**
* Tests that robots header is not present when no env variable is set.
*
* @covers ::robotsHeaderEnabled
* @covers ::onResponse
* @covers ::__construct
*/
public function testNoEnvVariable() : void {
$event = $this->getResponseEvent();
Expand All @@ -133,11 +123,6 @@ public function testNoEnvVariable() : void {

/**
* Tests that robots header is added when env variable is present.
*
* @covers ::robotsHeaderEnabled
* @covers ::onResponse
* @covers ::__construct
* @covers ::addRobotHeader
*/
public function testEnvVariable() : void {
putenv(RobotsResponseSubscriber::X_ROBOTS_TAG_HEADER_NAME . '=1');
Expand All @@ -148,11 +133,6 @@ public function testEnvVariable() : void {

/**
* Tests robots path handler.
*
* @covers ::robotsHeaderEnabled
* @covers ::onResponse
* @covers ::__construct
* @covers ::addRobotHeader
*/
public function testRobotsPaths() : void {
$this->config('helfi_proxy.settings')
Expand Down
17 changes: 0 additions & 17 deletions tests/src/Kernel/SessionConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/**
* Tests session configuration.
*
* @coversDefaultClass \Drupal\helfi_proxy\SessionConfiguration
* @group helfi_proxy
*/
class SessionConfigurationTest extends KernelTestBase {
Expand Down Expand Up @@ -51,11 +50,6 @@ public function setUp() : void {

/**
* Tests session suffix from configuration.
*
* @covers ::getOptions
* @covers ::getName
* @covers ::getSuffix
* @covers ::__construct
*/
public function testSessionNameConfig() : void {
$this->config('helfi_proxy.settings')
Expand All @@ -68,11 +62,6 @@ public function testSessionNameConfig() : void {

/**
* Tests session suffix from DRUPAL_SESSION_SUFFIX env variable.
*
* @covers ::getOptions
* @covers ::getName
* @covers ::getSuffix
* @covers ::__construct
*/
public function testSessionNameEnvVariable() : void {
putenv('DRUPAL_SESSION_SUFFIX=testlocal');
Expand All @@ -83,12 +72,6 @@ public function testSessionNameEnvVariable() : void {

/**
* Tests session suffix fallback.
*
* @covers ::getCleanHostname
* @covers ::getOptions
* @covers ::getName
* @covers ::getSuffix
* @covers ::__construct
*/
public function testSessionNameFallback() : void {
$options = $this->configuration->getOptions($this->requestStack->getCurrentRequest());
Expand Down
85 changes: 85 additions & 0 deletions tests/src/Kernel/SitePrefixPathProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests\helfi_proxy\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\remote_entity_test\Entity\RemoteEntityTest;
use Drupal\Tests\helfi_api_base\Traits\LanguageManagerTrait;

/**
* Tests Active site prefix service.
*
* @group helfi_proxy
*/
class SitePrefixPathProcessorTest extends KernelTestBase {

use LanguageManagerTrait;

/**
* {@inheritdoc}
*/
protected static $modules = [
'language',
'system',
'path_alias',
'content_translation',
'menu_link_content',
'user',
'helfi_language_negotiator_test',
'remote_entity_test',
'helfi_proxy',
];

/**
* The proxy prefixes.
*
* @var array
*/
protected array $prefixes = [
'sv' => 'prefix-sv',
'en' => 'prefix-en',
'fi' => 'prefix-fi',
'zxx' => 'prefix-zxx',
];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->setupLanguages();
$this->installEntitySchema('remote_entity_test');
$this->config('helfi_proxy.settings')
->set('prefixes', $this->prefixes)
->save();
$this->container->get('kernel')->rebuildContainer();
}

/**
* Tests prefixes with entity URL generation.
*/
public function testToUrl(): void {
$entity = RemoteEntityTest::create([
'id' => '1',
'title' => 'Test en',
'langcode' => 'en',
]);
$entity->save();

$entity->addTranslation('fi', [
'title' => 'Test fi',
])->addTranslation('sv', [
'title' => 'Test sv',
])->save();

foreach ($this->prefixes as $langcode => $prefix) {
$language = \Drupal::languageManager()->getLanguage($langcode);
$url = $entity->toUrl(options: ['language' => $language]);
$this->assertEquals(sprintf('/%s/rmt/1', $prefix), $url->toString());
}
}

}
1 change: 0 additions & 1 deletion tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/**
* Tests Tunnistamo redirect url subscriber.
*
* @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\TunnistamoRedirectUrlSubscriber
* @group helfi_proxy
*/
class TunnistamoRedirectUrlSubscriberTest extends KernelTestBase {
Expand Down
Loading