From 4b3313c38df74d19ab0ab897300906820b482f18 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 11 Jan 2024 08:38:16 +0000 Subject: [PATCH] Issue #3399152 by SamLerner, smustgrave, sourabhjain, DishaKatariya, Nitin shrivastava, Nikolay Shapovalov, xjm: Change sort order of configuration options on config single export form --- .../src/Form/ConfigSingleExportForm.php | 2 +- .../ConfigSingleImportExportTest.php | 2 +- .../FunctionalJavascript/ConfigExportTest.php | 66 ++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/core/modules/config/src/Form/ConfigSingleExportForm.php b/core/modules/config/src/Form/ConfigSingleExportForm.php index 2a7ac00f1078..963a6a1d9d41 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -173,7 +173,7 @@ protected function findConfiguration($config_type) { foreach ($entity_storage->loadMultiple() as $entity) { $entity_id = $entity->id(); if ($label = $entity->label()) { - $names[$entity_id] = new TranslatableMarkup('@label (@id)', ['@label' => $label, '@id' => $entity_id]); + $names[$entity_id] = new TranslatableMarkup('@id (@label)', ['@label' => $label, '@id' => $entity_id]); } else { $names[$entity_id] = $entity_id; diff --git a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php index 8e55ab7890ca..215f5d24578b 100644 --- a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php +++ b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php @@ -278,7 +278,7 @@ public function testExport() { // Verify that the fallback date format config entity is selected when // specified in the URL. $this->drupalGet('admin/config/development/configuration/single/export/date_format/fallback'); - $option_node = $this->assertSession()->optionExists("config_name", 'Fallback date format (fallback)'); + $option_node = $this->assertSession()->optionExists("config_name", 'fallback (Fallback date format)'); $this->assertTrue($option_node->isSelected()); $fallback_date = \Drupal::entityTypeManager()->getStorage('date_format')->load('fallback'); $yaml_text = $this->assertSession()->fieldExists('export')->getValue(); diff --git a/core/modules/config/tests/src/FunctionalJavascript/ConfigExportTest.php b/core/modules/config/tests/src/FunctionalJavascript/ConfigExportTest.php index 5c87adc37137..ae1c582348f3 100644 --- a/core/modules/config/tests/src/FunctionalJavascript/ConfigExportTest.php +++ b/core/modules/config/tests/src/FunctionalJavascript/ConfigExportTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\config\FunctionalJavascript; +use Drupal\block_content\Entity\BlockContent; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; /** @@ -16,19 +17,71 @@ class ConfigExportTest extends WebDriverTestBase { /** * {@inheritdoc} */ - protected static $modules = ['config', 'system']; + protected static $modules = ['config', 'system', 'block', 'block_content']; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; + /** + * @var string + * A prefix string used in naming the test blocks. + */ + protected string $blockNamePrefix = 'aaaaaa_config_export_test_block'; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $this->drupalLogin($this->drupalCreateUser([ + 'administer blocks', + 'access block library', + 'administer block types', + 'administer block content', + ])); + + // Create test blocks, so we know what the titles will be to check their order. + foreach ([1, 2, 3, 4] as $num) { + $block_name = $this->blockNamePrefix . $num; + $new_block = $this->createBlockContent($block_name); + $this->drupalPlaceBlock('block_content:' . $new_block->uuid(), [ + 'id' => $block_name, + 'label' => $this->randomMachineName(), + 'theme' => $this->defaultTheme, + 'region' => 'sidebar_first', + ]); + } + } + + /** + * Creates test blocks. + * + * @param $title + * Title of the block. + * + * @return \Drupal\block_content\Entity\BlockContent + * + * @throws \Drupal\Core\Entity\EntityStorageException + */ + protected function createBlockContent($title) { + $block_content = BlockContent::create([ + 'info' => $title, + 'type' => 'basic', + ]); + $block_content->save(); + return $block_content; + } + /** * Tests Ajax form functionality on the config export page. */ public function testAjaxOnExportPage() { $this->drupalLogin($this->drupalCreateUser([ 'export configuration', + 'administer blocks', ])); $page = $this->getSession()->getPage(); @@ -53,6 +106,17 @@ public function testAjaxOnExportPage() { $page->selectFieldOption('config_type', 'Action'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertSession()->fieldValueEquals('export', ''); + + // Check that the 'Configuration name' list is sorted alphabetically by ID, + // which always begins with our prefix, and not the label, which is randomized. + $page->selectFieldOption('config_type', 'Block'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $options = $page->findField('config_name')->findAll('css', 'option'); + foreach ([1, 2, 3, 4] as $num) { + $block_name = $this->blockNamePrefix . $num; + $this->assertStringStartsWith($block_name, $options[$num]->getText()); + $this->assertEquals($block_name, $options[$num]->getValue()); + } } } -- GitLab