Skip to content
Snippets Groups Projects

Resolve #3412398 "Fix failing tests"

Files
2
@@ -91,8 +91,23 @@ abstract class FieldDefaultsTestBase extends BrowserTestBase {
protected function createField($type = 'boolean', $cardinality = '1', $contentType = 'page') {
$this->drupalGet('admin/structure/types/manage/' . $contentType . '/fields');
// Go to the 'Add field' page.
$this->clickLink('Add field');
// In Drupal 10.2 version changed the form to add a new field to a content
// type and we have to take into it for tests for different core version.
// We follow the approach using in the DeprecationHelper class, but in our
// case changed UI not method or class. To correct pass test we'll search
// buttons by different label have to Drupal core version.
// @see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Component/Utility/DeprecationHelper.php
// Go to the 'Create a new field' page.
// The label of Save button change depend on Drupal core version.
$core_v = \Drupal::VERSION;
// Clicks on Add field button.
if (version_compare($core_v, '9.5', '<=')) {
$this->clickLink('Add field');
}
else {
$this->clickLink('Create a new field');
}
// Make a name for this field.
$field_name = strtolower($this->randomMachineName(10));
@@ -103,7 +118,22 @@ abstract class FieldDefaultsTestBase extends BrowserTestBase {
'field_name' => $field_name,
'label' => $field_name,
];
$this->submitForm($edit, 'Save and continue');
// Saves the first step Add a new Field form.
if (version_compare($core_v, '10.2', '<=')) {
$this->submitForm($edit, 'Save and continue');
}
if (version_compare($core_v, '10.2', '>=') && $type == 'boolean') {
$this->submitForm($edit, 'Continue');
}
if (version_compare($core_v, '10.2', '>=') && $type == 'plain_text') {
$this->submitForm($edit, 'Continue');
$edit += [
'group_field_options_wrapper' => 'string',
];
$this->submitForm($edit, 'Continue');
}
// Fill out the $cardinality form as if we're not using an unlimited values.
$edit = [
@@ -119,9 +149,12 @@ abstract class FieldDefaultsTestBase extends BrowserTestBase {
}
// And now we save the cardinality settings.
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("Updated field {$field_name} field settings.");
// In D10.2 cardinality settings was combined with description and
// saves as one step.
if (version_compare($core_v, '10.2', '<=')) {
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("Updated field {$field_name} field settings.");
}
// Save.
$this->submitForm([], 'Save settings');
$this->assertSession()->pageTextContains("Saved {$field_name} configuration.");
Loading