diff --git a/modules/helfi_etusivu_entities/README.md b/modules/helfi_etusivu_entities/README.md index ff0009477..412496245 100644 --- a/modules/helfi_etusivu_entities/README.md +++ b/modules/helfi_etusivu_entities/README.md @@ -3,6 +3,10 @@ Remote entities module allows fetching announcements from `Etusivu`-instance. It utilizes `json-api` and `external_entities`-module to transfer the data between instances. +## Language support + +If current language is not in [default languages](https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/default-languages.md), remote entities use fallback language. Alt languages show local announcements in current language (if translated) and in English. + ## How to set up locally Local setup requires Etusivu-instance to be up and running with some relevant data created to it. diff --git a/modules/helfi_etusivu_entities/tests/src/Functional/LocalEntitiesTest.php b/modules/helfi_etusivu_entities/tests/src/Functional/LocalEntitiesTest.php index 716ed9777..835b4b9a9 100644 --- a/modules/helfi_etusivu_entities/tests/src/Functional/LocalEntitiesTest.php +++ b/modules/helfi_etusivu_entities/tests/src/Functional/LocalEntitiesTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\helfi_etusivu_entities\Functional; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\node\NodeInterface; use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\BrowserTestBase; @@ -45,6 +46,8 @@ final class LocalEntitiesTest extends BrowserTestBase { public function setUp(): void { parent::setUp(); + ConfigurableLanguage::createFromLangcode('uk')->save(); + $this->testNode = $this->createNode([ 'status' => NodeInterface::PUBLISHED, 'type' => 'page', @@ -99,17 +102,32 @@ public function testBlocks(): void { 'type' => 'announcement', 'title' => 'Test announcement', 'body' => 'Announcement content', + 'field_announcement_type' => 'notification', 'langcode' => 'en', ]); - $this->drupalGet('/'); + $this->createNode([ + 'status' => NodeInterface::PUBLISHED, + 'type' => 'announcement', + 'title' => 'UK announcement (uk)', + 'body' => 'Announcement content', + 'field_announcement_type' => 'notification', + 'langcode' => 'uk', + ]); + $this->drupalGet('/'); $this->assertSession()->pageTextContains('Old test survey'); $this->assertSession()->pageTextNotContains('New test survey'); $this->assertSession()->pageTextContains('Test announcement'); - $this->drupalGet($this->testNode->toUrl()); + // Local announcements can be translated.pages + // English announcements are shown on alt language pages. + $this->drupalGet('/', ['language' => \Drupal::languageManager()->getLanguage('uk')]); + $this->assertSession()->pageTextContains('UK announcement'); + $this->assertSession()->pageTextContains('Test announcement'); + // Tests page filtering. + $this->drupalGet($this->testNode->toUrl()); $this->assertSession()->pageTextContains('New test survey'); $this->assertSession()->pageTextNotContains('Old test survey'); $this->assertSession()->pageTextContains('Test announcement');