Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Merge pull request #1196 from phpDocumentor/feat/case-insensitive-text-roles #1197

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading