From f91d0a01ed262b10508b461e4ad9b97076099b97 Mon Sep 17 00:00:00 2001 From: Adam Bramley <46227-acbramley@users.noreply.drupalcode.org> Date: Thu, 11 Apr 2024 08:45:43 +0000 Subject: [PATCH] Issue #3439808 by acbramley, jibran: Fix tests on HEAD --- .../DynamicEntityReferenceBaseTest.php | 45 +++++------ ...icEntityReferenceFieldDefaultValueTest.php | 2 +- .../Functional/DynamicEntityReferenceTest.php | 76 +++++++++---------- .../DynamicEntityReferenceWidgetTest.php | 24 ++---- .../DynamicEntityReferenceTest.php | 2 +- 5 files changed, 63 insertions(+), 86 deletions(-) diff --git a/tests/src/Functional/DynamicEntityReferenceBaseTest.php b/tests/src/Functional/DynamicEntityReferenceBaseTest.php index 187cae8..5b7a217 100644 --- a/tests/src/Functional/DynamicEntityReferenceBaseTest.php +++ b/tests/src/Functional/DynamicEntityReferenceBaseTest.php @@ -104,7 +104,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { 'user_id[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $entities = \Drupal::entityTypeManager() ->getStorage('entity_test') ->loadByProperties([ @@ -126,7 +126,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { // Remove one child. 'dynamic_references[0][target_id]' => '', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. @@ -152,11 +152,11 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { $edit = [ 'dynamic_references[0][target_id]' => 'duplicate label', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); // We don't know the order in which the entities will be listed, so just // assert parts and make sure both are shown. - $error_message = t('Multiple test entity entities match this reference;'); + $error_message = 'Multiple test entity entities match this reference;'; $assert_session->responseContains($error_message); $assert_session->responseContains($labels[0]); $assert_session->responseContains($labels[1]); @@ -172,15 +172,11 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { } // Submit again with the same values. - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); - $params = [ - '%value' => 'duplicate label', - ]; // We don't know which id it will display, so just assert a part of the // error. - $error_message = t('Many test entity entities are called %value. Specify the one you want by appending the id in parentheses', $params); - $assert_session->responseContains($error_message); + $assert_session->pageTextContains('Many test entity entities are called duplicate label. Specify the one you want by appending the id in parentheses'); // Submit with a label that does not match anything. // Now try to submit and just specify the label. @@ -188,8 +184,8 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { $edit = [ 'dynamic_references[0][target_id]' => 'does not exist', ]; - $this->submitForm($edit, t('Save')); - $assert_session->responseContains(t('There are no test entity entities matching "%value".', ['%value' => 'does not exist'])); + $this->submitForm($edit, 'Save'); + $assert_session->pageTextContains('There are no test entity entities matching "does not exist".'); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $edit = [ @@ -197,7 +193,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { // Reference itself. 'dynamic_references[0][target_id]' => 'Bazbar (' . $entity->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. @@ -262,7 +258,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { 'user_id[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $entities = \Drupal::entityTypeManager() ->getStorage('entity_test') ->loadByProperties(['name' => 'Barfoo']); @@ -284,7 +280,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { // Remove one child. 'dynamic_references[1][target_id]' => '', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. @@ -310,12 +306,11 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { $edit = [ 'dynamic_references[1][target_id]' => 'duplicate label', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); // We don't know the order in which the entities will be listed, so just // assert parts and make sure both are shown. - $error_message = t('Multiple test entity entities match this reference;'); - $assert_session->responseContains($error_message); + $assert_session->responseContains('Multiple test entity entities match this reference;'); $assert_session->responseContains($labels[0]); $assert_session->responseContains($labels[1]); @@ -330,15 +325,11 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { } // Submit again with the same values. - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); - $params = [ - '%value' => 'duplicate label', - ]; // We don't know which id it will display, so just assert a part of the // error. - $error_message = t('Many test entity entities are called %value. Specify the one you want by appending the id in parentheses', $params); - $assert_session->responseContains($error_message); + $assert_session->pageTextContains('Many test entity entities are called duplicate label. Specify the one you want by appending the id in parentheses'); // Submit with a label that does not match anything. // Now try to submit and just specify the label. @@ -346,8 +337,8 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { $edit = [ 'dynamic_references[1][target_id]' => 'does not exist', ]; - $this->submitForm($edit, t('Save')); - $assert_session->responseContains(t('There are no test entity entities matching "%value".', ['%value' => 'does not exist'])); + $this->submitForm($edit, 'Save'); + $assert_session->pageTextContains('There are no test entity entities matching "does not exist".'); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $edit = [ @@ -355,7 +346,7 @@ class DynamicEntityReferenceBaseTest extends BrowserTestBase { // Reference itself. 'dynamic_references[1][target_id]' => 'Bazbar (' . $entity->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. diff --git a/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php b/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php index 6b20fdd..07e0ac4 100644 --- a/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php +++ b/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php @@ -118,7 +118,7 @@ class DynamicEntityReferenceFieldDefaultValueTest extends BrowserTestBase { 'default_value_input[' . $field_name . '][0][target_id]' => $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')', ]; $this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name); - $this->submitForm($field_edit, t('Save settings')); + $this->submitForm($field_edit, 'Save settings'); $field_config = \Drupal::entityTypeManager()->getStorage('field_config')->loadUnchanged($field_config->id()); $default_value = $field_config->getDefaultValueLiteral(); $this->assertNotEmpty($default_value); diff --git a/tests/src/Functional/DynamicEntityReferenceTest.php b/tests/src/Functional/DynamicEntityReferenceTest.php index 508b5be..771dfa2 100644 --- a/tests/src/Functional/DynamicEntityReferenceTest.php +++ b/tests/src/Functional/DynamicEntityReferenceTest.php @@ -146,9 +146,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'group_field_options_wrapper' => 'dynamic_entity_reference', 'label' => 'Foobar', 'field_name' => 'foobar', - ], t('Continue')); + ], 'Continue'); $field_name = 'field_storage[subform][settings][entity_type_ids][]'; - $button_label = t('Save settings'); + $button_label = 'Save settings'; $cardinality_field = 'field_storage[subform][cardinality]'; $additions += $edit; $edit_path = 'entity_test/structure/entity_test/fields/entity_test.entity_test.field_foobar'; @@ -160,9 +160,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'label' => 'Foobar', 'field_name' => 'foobar', 'new_storage_type' => 'dynamic_entity_reference', - ], t('Save and continue')); + ], 'Save and continue'); $field_name = 'settings[entity_type_ids][]'; - $button_label = t('Save field settings'); + $button_label = 'Save field settings'; $cardinality_field = 'cardinality'; $exclude_field_name = 'settings[exclude_entity_types]'; } @@ -170,13 +170,13 @@ class DynamicEntityReferenceTest extends BrowserTestBase { $assert_session->optionNotExists($field_name, 'settings[entity_test_no_id][handler_settings][target_bundles][entity_test_string_id]'); $assert_session->fieldExists($cardinality_field)->setValue(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); $assert_session->fieldExists($field_name)->setValue(['user', 'entity_test_label']); - $assert_session->buttonExists(t('Update settings'))->click(); + $assert_session->buttonExists('Update settings')->click(); $assert_session->fieldExists('default_value_input[field_foobar][0][target_type]'); $assert_session->optionExists('default_value_input[field_foobar][0][target_type]', 'entity_test'); $assert_session->optionNotExists('default_value_input[field_foobar][0][target_type]', 'user'); $this->submitForm($additions, $button_label); - $assert_session->responseContains(t('Saved %name configuration', ['%name' => 'Foobar'])); + $assert_session->pageTextContains('Saved Foobar configuration'); $excluded_entity_type_ids = FieldStorageConfig::loadByName('entity_test', 'field_foobar') ->getSetting('entity_type_ids'); $this->assertNotNull($excluded_entity_type_ids); @@ -215,8 +215,8 @@ class DynamicEntityReferenceTest extends BrowserTestBase { $edit = [ 'settings[entity_test_label][handler_settings][target_bundles][entity_test_label]' => 'entity_test_label', ]; - $this->submitForm($edit, t('Save settings')); - $assert_session->responseContains(t('Saved %name configuration', ['%name' => 'Foobar'])); + $this->submitForm($edit, 'Save settings'); + $assert_session->pageTextContains('Saved Foobar configuration'); $excluded_entity_type_ids = FieldStorageConfig::loadByName('entity_test', 'field_foobar') ->getSetting('entity_type_ids'); $this->assertNotNull($excluded_entity_type_ids); @@ -232,7 +232,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'set_default_value' => '1', 'default_value_input[field_foobar][0][target_type]' => 'user', 'default_value_input[field_foobar][0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', - ], t('Save settings')); + ], 'Save settings'); $field_config = FieldConfig::loadByName('entity_test', 'entity_test', 'field_foobar')->toArray(); $this->assertEquals($field_config['default_value']['0'], [ @@ -257,9 +257,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'group_field_options_wrapper' => 'dynamic_entity_reference', 'label' => 'Foobar', 'field_name' => 'foobar', - ], t('Continue')); + ], 'Continue'); $field_name = 'field_storage[subform][settings][entity_type_ids][]'; - $button_label = t('Save settings'); + $button_label = 'Save settings'; $cardinality_field = 'field_storage[subform][cardinality]'; } else { @@ -267,9 +267,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'label' => 'Foobar', 'field_name' => 'foobar', 'new_storage_type' => 'dynamic_entity_reference', - ], t('Save and continue')); + ], 'Save and continue'); $field_name = 'settings[entity_type_ids][]'; - $button_label = t('Save field settings'); + $button_label = 'Save field settings'; $cardinality_field = 'cardinality'; } $assert_session->optionNotExists($field_name, 'settings[entity_test_no_id][handler_settings][target_bundles][entity_test_no_id]'); @@ -294,8 +294,8 @@ class DynamicEntityReferenceTest extends BrowserTestBase { } } } - $this->submitForm($edit, t('Save settings')); - $assert_session->responseContains(t('Saved %name configuration', ['%name' => 'Foobar'])); + $this->submitForm($edit, 'Save settings'); + $assert_session->pageTextContains('Saved Foobar configuration'); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions(); // Create some items to reference. @@ -347,7 +347,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'user_id[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $entities = \Drupal::entityTypeManager() ->getStorage('entity_test') ->loadByProperties(['name' => 'Barfoo']); @@ -394,7 +394,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { // Remove one child. 'field_foobar[2][target_id]' => '', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. @@ -420,12 +420,11 @@ class DynamicEntityReferenceTest extends BrowserTestBase { $edit = [ 'field_foobar[1][target_id]' => 'duplicate label', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); // We don't know the order in which the entities will be listed, so just // assert parts and make sure both are shown. - $error_message = t('Multiple test entity entities match this reference;'); - $assert_session->responseContains($error_message); + $assert_session->responseContains('Multiple test entity entities match this reference;'); $assert_session->responseContains($labels[0]); $assert_session->responseContains($labels[1]); @@ -440,15 +439,11 @@ class DynamicEntityReferenceTest extends BrowserTestBase { } // Submit again with the same values. - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); - $params = [ - '%value' => 'duplicate label', - ]; // We don't know which id it will display, so just assert a part of the // error. - $error_message = t('Many test entity entities are called %value. Specify the one you want by appending the id in parentheses', $params); - $assert_session->responseContains($error_message); + $assert_session->pageTextContains('Many test entity entities are called duplicate label. Specify the one you want by appending the id in parentheses'); // Submit with a label that does not match anything. // Now try to submit and just specify the label. @@ -456,9 +451,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { $edit = [ 'field_foobar[1][target_id]' => 'does not exist', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); - $assert_session->responseContains(t('There are no test entity entities matching "%value".', ['%value' => 'does not exist'])); + $assert_session->pageTextContains('There are no test entity entities matching "does not exist".'); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $edit = [ @@ -466,7 +461,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { // Reference itself. 'field_foobar[1][target_id]' => 'Bazbar (' . $entity->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $this->drupalGet('entity_test/' . $entity->id()); $assert_session->pageTextContains('Bazbar'); // Reload entity. @@ -512,9 +507,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'group_field_options_wrapper' => 'dynamic_entity_reference', 'label' => 'Foobar', 'field_name' => 'foobar', - ], t('Continue')); + ], 'Continue'); $field_name = 'field_storage[subform][settings][entity_type_ids][]'; - $button_label = t('Save settings'); + $button_label = 'Save settings'; $cardinality_field = 'field_storage[subform][cardinality]'; $exclude_field_name = 'field_storage[subform][settings][exclude_entity_types]'; } @@ -523,9 +518,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'label' => 'Foobar', 'field_name' => 'foobar', 'new_storage_type' => 'dynamic_entity_reference', - ], t('Save and continue')); + ], 'Save and continue'); $field_name = 'settings[entity_type_ids][]'; - $button_label = t('Save field settings'); + $button_label = 'Save field settings'; $cardinality_field = 'cardinality'; $exclude_field_name = 'settings[exclude_entity_types]'; } @@ -555,7 +550,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'user_id[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $entities = \Drupal::entityTypeManager() ->getStorage('entity_test') @@ -622,9 +617,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'group_field_options_wrapper' => 'dynamic_entity_reference', 'label' => 'Foobar', 'field_name' => 'der', - ], t('Continue')); + ], 'Continue'); $field_name = 'field_storage[subform][settings][entity_type_ids][]'; - $button_label = t('Save settings'); + $button_label = 'Save settings'; $cardinality_field = 'field_storage[subform][cardinality]'; $exclude_field_name = 'field_storage[subform][settings][exclude_entity_types]'; $additional = $edit; @@ -634,9 +629,9 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'label' => 'Foobar', 'field_name' => 'der', 'new_storage_type' => 'dynamic_entity_reference', - ], t('Save and continue')); + ], 'Save and continue'); $field_name = 'settings[entity_type_ids][]'; - $button_label = t('Save field settings'); + $button_label = 'Save field settings'; $cardinality_field = 'cardinality'; $exclude_field_name = 'settings[exclude_entity_types]'; } @@ -662,7 +657,7 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'uid[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Preview')); + $this->submitForm($edit, 'Preview'); $assert_session->pageTextContains($title); $assert_session->pageTextContains($term->label()); // Back to node add page. @@ -682,13 +677,12 @@ class DynamicEntityReferenceTest extends BrowserTestBase { 'uid[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', ]; - $this->submitForm($edit, t('Preview')); + $this->submitForm($edit, 'Preview'); $assert_session->pageTextContains($title); $assert_session->pageTextContains($new_term); // Back to node add page. $this->clickLink('Back to content editing'); $assert_session->fieldValueEquals('field_der[0][target_id]', $new_term); - } } diff --git a/tests/src/Functional/DynamicEntityReferenceWidgetTest.php b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php index f1b70ce..1e4d29a 100644 --- a/tests/src/Functional/DynamicEntityReferenceWidgetTest.php +++ b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php @@ -123,12 +123,9 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase { // Only 1 target_type is configured, so this field is not available on the // node add/edit page. $assert_session->fieldNotExists($field_name . '[0][target_type]'); - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); $node = $this->drupalGetNodeByTitle($title); - $assert_session->responseContains(t('@type %title has been created.', [ - '@type' => 'reference_content', - '%title' => $node->toLink($node->label())->toString(), - ])); + $assert_session->pageTextContains(sprintf('reference_content %s has been created.', $node->label())); $nodes = \Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties(['title' => $title]); @@ -157,12 +154,10 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase { $field_name => $referenced_node->getEntityTypeId() . '-' . $referenced_node->id(), ]; $this->drupalGet(Url::fromRoute('node.add', ['node_type' => 'reference_content'])); - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); + $node = $this->drupalGetNodeByTitle($title); - $assert_session->responseContains(t('@type %title has been created.', [ - '@type' => 'reference_content', - '%title' => $node->toLink($node->label())->toString(), - ])); + $assert_session->pageTextContains(sprintf('reference_content %s has been created.', $node->label())); $nodes = \Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties(['title' => $title]); @@ -195,12 +190,10 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase { // Only one bundle is configuerd, so optgroup should not be added to // the select element. $assert_session->elementNotContains('css', '[name=' . $field_name . ']', 'optgroup'); - $this->submitForm($edit, t('Save')); + $this->submitForm($edit, 'Save'); + $node = $this->drupalGetNodeByTitle($title); - $assert_session->responseContains(t('@type %title has been created.', [ - '@type' => 'reference_content', - '%title' => $node->toLink($node->label())->toString(), - ])); + $assert_session->pageTextContains(sprintf('reference_content %s has been created.', $node->label())); $nodes = \Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties(['title' => $title]); @@ -225,7 +218,6 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase { $assert_session->elementContains('css', '[name=' . $field_name . ']', 'optgroup'); $field_config->setSetting('node', $node_setting); - } } diff --git a/tests/src/FunctionalJavascript/DynamicEntityReferenceTest.php b/tests/src/FunctionalJavascript/DynamicEntityReferenceTest.php index cefe455..773797d 100644 --- a/tests/src/FunctionalJavascript/DynamicEntityReferenceTest.php +++ b/tests/src/FunctionalJavascript/DynamicEntityReferenceTest.php @@ -217,7 +217,7 @@ class DynamicEntityReferenceTest extends WebDriverTestBase { $page = $this->getSession()->getPage(); $assert_session->assertWaitOnAjaxRequest(20000); $page->checkField('settings[entity_test][handler_settings][auto_create]'); - $this->submitForm([], t('Save settings')); + $this->submitForm([], 'Save settings'); $assert_session->pageTextContains('Saved Foobar configuration'); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions(); $this->drupalGet('entity_test/add'); -- GitLab