Skip to content

Commit

Permalink
Merge pull request #1196 from phpDocumentor/feat/case-insensitive-tex…
Browse files Browse the repository at this point in the history
…t-roles

FEAT: make textroles case insentive
  • Loading branch information
jaapio authored Jan 20, 2025
2 parents 70c3d24 + 4eed6b0 commit 1d75702
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use function in_array;
use function strtolower;

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

public function getTextRole(string $name, string|null $domain = null): TextRole
{
if ($name === 'default') {
$normalizedName = strtolower($name);
if ($normalizedName === 'default') {
return $this->defaultTextRole;
}

if ($domain === null) {
return $this->findTextRole($this->textRoles, $name);
return $this->findTextRole($this->textRoles, $normalizedName);
}

if (isset($this->domains[$domain])) {
return $this->findTextRole($this->domains[$domain], $name);
return $this->findTextRole($this->domains[$domain], $normalizedName);
}

return $this->genericTextRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp(): void
{
$this->logger = new Logger('test');
$this->defaultTextRoleFactory = new DefaultTextRoleFactory(
new GenericTextRole(self::createMock(SettingsManager::class)),
new GenericTextRole($this->createMock(SettingsManager::class)),
new LiteralTextRole(),
[],
[],
Expand All @@ -45,4 +45,11 @@ public function testRegisteredTextRoleIsReturned(): void
$textRole = $this->defaultTextRoleFactory->getTextRole('abbreviation');
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
}

public function testRegisteredTextRoleIsCaseInSensitive(): void
{
$this->defaultTextRoleFactory->registerTextRole(new AbbreviationTextRole($this->logger));
$textRole = $this->defaultTextRoleFactory->getTextRole('ABbreviation');
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
}
}

0 comments on commit 1d75702

Please sign in to comment.