From a55bbc9878bc479016db011bb8b50833e8d17255 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Wed, 21 Sep 2022 17:38:38 +0200
Subject: [PATCH] Issue #1987504 by mohit_aghera, quietone, xjm,
 mandarmbhagwat78, neRok, larowlan, Berdir: Inconsistent character casing for
 entity type labels

---
 core/modules/editor/src/Entity/Editor.php     |  4 +-
 .../src/Entity/ContentLanguageSettings.php    |  4 +-
 .../src/Kernel/Entity/EntityLabelTest.php     | 53 +++++++++++++++++++
 3 files changed, 57 insertions(+), 4 deletions(-)
 create mode 100644 core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php

diff --git a/core/modules/editor/src/Entity/Editor.php b/core/modules/editor/src/Entity/Editor.php
index fc5f632d036d..b04ea8387fa8 100644
--- a/core/modules/editor/src/Entity/Editor.php
+++ b/core/modules/editor/src/Entity/Editor.php
@@ -11,8 +11,8 @@
  *
  * @ConfigEntityType(
  *   id = "editor",
- *   label = @Translation("Text Editor"),
- *   label_collection = @Translation("Text Editors"),
+ *   label = @Translation("Text editor"),
+ *   label_collection = @Translation("Text editors"),
  *   label_singular = @Translation("text editor"),
  *   label_plural = @Translation("text editors"),
  *   label_count = @PluralTranslation(
diff --git a/core/modules/language/src/Entity/ContentLanguageSettings.php b/core/modules/language/src/Entity/ContentLanguageSettings.php
index d3751a0eaa6f..d7c549924ed0 100644
--- a/core/modules/language/src/Entity/ContentLanguageSettings.php
+++ b/core/modules/language/src/Entity/ContentLanguageSettings.php
@@ -13,8 +13,8 @@
  *
  * @ConfigEntityType(
  *   id = "language_content_settings",
- *   label = @Translation("Content Language Settings"),
- *   label_collection = @Translation("Content Language Settings"),
+ *   label = @Translation("Content language settings"),
+ *   label_collection = @Translation("Content language settings"),
  *   label_singular = @Translation("content language setting"),
  *   label_plural = @Translation("content languages settings"),
  *   label_count = @PluralTranslation(
diff --git a/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php
new file mode 100644
index 000000000000..a29d454355ae
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Entity;
+
+use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Tests that entity type labels use sentence-case.
+ *
+ * @group Entity
+ */
+class EntityLabelTest extends KernelTestBase {
+
+  /**
+   * Tests that entity type labels use sentence-case.
+   */
+  public function testEntityLabelCasing() {
+    $base_directory = $this->root . '/core/modules/';
+    $modules = scandir($base_directory);
+    $paths = [];
+    foreach ($modules as $module) {
+      $paths["\Drupal\\{$module}\Entity"] = $base_directory . $module . '/src/';
+    }
+    $namespaces = new \ArrayObject($paths);
+    $discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
+    $definitions = $discovery->getDefinitions();
+
+    foreach ($definitions as $definition) {
+      /** @var \Drupal\Core\Entity\EntityType $definition */
+
+      /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
+      $label = $definition->getLabel();
+      $collection_label = $definition->getCollectionLabel();
+
+      $label_string = $label->getUntranslatedString();
+      $collection_label_string = $collection_label->getUntranslatedString();
+
+      // Keep the first word as it is for nouns that are all capital letters
+      // (like RDF, URL alias etc.) so we can't run strtolower() for the entire
+      // string. Special cases may need to be added to this test in the future
+      // if an acronym is in a different position in the label.
+      $first_word = strtok($label_string, " ");
+      $remaining_string = strtolower(strstr($label_string, " "));
+      $this->assertEquals($first_word . $remaining_string, $label_string);
+
+      $first_word = strtok($collection_label_string, " ");
+      $remaining_string = strtolower(strstr($collection_label_string, " "));
+      $this->assertEquals($first_word . $remaining_string, $collection_label_string);
+    }
+  }
+
+}
-- 
GitLab