diff --git a/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php b/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php index c426add..1ff2be7 100644 --- a/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php +++ b/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\field_ui\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Provides common functionality for the Field UI test classes. */ @@ -26,13 +28,13 @@ * (optional) $edit parameter for drupalPostForm() on the third step ('Field * settings' form). */ - public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = array(), array $field_edit = array()) { + protected function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = [], array $field_edit = []) { $label = $label ?: $this->randomString(); - $initial_edit = array( + $initial_edit = [ 'new_storage_type' => $field_type, 'label' => $label, 'field_name' => $field_name, - ); + ]; // Allow the caller to set a NULL path in case they navigated to the right // page before calling this method. @@ -41,18 +43,18 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi } // First step: 'Add field' page. - $this->drupalPostForm($bundle_path, $initial_edit, t('Save and continue')); - $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Storage settings page was displayed.'); + $this->drupalPostForm($bundle_path, $initial_edit, 'Save and continue'); + $this->assertSession()->responseContains(new FormattableMarkup('These settings apply to the %label field everywhere it is used.', ['%label' => $label])); // Test Breadcrumbs. - $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.'); + $this->assertSession()->linkExists($label); // Second step: 'Storage settings' form. - $this->drupalPostForm(NULL, $storage_edit, t('Save field settings')); - $this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), 'Redirected to field settings page.'); + $this->drupalPostForm(NULL, $storage_edit, 'Save field settings'); + $this->assertSession()->responseContains(new FormattableMarkup('Updated field %label field settings.', ['%label' => $label])); // Third step: 'Field settings' form. - $this->drupalPostForm(NULL, $field_edit, t('Save settings')); - $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.'); + $this->drupalPostForm(NULL, $field_edit, 'Save settings'); + $this->assertSession()->responseContains(new FormattableMarkup('Saved %label configuration.', ['%label' => $label])); // Check that the field appears in the overview form. $this->assertSession()->elementExists('xpath', '//table[@id="field-overview"]//tr/td[1][text() = "' . $label . '"]'); @@ -72,25 +74,25 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi * (optional) $edit parameter for drupalPostForm() on the second step * ('Field settings' form). */ - public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = array()) { + protected function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = []) { $label = $label ?: $this->randomString(); - $initial_edit = array( + $initial_edit = [ 'existing_storage_name' => $existing_storage_name, 'existing_storage_label' => $label, - ); + ]; // First step: 'Re-use existing field' on the 'Add field' page. - $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue')); + $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, 'Save and continue'); // Set the main content to only the content region because the label can // contain HTML which will be auto-escaped by Twig. $main_content = $this->cssSelect('.region-content'); $this->setRawContent(reset($main_content)->asXml()); - $this->assertRaw('field-config-edit-form', 'The field config edit form is present.'); - $this->assertNoRaw('<', 'The page does not have double escaped HTML tags.'); + $this->assertSession()->responseContains('field-config-edit-form'); + $this->assertSession()->responseNotContains('<'); // Second step: 'Field settings' form. - $this->drupalPostForm(NULL, $field_edit, t('Save settings')); - $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.'); + $this->drupalPostForm(NULL, $field_edit, 'Save settings'); + $this->assertSession()->responseContains(new FormattableMarkup('Saved %label configuration.', ['%label' => $label])); // Check that the field appears in the overview form. $this->assertSession()->elementExists('xpath', '//table[@id="field-overview"]//tr/td[1][text() = "' . $label . '"]'); @@ -108,17 +110,17 @@ public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $l * @param string $bundle_label * The label of the bundle. */ - public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) { + protected function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) { // Display confirmation form. $this->drupalGet("$bundle_path/fields/$field_name/delete"); - $this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), 'Delete confirmation was found.'); + $this->assertSession()->responseContains(new FormattableMarkup('Are you sure you want to delete the field %label', ['%label' => $label])); // Test Breadcrumbs. - $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the field delete page.'); + $this->assertSession()->linkExists($label); // Submit confirmation form. - $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), 'Delete message was found.'); + $this->drupalPostForm(NULL, [], 'Delete'); + $this->assertSession()->responseContains(new FormattableMarkup('The field %label has been deleted from the %type content type.', ['%label' => $label, '%type' => $bundle_label])); // Check that the field does not appear in the overview form. $this->assertSession()->elementNotExists('xpath', '//table[@id="field-overview"]//tr/td[1][text() = "' . $label . '"]');