From 0e80ad191a22df7278f8b5d27670e35019bb9cce Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:00:41 +0200 Subject: [PATCH 1/8] Stash --- .../Kernel/SitePrefixPathProcessorTest.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/src/Kernel/SitePrefixPathProcessorTest.php diff --git a/tests/src/Kernel/SitePrefixPathProcessorTest.php b/tests/src/Kernel/SitePrefixPathProcessorTest.php new file mode 100644 index 0000000..a6ccfab --- /dev/null +++ b/tests/src/Kernel/SitePrefixPathProcessorTest.php @@ -0,0 +1,85 @@ + '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()); + } + } + +} From 41b56a91f3fe130ae6d0f82420cca2023c71e7f4 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:17:20 +0200 Subject: [PATCH 2/8] Patch core --- composer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/composer.json b/composer.json index 2326c12..b26bb65 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,13 @@ "conflict": { "drupal/helfi_tunnistamo": "<=2.2.1" }, + "extra": { + "patches": { + "drupal/core": { + "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "https://www.drupal.org/files/issues/2023-09-18/3385550-9.patch" + } + } + }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "drupal/coder": "^8.3", From ffbde3654e0011e237a17ea1cb3a7291685e0c30 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:22:04 +0200 Subject: [PATCH 3/8] Local patch --- composer.json | 2 +- patches/3385550.patch | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 patches/3385550.patch diff --git a/composer.json b/composer.json index b26bb65..0321b9e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "extra": { "patches": { "drupal/core": { - "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "https://www.drupal.org/files/issues/2023-09-18/3385550-9.patch" + "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "./patches/338550.patch" } } }, diff --git a/patches/3385550.patch b/patches/3385550.patch new file mode 100644 index 0000000..57d6f3e --- /dev/null +++ b/patches/3385550.patch @@ -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; + } From f3108f46ae8a22ea0b7cef9854d8ee5144ff9a2e Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:23:22 +0200 Subject: [PATCH 4/8] Fixed path --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0321b9e..7578fa4 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "extra": { "patches": { "drupal/core": { - "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "./patches/338550.patch" + "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "patches/338550.patch" } } }, From 643a27a2190115d535982bb3843ee9c56a95c9d7 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:25:16 +0200 Subject: [PATCH 5/8] Install patch from git --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7578fa4..fbfa5be 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "extra": { "patches": { "drupal/core": { - "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "patches/338550.patch" + "[#3385550] Language negotiation breaks updating Drupal 9 to 10": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-module-helfi-proxy/ffbde3654e0011e237a17ea1cb3a7291685e0c30/patches/3385550.patch" } } }, From bcf85bb16316e5d2f9a1c36c9da1f08906629d20 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:30:02 +0200 Subject: [PATCH 6/8] Require 10.1 core --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fbfa5be..68b0093 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "ext-dom": "*" }, "conflict": { - "drupal/helfi_tunnistamo": "<=2.2.1" + "drupal/helfi_tunnistamo": "<=2.2.1", + "drupal/core": "<10.1" }, "extra": { "patches": { From 3523bb4ba4b96b93a504db9983f2ad359e6b7962 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:33:32 +0200 Subject: [PATCH 7/8] Remove covers annotations --- tests/src/Kernel/ActiveSitePrefixTest.php | 7 ------- .../src/Kernel/CorsResponseSubscriberTest.php | 1 - tests/src/Kernel/ProxyManagerTest.php | 17 ---------------- .../Kernel/RobotsResponseSubscriberTest.php | 20 ------------------- tests/src/Kernel/SessionConfigurationTest.php | 17 ---------------- .../TunnistamoRedirectUrlSubscriberTest.php | 1 - 6 files changed, 63 deletions(-) diff --git a/tests/src/Kernel/ActiveSitePrefixTest.php b/tests/src/Kernel/ActiveSitePrefixTest.php index 5a3fe43..05f9046 100644 --- a/tests/src/Kernel/ActiveSitePrefixTest.php +++ b/tests/src/Kernel/ActiveSitePrefixTest.php @@ -11,7 +11,6 @@ /** * Tests Active site prefix service. * - * @coversDefaultClass \Drupal\helfi_proxy\ActiveSitePrefix * @group helfi_proxy */ class ActiveSitePrefixTest extends KernelTestBase { @@ -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()); @@ -49,9 +45,6 @@ public function testEmptyPrefix() : void { /** * Tests ::getPrefix with proxy paths. - * - * @covers ::getPrefix - * @covers ::getPrefixes */ public function testPrefix() : void { $prefixes = [ diff --git a/tests/src/Kernel/CorsResponseSubscriberTest.php b/tests/src/Kernel/CorsResponseSubscriberTest.php index 02de20a..d48b22d 100644 --- a/tests/src/Kernel/CorsResponseSubscriberTest.php +++ b/tests/src/Kernel/CorsResponseSubscriberTest.php @@ -10,7 +10,6 @@ /** * Tests CORS response subscriber. * - * @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\CorsResponseSubscriber * @group helfi_proxy */ class CorsResponseSubscriberTest extends KernelTestBase { diff --git a/tests/src/Kernel/ProxyManagerTest.php b/tests/src/Kernel/ProxyManagerTest.php index 63ce3cd..943d6a6 100644 --- a/tests/src/Kernel/ProxyManagerTest.php +++ b/tests/src/Kernel/ProxyManagerTest.php @@ -11,7 +11,6 @@ /** * Tests Proxy manager. * - * @coversDefaultClass \Drupal\helfi_proxy\ProxyManager * @group helfi_proxy */ class ProxyManagerTest extends KernelTestBase { @@ -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)); @@ -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)); @@ -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)); @@ -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. diff --git a/tests/src/Kernel/RobotsResponseSubscriberTest.php b/tests/src/Kernel/RobotsResponseSubscriberTest.php index 4439412..a8b9abb 100644 --- a/tests/src/Kernel/RobotsResponseSubscriberTest.php +++ b/tests/src/Kernel/RobotsResponseSubscriberTest.php @@ -15,7 +15,6 @@ /** * Tests robots response headers. * - * @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\RobotsResponseSubscriber * @group helfi_proxy */ class RobotsResponseSubscriberTest extends KernelTestBase { @@ -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') @@ -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(); @@ -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'); @@ -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') diff --git a/tests/src/Kernel/SessionConfigurationTest.php b/tests/src/Kernel/SessionConfigurationTest.php index b427376..c07308a 100644 --- a/tests/src/Kernel/SessionConfigurationTest.php +++ b/tests/src/Kernel/SessionConfigurationTest.php @@ -13,7 +13,6 @@ /** * Tests session configuration. * - * @coversDefaultClass \Drupal\helfi_proxy\SessionConfiguration * @group helfi_proxy */ class SessionConfigurationTest extends KernelTestBase { @@ -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') @@ -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'); @@ -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()); diff --git a/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php b/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php index 563c494..f85b1f9 100644 --- a/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php +++ b/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php @@ -17,7 +17,6 @@ /** * Tests Tunnistamo redirect url subscriber. * - * @coversDefaultClass \Drupal\helfi_proxy\EventSubscriber\TunnistamoRedirectUrlSubscriber * @group helfi_proxy */ class TunnistamoRedirectUrlSubscriberTest extends KernelTestBase { From 819995ea4412c720822b0f60c7930351130fd450 Mon Sep 17 00:00:00 2001 From: tuutti Date: Tue, 7 Nov 2023 10:46:13 +0200 Subject: [PATCH 8/8] Install simple_sitemap module --- .github/workflows/ci.yml | 2 +- phpunit.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b986b3e..68b6bba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: # phpunit. Copy .git folder manually so codecov can generate line by # line coverage. cp -r $GITHUB_WORKSPACE/.git $MODULE_FOLDER/ - composer require drupal/redirect drupal/helfi_tunnistamo -W + composer require drupal/redirect drupal/helfi_tunnistamo drupal/simple_sitemap -W - name: Install Drupal working-directory: ${{ env.DRUPAL_ROOT }} diff --git a/phpunit.xml b/phpunit.xml index 4851550..9375c00 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,11 +4,11 @@ colors="true" cacheResultFile=".phpunit.cache/test-results" executionOrder="depends,defects" - forceCoversAnnotation="true" + forceCoversAnnotation="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" - beStrictAboutCoversAnnotation="true" + beStrictAboutCoversAnnotation="false" printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" failOnRisky="true" failOnWarning="true"