function ConfigActionsTest::testConfigActions
Same name in this branch
- 11.x core/modules/media/tests/src/Kernel/ConfigActionsTest.php \Drupal\Tests\media\Kernel\ConfigActionsTest::testConfigActions()
- 11.x core/modules/language/tests/src/Kernel/ConfigActionsTest.php \Drupal\Tests\language\Kernel\ConfigActionsTest::testConfigActions()
- 11.x core/modules/contact/tests/src/Kernel/ConfigActionsTest.php \Drupal\Tests\contact\Kernel\ConfigActionsTest::testConfigActions()
- 11.x core/modules/node/tests/src/Kernel/ConfigActionsTest.php \Drupal\Tests\node\Kernel\ConfigActionsTest::testConfigActions()
- 11.x core/modules/image/tests/src/Kernel/ConfigActionsTest.php \Drupal\Tests\image\Kernel\ConfigActionsTest::testConfigActions()
File
-
core/
modules/ field/ tests/ src/ Kernel/ ConfigActionsTest.php, line 39
Class
- ConfigActionsTest
- @group field
Namespace
Drupal\Tests\field\KernelCode
public function testConfigActions() : void {
$field_storage = FieldStorageConfig::create([
'field_name' => 'test',
'type' => 'boolean',
'entity_type' => 'entity_test_with_bundle',
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'test',
]);
$field->save();
$this->assertTrue($field->isTranslatable());
$this->assertFalse($field->isRequired());
$this->assertSame('On', (string) $field->getSetting('on_label'));
$this->assertSame('Off', (string) $field->getSetting('off_label'));
$this->assertEmpty($field->getDefaultValueLiteral());
$this->configActionManager
->applyAction('entity_method:field.field:setLabel', $field->getConfigDependencyName(), 'Not what you were expecting!');
$this->configActionManager
->applyAction('entity_method:field.field:setDescription', $field->getConfigDependencyName(), "Any ol' nonsense can go here.");
$this->configActionManager
->applyAction('entity_method:field.field:setTranslatable', $field->getConfigDependencyName(), FALSE);
$this->configActionManager
->applyAction('entity_method:field.field:setRequired', $field->getConfigDependencyName(), TRUE);
$this->configActionManager
->applyAction('entity_method:field.field:setSettings', $field->getConfigDependencyName(), [
'on_label' => 'Zap!',
'off_label' => 'Zing!',
]);
$this->configActionManager
->applyAction('entity_method:field.field:setDefaultValue', $field->getConfigDependencyName(), [
'value' => FALSE,
]);
$field = FieldConfig::load($field->id());
$this->assertNotEmpty($field);
$this->assertSame('Not what you were expecting!', $field->getLabel());
$this->assertSame("Any ol' nonsense can go here.", $field->getDescription());
$this->assertFalse($field->isTranslatable());
$this->assertTrue($field->isRequired());
$this->assertSame('Zap!', $field->getSetting('on_label'));
$this->assertSame('Zing!', $field->getSetting('off_label'));
$this->assertSame([
[
'value' => 0,
],
], $field->getDefaultValueLiteral());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.