File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
packages/guides-restructured-text
src/RestructuredText/TextRoles Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1414namespace phpDocumentor \Guides \RestructuredText \TextRoles ;
1515
1616use function in_array ;
17+ use function strtolower ;
1718
1819final 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 ;
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments