function ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle

Same name and namespace in other branches
  1. 10 core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()
  2. 11.x core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()
  3. 9 core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()
  4. 8.9.x core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()

Tests load by entity type bundle.

Attributes

#[DataProvider('providerLoadByEntityTypeBundle')]

File

core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php, line 268

Class

ContentLanguageSettingsUnitTest
Tests Drupal\language\Entity\ContentLanguageSettings.

Namespace

Drupal\Tests\language\Unit

Code

public function testLoadByEntityTypeBundle(string $config_id, ?ContentLanguageSettings $existing_config, string $expected_langcode, bool $expected_language_alterable) : void {
  $this->setUpMockConfigEntityStorage();
  $this->setUpMockEntityTypeManager();
  [$type, $bundle] = explode('.', $config_id);
  $nullConfig = new ContentLanguageSettings([
    'target_entity_type_id' => $type,
    'target_bundle' => $bundle,
  ], 'language_content_settings');
  $this->configEntityStorageInterface
    ->method('load')
    ->with($config_id)
    ->willReturn($existing_config);
  $this->configEntityStorageInterface
    ->method('create')
    ->willReturn($nullConfig);
  $this->entityTypeManager
    ->method('getStorage')
    ->with('language_content_settings')
    ->willReturn($this->configEntityStorageInterface);
  if ($existing_config === NULL) {
    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
    $entity_type_repository->expects($this->atLeastOnce())
      ->method('getEntityTypeFromClass')
      ->with(ContentLanguageSettings::class)
      ->willReturn('language_content_settings');
    \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
  }
  $config = ContentLanguageSettings::loadByEntityTypeBundle($type, $bundle);
  $this->assertSame($expected_langcode, $config->getDefaultLangcode());
  $this->assertSame($expected_language_alterable, $config->isLanguageAlterable());
}

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