Skip to content

Commit d2ff3e4

Browse files
authored
Merge pull request #1197 from phpDocumentor/backport/1.x/pr-1196
[1.x] Merge pull request #1196 from phpDocumentor/feat/case-insensitive-text-roles
2 parents 9cd73d3 + acdf3bf commit d2ff3e4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/guides-restructured-text/src/RestructuredText/TextRoles/DefaultTextRoleFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
1515

1616
use function in_array;
17+
use function strtolower;
1718

1819
final class DefaultTextRoleFactory implements TextRoleFactory
1920
{
@@ -53,16 +54,17 @@ public function replaceTextRole(TextRole $newTextRole): void
5354

5455
public function getTextRole(string $name, string|null $domain = null): TextRole
5556
{
56-
if ($name === 'default') {
57+
$normalizedName = strtolower($name);
58+
if ($normalizedName === 'default') {
5759
return $this->defaultTextRole;
5860
}
5961

6062
if ($domain === null) {
61-
return $this->findTextRole($this->textRoles, $name);
63+
return $this->findTextRole($this->textRoles, $normalizedName);
6264
}
6365

6466
if (isset($this->domains[$domain])) {
65-
return $this->findTextRole($this->domains[$domain], $name);
67+
return $this->findTextRole($this->domains[$domain], $normalizedName);
6668
}
6769

6870
return $this->genericTextRole;

packages/guides-restructured-text/tests/unit/TextRoles/DefaultTextRoleFactoryTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626
{
2727
$this->logger = new Logger('test');
2828
$this->defaultTextRoleFactory = new DefaultTextRoleFactory(
29-
new GenericTextRole(self::createMock(SettingsManager::class)),
29+
new GenericTextRole($this->createMock(SettingsManager::class)),
3030
new LiteralTextRole(),
3131
[],
3232
[],
@@ -45,4 +45,11 @@ public function testRegisteredTextRoleIsReturned(): void
4545
$textRole = $this->defaultTextRoleFactory->getTextRole('abbreviation');
4646
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
4747
}
48+
49+
public function testRegisteredTextRoleIsCaseInSensitive(): void
50+
{
51+
$this->defaultTextRoleFactory->registerTextRole(new AbbreviationTextRole($this->logger));
52+
$textRole = $this->defaultTextRoleFactory->getTextRole('ABbreviation');
53+
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
54+
}
4855
}

0 commit comments

Comments
 (0)