protected function ReadonlyFieldWidgetTest::setUp in Read-only Field Widget 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ ReadonlyFieldWidgetTest.php, line 43
Class
- ReadonlyFieldWidgetTest
- Tests Readonly Field Widget basic behaviour.
Namespace
Drupal\Tests\readonly_field_widget\FunctionalCode
protected function setUp() {
parent::setUp();
$this
->createContentType([
'name' => 'page',
'type' => 'page',
]);
$this
->createContentType([
'name' => 'article',
'type' => 'article',
]);
$tags_vocab = Vocabulary::create([
'vid' => 'tags',
'title' => 'Tags',
]);
$tags_vocab
->save();
$this->admin = $this
->createUser([], NULL, TRUE);
$this
->drupalLogin($this->admin);
// Add an article reference field.
$this
->drupalGet('/admin/structure/types/manage/page/fields/add-field');
$this
->submitForm([
'new_storage_type' => 'field_ui:entity_reference:node',
'label' => 'article reference',
'field_name' => 'article_reference',
], 'Save and continue');
$this
->submitForm([], 'Save field settings');
$this
->submitForm([
'settings[handler_settings][target_bundles][article]' => 'article',
], 'Save settings');
$this
->drupalGet('/admin/structure/types/manage/page/form-display');
$this
->submitForm([
'fields[field_article_reference][type]' => 'readonly_field_widget',
], 'Save');
$this
->submitForm([], 'field_article_reference_settings_edit');
$this
->submitForm([
'fields[field_article_reference][settings_edit_form][settings][label]' => 'above',
'fields[field_article_reference][settings_edit_form][settings][formatter_type]' => 'entity_reference_entity_view',
'fields[field_article_reference][settings_edit_form][settings][show_description]' => TRUE,
'fields[field_article_reference][settings_edit_form][settings][formatter_settings][entity_reference_entity_view][view_mode]' => 'default',
], 'Update');
$this
->submitForm([], 'Save');
// Add a taxonomy term reference field.
$this
->drupalGet('/admin/structure/types/manage/page/fields/add-field');
$this
->submitForm([
'new_storage_type' => 'field_ui:entity_reference:taxonomy_term',
'label' => 'term reference',
'field_name' => 'term_reference',
], 'Save and continue');
$this
->submitForm([], 'Save field settings');
$this
->submitForm([
'settings[handler_settings][target_bundles][tags]' => 'tags',
], 'Save settings');
$this
->drupalGet('/admin/structure/types/manage/page/form-display');
$this
->submitForm([
'fields[field_term_reference][type]' => 'readonly_field_widget',
], 'Save');
// Add a simple text field.
$this
->drupalGet('/admin/structure/types/manage/page/fields/add-field');
$this
->submitForm([
'new_storage_type' => 'string',
'label' => 'some plain text',
'field_name' => 'some_plain_text',
], 'Save and continue');
$this
->drupalGet('/admin/structure/types/manage/page/form-display');
$this
->submitForm([
'fields[field_some_plain_text][type]' => 'readonly_field_widget',
], 'Save');
$this
->submitForm([], 'field_some_plain_text_settings_edit');
$this
->submitForm([
'fields[field_some_plain_text][settings_edit_form][settings][label]' => 'above',
'fields[field_some_plain_text][settings_edit_form][settings][formatter_type]' => 'string',
'fields[field_some_plain_text][settings_edit_form][settings][show_description]' => TRUE,
'fields[field_some_plain_text][settings_edit_form][settings][formatter_settings][string][link_to_entity]' => TRUE,
], 'Update');
$this
->submitForm([], 'Save');
// Add a second text field.
$this
->drupalGet('/admin/structure/types/manage/page/fields/add-field');
$this
->submitForm([
'new_storage_type' => 'string',
'label' => 'restricted text',
'field_name' => 'restricted_text',
], 'Save and continue');
$this
->drupalGet('/admin/structure/types/manage/page/form-display');
$this
->submitForm([
'fields[field_restricted_text][type]' => 'readonly_field_widget',
'fields[title][type]' => 'readonly_field_widget',
], 'Save');
$this
->submitForm([], 'field_restricted_text_settings_edit');
$this
->submitForm([
'fields[field_restricted_text][settings_edit_form][settings][label]' => 'above',
'fields[field_restricted_text][settings_edit_form][settings][formatter_type]' => 'string',
'fields[field_restricted_text][settings_edit_form][settings][show_description]' => TRUE,
'fields[field_restricted_text][settings_edit_form][settings][formatter_settings][string][link_to_entity]' => TRUE,
], 'Update');
$this
->submitForm([], 'Save');
// Set the title to be read-only.
$this
->submitForm([
'fields[title][type]' => 'readonly_field_widget',
], 'Save');
$this
->submitForm([], 'title_settings_edit');
$this
->submitForm([
'fields[title][settings_edit_form][settings][label]' => 'inline',
'fields[title][settings_edit_form][settings][formatter_type]' => 'string',
'fields[title][settings_edit_form][settings][show_description]' => TRUE,
'fields[title][settings_edit_form][settings][formatter_settings][string][link_to_entity]' => FALSE,
], 'Update');
$this
->submitForm([], 'Save');
}