You are here

public function ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()

@covers ::loadByEntityTypeBundle

@dataProvider providerLoadByEntityTypeBundle

File

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

Class

ContentLanguageSettingsUnitTest
@coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings @group language

Namespace

Drupal\Tests\language\Unit

Code

public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
  list($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)
    ->will($this
    ->returnValue($existing_config));
  $this->configEntityStorageInterface
    ->expects($this
    ->any())
    ->method('create')
    ->will($this
    ->returnValue($nullConfig));
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('language_content_settings')
    ->will($this
    ->returnValue($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());
}