function ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle

Same name in other branches
  1. 9 core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()
  2. 8.9.x core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest::testLoadByEntityTypeBundle()
  3. 11.x 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 247

Class

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

Namespace

Drupal\Tests\language\Unit

Code

public function testLoadByEntityTypeBundle($config_id, ?ContentLanguageSettings $existing_config, $expected_langcode, $expected_language_alterable) : void {
    [
        $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->createMock(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.