Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Sep 11, 2024
1 parent 7d22bc0 commit 18795e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions modules/helfi_etusivu_entities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 18795e9

Please sign in to comment.