diff --git a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php index 97592d2..ef87eb6 100644 --- a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php +++ b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php @@ -34,10 +34,12 @@ function testLanguageConfiguration() { // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); + // Default English has no path prefix. + $this->assertSession()->fieldExists('prefix[en]'); // Check that Add language is a primary button. $this->drupalGet('admin/config/regional/language/add'); + // Add language is a primary button. $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button'); // Add predefined language. diff --git a/core/modules/language/tests/src/Functional/LanguageListTest.php b/core/modules/language/tests/src/Functional/LanguageListTest.php index bdbda9e..ecad682 100644 --- a/core/modules/language/tests/src/Functional/LanguageListTest.php +++ b/core/modules/language/tests/src/Functional/LanguageListTest.php @@ -39,7 +39,8 @@ function testLanguageList() { 'predefined_langcode' => 'fr', ); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); - $this->assertText('French', 'Language added successfully.'); + // Language added successfully. + $this->assertText('French'); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); // Get the weight of the last language and check that the weight is one unit @@ -61,8 +62,10 @@ function testLanguageList() { ); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); - $this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.'); - $this->assertText(t($name), 'Test language added.'); + // Language code found. + $this->assertRaw('"edit-languages-' . $langcode . '-weight"'); + // Test language added. + $this->assertText(t($name)); $language = \Drupal::service('language_manager')->getLanguage($langcode); $english = \Drupal::service('language_manager')->getLanguage('en'); @@ -70,31 +73,36 @@ function testLanguageList() { // Check if we can change the default language. $path = 'admin/config/regional/language'; $this->drupalGet($path); - $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.'); + // English is the default language. + $this->assertFieldChecked('edit-site-default-language-en'); // Change the default language. $edit = array( 'site_default_language' => $langcode, ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->rebuildContainer(); - $this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.'); + // Default language updated. + $this->assertNoFieldChecked('edit-site-default-language-en'); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); // Ensure we can't delete the default language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); - $this->assertResponse(403, 'Failed to delete the default language.'); + // Failed to delete the default language. + $this->assertResponse(403); // Ensure 'Edit' link works. $this->drupalGet('admin/config/regional/language'); $this->clickLink(t('Edit')); - $this->assertTitle(t('Edit language | Drupal'), 'Page title is "Edit language".'); + // Page title is "Edit language". + $this->assertTitle(t('Edit language | Drupal')); // Edit a language. $name = $this->randomMachineName(16); $edit = array( 'label' => $name, ); $this->drupalPostForm('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language')); - $this->assertRaw($name, 'The language has been updated.'); + // The language has been updated. + $this->assertRaw($name); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); // Change back the default language. @@ -106,23 +114,27 @@ function testLanguageList() { // Ensure 'delete' link works. $this->drupalGet('admin/config/regional/language'); $this->clickLink(t('Delete')); - $this->assertText(t('Are you sure you want to delete the language'), '"Delete" link is correct.'); + // "Delete" link is correct. + $this->assertText(t('Are you sure you want to delete the language')); // Delete a language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); // First test the 'cancel' link. $this->clickLink(t('Cancel')); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $english])); - $this->assertRaw($name, 'The language was not deleted.'); + // The language was not deleted. + $this->assertRaw($name); // Delete the language for real. This a confirm form, we do not need any // fields changed. $this->drupalPostForm('admin/config/regional/language/delete/' . $langcode, array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => $name, '%langcode' => $langcode); - $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.'); + // The test language has been removed. + $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args)); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $english])); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); - $this->assertResponse(404, 'Language no longer found.'); + // Language no longer found. + $this->assertResponse(404); // Delete French. $this->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('Delete')); @@ -130,11 +142,13 @@ function testLanguageList() { $this->rebuildContainer(); // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => 'French', '%langcode' => 'fr'); - $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The French language has been removed.'); + // The French language has been removed. + $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args)); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/fr'); - $this->assertResponse(404, 'Language no longer found.'); + // Language no longer found. + $this->assertResponse(404); // Make sure the "language_count" state has not changed. // Ensure we can delete the English language. Right now English is the only @@ -150,37 +164,42 @@ function testLanguageList() { ); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); - $this->assertText($name, 'Name found.'); + $this->assertText($name); // Check if we can change the default language. $path = 'admin/config/regional/language'; $this->drupalGet($path); - $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.'); + // English is the default language. + $this->assertFieldChecked('edit-site-default-language-en'); // Change the default language. $edit = array( 'site_default_language' => $langcode, ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->rebuildContainer(); - $this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.'); + // Default language updated. + $this->assertNoFieldChecked('edit-site-default-language-en'); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => 'English', '%langcode' => 'en'); - $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The English language has been removed.'); + // The English language has been removed. + $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args)); $this->rebuildContainer(); // Ensure we can't delete a locked language. $this->drupalGet('admin/config/regional/language/delete/und'); - $this->assertResponse(403, 'Can not delete locked language'); + // Can not delete locked language + $this->assertResponse(403); // Ensure that NL cannot be set default when it's not available. $this->drupalGet('admin/config/regional/language'); $extra_values = '&site_default_language=nl'; $this->drupalPostForm(NULL, array(), t('Save configuration'), array(), array(), NULL, $extra_values); $this->assertText(t('Selected default language no longer exists.')); - $this->assertNoFieldChecked('edit-site-default-language-xx', 'The previous default language got deselected.'); + // The previous default language got deselected. + $this->assertNoFieldChecked('edit-site-default-language-xx'); } /** diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php index 4c274e5..9e81989 100644 --- a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php @@ -105,7 +105,8 @@ function testInfoAlterations() { $this->assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.'); $this->drupalGet('admin/config/regional/language/detection'); - $this->assertNoFieldByName($form_field, NULL, 'Interface language negotiation method unavailable.'); + // Interface language negotiation method unavailable.. + $this->assertNoFieldByName($form_field, NULL); // Check that type-specific language negotiation methods can be assigned // only to the corresponding language types. diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index 1b43863..a4c78fa 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -129,6 +129,27 @@ protected function assertFieldByName($name, $value = NULL) { } /** + * Asserts that a field exists with the given name and value. + * + * @param string $name + * Name of field to assert. + * @param string $value + * (optional) Value of the field to assert. You may pass in NULL (default) + * to skip checking the actual value, while still checking that the field + * exists. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldNotExists() or + * $this->assertSession()->fieldValueNotEquals() instead. + */ + protected function assertNoFieldByName($name, $value = NULL) { + $this->assertSession()->fieldNotExists($name); + if ($value !== NULL) { + $this->assertSession()->fieldValueNotEquals($name, (string) $value); + } + } + + /** * Asserts that a field exists with the given ID and value. * * @param string $id