function TextItemBaseTest::testApplyDefaultValueFormat
Same name and namespace in other branches
- 11.x core/modules/text/tests/src/Kernel/TextItemBaseTest.php \Drupal\Tests\text\Kernel\TextItemBaseTest::testApplyDefaultValueFormat()
Tests applyDefaultValue respects allowed_formats.
@legacy-covers ::applyDefaultValue
Attributes
#[DataProvider('providerApplyDefaultValueFormat')]
File
-
core/
modules/ text/ tests/ src/ Kernel/ TextItemBaseTest.php, line 112
Class
- TextItemBaseTest
- Tests TextItemBase.
Namespace
Drupal\Tests\text\KernelCode
public function testApplyDefaultValueFormat(array $formats, string $expected_format) : void {
$this->installConfig([
'filter',
]);
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
$this->assertSame('plain_text', \Drupal::service(FilterFormatRepositoryInterface::class)->getFallbackFormatId());
foreach ($formats as $format_id) {
if ($format_id === 'plain_text') {
continue;
}
FilterFormat::create([
'format' => $format_id,
'name' => $format_id,
])->save();
}
$field_name = $this->randomMachineName();
FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text',
])->save();
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => [
'allowed_formats' => $formats,
],
])->save();
$entity = \Drupal::entityTypeManager()->getStorage('entity_test')
->create();
$item = $entity->get($field_name)
->appendItem();
$item->applyDefaultValue();
$this->assertSame($expected_format, $item->format);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.