From fe06cae4df61a8b8e2fd13f7c3ad5fb87fee79af Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Sat, 24 Apr 2021 13:23:55 +1000 Subject: [PATCH] Issue #1624278 by quietone, longwave: cleanup of docblock to UI text in update_get_update_list() is weak --- core/includes/update.inc | 9 ++- .../update_test_description.info.yml | 5 ++ .../update_test_description.install | 19 +++++ .../UpdateSystem/UpdateDescriptionTest.php | 70 +++++++++++++++++++ .../UpdatePostUpdateFailingTest.php | 4 +- .../UpdateSystem/UpdatePostUpdateTest.php | 2 +- 6 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 core/modules/system/tests/modules/update_test_description/update_test_description.info.yml create mode 100644 core/modules/system/tests/modules/update_test_description/update_test_description.install create mode 100644 core/modules/system/tests/src/Functional/UpdateSystem/UpdateDescriptionTest.php diff --git a/core/includes/update.inc b/core/includes/update.inc index d5818d005aaa..521773703cf7 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -397,7 +397,14 @@ function update_get_update_list() { if ($update > $schema_version) { // The description for an update comes from its Doxygen. $func = new ReflectionFunction($module . '_update_' . $update); - $description = str_replace(["\n", '*', '/'], '', $func->getDocComment()); + $patterns = [ + '/^\s*[\/*]*/', + '/(\n\s*\**)(.*)/', + '/\/$/', + '/^\s*/', + ]; + $replacements = ['', '$2', '', '']; + $description = preg_replace($patterns, $replacements, $func->getDocComment()); $ret[$module]['pending'][$update] = "$update - $description"; if (!isset($ret[$module]['start'])) { $ret[$module]['start'] = $update; diff --git a/core/modules/system/tests/modules/update_test_description/update_test_description.info.yml b/core/modules/system/tests/modules/update_test_description/update_test_description.info.yml new file mode 100644 index 000000000000..be1e007cb511 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_description/update_test_description.info.yml @@ -0,0 +1,5 @@ +name: Update test description +type: module +description: Support module for update testing. +package: Testing +version: VERSION diff --git a/core/modules/system/tests/modules/update_test_description/update_test_description.install b/core/modules/system/tests/modules/update_test_description/update_test_description.install new file mode 100644 index 000000000000..1ed00ccad30b --- /dev/null +++ b/core/modules/system/tests/modules/update_test_description/update_test_description.install @@ -0,0 +1,19 @@ +drupalCreateUser([ + 'administer software updates', + 'access site in maintenance mode', + ]); + $this->drupalLogin($user); + + $connection = Database::getConnection(); + // Set the schema version. + $connection->merge('key_value') + ->condition('collection', 'system.schema') + ->condition('name', 'update_test_description') + ->fields([ + 'collection' => 'system.schema', + 'name' => 'update_test_description', + 'value' => 'i:8000;', + ]) + ->execute(); + // Update core.extension. + $extensions = $connection->select('config') + ->fields('config', ['data']) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute() + ->fetchField(); + $extensions = unserialize($extensions); + $extensions['module']['update_test_description'] = 8000; + $connection->update('config') + ->fields([ + 'data' => serialize($extensions), + ]) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute(); + + // Go to the update page. + $update_url = Url::fromRoute('system.db_update'); + + $this->drupalGet($update_url); + $this->clickLink(t('Continue')); + + // Check that the description is displayed correctly. + $this->assertSession()->responseContains('8001 - Update test of slash in description and/or.'); + $this->assertSession()->responseContains('8002 - Update test with multiline description, the quick brown fox jumped over the lazy dog.'); + } + +} diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateFailingTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateFailingTest.php index fee94d95054a..bef4c112c50e 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateFailingTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateFailingTest.php @@ -76,8 +76,8 @@ class UpdatePostUpdateFailingTest extends BrowserTestBase { */ protected function doSelectionTest() { // First update, should not be run since this module's update hooks fail. - $this->assertRaw('8001 - This update will fail.'); - $this->assertRaw('8002 - A further update.'); + $this->assertSession()->responseContains('8001 - This update will fail.'); + $this->assertSession()->responseContains('8002 - A further update'); $this->assertSession()->assertEscaped("First update, should not be run since this module's update hooks fail."); } diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php index 8cfa3d33bbee..6c065454e95d 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php @@ -75,7 +75,7 @@ class UpdatePostUpdateTest extends BrowserTestBase { protected function doSelectionTest() { // Ensure that normal and post_update updates are merged together on the // selection page. - $this->assertRaw(''); + $this->assertSession()->responseContains(''); } /**