function ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle

@covers ::loadByEntityTypeBundle

@dataProvider providerLoadByEntityTypeBundle

File

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

Class

ContentLanguageSettingsUnitTest
@coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings[[api-linebreak]] @group language

Namespace

Drupal\Tests\language\Unit

Code

public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
  [$type, $bundle] = explode('.', $config_id);
  $nullConfig = new ContentLanguageSettings([
    'target_entity_type_id' => $type,
    'target_bundle' => $bundle,
  ], 'language_content_settings');
  $this->configEntityStorageInterface
    ->expects($this->any())
    ->method('load')
    ->with($config_id)
    ->willReturn($existing_config);
  $this->configEntityStorageInterface
    ->expects($this->any())
    ->method('create')
    ->willReturn($nullConfig);
  $this->entityTypeManager
    ->expects($this->any())
    ->method('getStorage')
    ->with('language_content_settings')
    ->willReturn($this->configEntityStorageInterface);
  $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
  $entity_type_repository->expects($this->any())
    ->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.