function BlockContentTranslationTest::testBlockContentTranslationAccess

Tests block access considers translation context.

File

core/modules/block_content/tests/src/Functional/BlockContentTranslationTest.php, line 46

Class

BlockContentTranslationTest
Tests block content translations.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testBlockContentTranslationAccess() : void {
  $block_content = $this->createBlockContent(save: FALSE);
  $block_content->set('body', [
    'value' => 'English block',
  ]);
  $block_content->setUnpublished();
  $block_content->save();
  $esTranslation = $block_content->addTranslation('es', $block_content->toArray());
  $esTranslation->set('body', [
    'value' => 'Spanish block',
  ]);
  $esTranslation->setPublished();
  $esTranslation->save();
  $this->placeBlock('block_content:' . $block_content->uuid());
  // English translation is unpublished, neither translation should display
  // on the english homepage.
  $this->drupalGet('<front>');
  $this->assertSession()
    ->pageTextNotContains('English block');
  $this->assertSession()
    ->pageTextNotContains('Spanish block');
  // Spanish translation is published, it should display on the spanish
  // homepage.
  $this->drupalGet('<front>', [
    'language' => ConfigurableLanguage::load('es'),
  ]);
  $this->assertSession()
    ->pageTextNotContains('English block');
  $this->assertSession()
    ->pageTextContains('Spanish block');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.