public function EditPageTest::setUp in Require on Publish 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ FunctionalJavascript/ EditPageTest.php, line 51
Class
- EditPageTest
- Tests Require on Publish functionality on the entity edit page.
Namespace
Drupal\Tests\require_on_publish\FunctionalJavascriptCode
public function setUp() : void {
parent::setUp();
$bundle = 'article';
/** @var \Drupal\node\NodeTypeInterface $type */
$type = $this->container
->get('entity_type.manager')
->getStorage('node_type')
->create([
'type' => $bundle,
'name' => 'Article',
]);
$type
->save();
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form */
$entity_form = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->create([
'targetEntityType' => 'node',
'bundle' => $bundle,
'mode' => 'default',
'status' => TRUE,
]);
$node_base_field_definitions = $this->container
->get('entity_field.manager')
->getBaseFieldDefinitions('node');
$blacklisted_field_types = [
'file_uri',
'entity_reference',
'language',
];
$field_type_plugin_manager = $this->container
->get('plugin.manager.field.field_type');
foreach ($this->container
->get('plugin.manager.field.widget')
->getDefinitions() as $widget) {
foreach ($widget['field_types'] as $field_type) {
if (in_array($field_type, $blacklisted_field_types)) {
continue;
}
if (in_array($field_type, array_keys($node_base_field_definitions))) {
continue;
}
$field_name = $widget['id'] . '__' . $field_type;
$field_id = substr($field_name, 0, 32);
FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => $field_id,
'type' => $field_type,
'settings' => $field_type_plugin_manager
->getDefaultStorageSettings($field_type),
])
->save();
$field_config = FieldConfig::create([
'field_name' => $field_id,
'label' => $field_name,
'entity_type' => 'node',
'bundle' => $bundle,
'third_party_settings' => [
'require_on_publish' => [
'require_on_publish' => TRUE,
],
],
])
->save();
$entity_form
->setComponent($field_id, [
'type' => $widget['id'],
])
->save();
}
}
drupal_flush_all_caches();
$this->account = $this
->drupalCreateUser([
'create article content',
]);
}