diff --git a/core/modules/filter/src/Tests/FilterFormTest.php b/core/modules/filter/src/Tests/FilterFormTest.php index f8555fd..4bee072 100644 --- a/core/modules/filter/src/Tests/FilterFormTest.php +++ b/core/modules/filter/src/Tests/FilterFormTest.php @@ -91,40 +91,40 @@ protected function doFilterFormTestAsAdmin() { $this->assertEnabledTextarea('edit-all-formats-no-default-value'); // If no default is given, the format with the lowest weight becomes the // default. - $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html'); + $this->assertOptions('edit-all-formats-no-default-format', $formats, 'filtered_html'); $this->assertEnabledTextarea('edit-all-formats-default-value'); // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses // 'filter_test' as the default value in this case. - $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test'); + $this->assertOptions('edit-all-formats-default-format', $formats, 'filter_test'); $this->assertEnabledTextarea('edit-all-formats-default-missing-value'); // If a missing format is set as the default, administrators must select a // valid replacement format. - $this->assertRequiredSelectAndOptions('edit-all-formats-default-missing-format--2', $formats); + $this->assertRequiredSelectAndOptions('edit-all-formats-default-missing-format', $formats); // Test a text format element with a predefined list of formats. $formats = array('full_html', 'filter_test'); $this->assertEnabledTextarea('edit-restricted-formats-no-default-value'); - $this->assertOptions('edit-restricted-formats-no-default-format--2', $formats, 'full_html'); + $this->assertOptions('edit-restricted-formats-no-default-format', $formats, 'full_html'); $this->assertEnabledTextarea('edit-restricted-formats-default-value'); - $this->assertOptions('edit-restricted-formats-default-format--2', $formats, 'full_html'); + $this->assertOptions('edit-restricted-formats-default-format', $formats, 'full_html'); $this->assertEnabledTextarea('edit-restricted-formats-default-missing-value'); - $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-missing-format--2', $formats); + $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-missing-format', $formats); $this->assertEnabledTextarea('edit-restricted-formats-default-disallowed-value'); - $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-disallowed-format--2', $formats); + $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-disallowed-format', $formats); // Test a text format element with a fixed format. $formats = array('filter_test'); // When there is only a single option there is no point in choosing. $this->assertEnabledTextarea('edit-single-format-no-default-value'); - $this->assertNoSelect('edit-single-format-no-default-format--2'); + $this->assertNoSelect('edit-single-format-no-default-format'); $this->assertEnabledTextarea('edit-single-format-default-value'); - $this->assertNoSelect('edit-single-format-default-format--2'); + $this->assertNoSelect('edit-single-format-default-format'); // If the select has a missing or disallowed format, administrators must // explicitly choose the format. $this->assertEnabledTextarea('edit-single-format-default-missing-value'); - $this->assertRequiredSelectAndOptions('edit-single-format-default-missing-format--2', $formats); + $this->assertRequiredSelectAndOptions('edit-single-format-default-missing-format', $formats); $this->assertEnabledTextarea('edit-single-format-default-disallowed-value'); - $this->assertRequiredSelectAndOptions('edit-single-format-default-disallowed-format--2', $formats); + $this->assertRequiredSelectAndOptions('edit-single-format-default-disallowed-format', $formats); } /** @@ -140,11 +140,11 @@ protected function doFilterFormTestAsNonAdmin() { $this->assertEnabledTextarea('edit-all-formats-no-default-value'); // If no default is given, the format with the lowest weight becomes the // default. This happens to be 'filtered_html'. - $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html'); + $this->assertOptions('edit-all-formats-no-default-format', $formats, 'filtered_html'); $this->assertEnabledTextarea('edit-all-formats-default-value'); // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses // 'filter_test' as the default value in this case. - $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test'); + $this->assertOptions('edit-all-formats-default-format', $formats, 'filter_test'); // If a missing format is given as default, non-admin users are presented // with a disabled textarea. $this->assertDisabledTextarea('edit-all-formats-default-missing-value'); @@ -153,7 +153,7 @@ protected function doFilterFormTestAsNonAdmin() { $this->assertEnabledTextarea('edit-restricted-formats-no-default-value'); // The user only has access to the 'filter_test' format, so when no default // is given that is preselected and the text format select is hidden. - $this->assertNoSelect('edit-restricted-formats-no-default-format--2'); + $this->assertNoSelect('edit-restricted-formats-no-default-format'); // When the format that the user does not have access to is preselected, the // textarea should be disabled. $this->assertDisabledTextarea('edit-restricted-formats-default-value'); @@ -163,9 +163,9 @@ protected function doFilterFormTestAsNonAdmin() { // Test a text format element with a fixed format. // When there is only a single option there is no point in choosing. $this->assertEnabledTextarea('edit-single-format-no-default-value'); - $this->assertNoSelect('edit-single-format-no-default-format--2'); + $this->assertNoSelect('edit-single-format-no-default-format'); $this->assertEnabledTextarea('edit-single-format-default-value'); - $this->assertNoSelect('edit-single-format-default-format--2'); + $this->assertNoSelect('edit-single-format-default-format'); // If the select has a missing or disallowed format make sure the textarea // is disabled. $this->assertDisabledTextarea('edit-single-format-default-missing-value'); @@ -191,8 +191,8 @@ protected function assertNoSelect($id) { /** * Asserts that a select element has the correct options. * - * @param string $id - * The HTML ID of the select element. + * @param string $name + * The HTML name of the select element. * @param array $expected_options * An array of option values. * @param string $selected @@ -201,11 +201,11 @@ protected function assertNoSelect($id) { * @return bool * TRUE if the assertion passed; FALSE otherwise. */ - protected function assertOptions($id, array $expected_options, $selected) { - $select = $this->xpath('//select[@id=:id]', array(':id' => $id)); + protected function assertOptions($drupal_selector, array $expected_options, $selected) { + $select = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]', [':data_drupal_selector' => $drupal_selector]); $select = reset($select); - $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', array( - '@id' => $id, + $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @name exists.', array( + '@name' => $drupal_selector, ))); $found_options = $this->getAllOptions($select); @@ -214,7 +214,7 @@ protected function assertOptions($id, array $expected_options, $selected) { if ($expected_key !== FALSE) { $this->pass(SafeMarkup::format('Option @option for field @id exists.', array( '@option' => $expected_options[$expected_key], - '@id' => $id, + '@id' => $drupal_selector, ))); unset($found_options[$found_key]); unset($expected_options[$expected_key]); @@ -226,19 +226,19 @@ protected function assertOptions($id, array $expected_options, $selected) { foreach ($expected_options as $expected_option) { $this->fail(SafeMarkup::format('Option @option for field @id exists.', array( '@option' => $expected_option, - '@id' => $id, + '@id' => $drupal_selector, ))); $passed = FALSE; } foreach ($found_options as $found_option) { $this->fail(SafeMarkup::format('Option @option for field @id does not exist.', array( '@option' => $found_option->attributes()->value, - '@id' => $id, + '@id' => $drupal_selector, ))); $passed = FALSE; } - return $passed && $this->assertOptionSelected($id, $selected); + return $passed && $this->assertOptionSelected($drupal_selector, $selected); } /** @@ -253,18 +253,16 @@ protected function assertOptions($id, array $expected_options, $selected) { * @return bool * TRUE if the assertion passed; FALSE otherwise. */ - protected function assertRequiredSelectAndOptions($id, array $options) { - $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', array( - ':id' => $id, - )); + protected function assertRequiredSelectAndOptions($drupal_selector, array $options) { + $select = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]', [':data_drupal_selector' => $drupal_selector]); $select = reset($select); - $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @id exists.', array( - '@id' => $id, + $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @data-drupal-selector exists.', array( + '@data-drupal-selector' => $drupal_selector, ))); // A required select element has a "- Select -" option whose key is an empty // string. $options[] = ''; - return $passed && $this->assertOptions($id, $options, ''); + return $passed && $this->assertOptions($drupal_selector, $options, ''); } /**