File tree 2 files changed +13
-4
lines changed
packages/guides-restructured-text
src/RestructuredText/TextRoles 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 14
14
namespace phpDocumentor \Guides \RestructuredText \TextRoles ;
15
15
16
16
use function in_array ;
17
+ use function strtolower ;
17
18
18
19
final class DefaultTextRoleFactory implements TextRoleFactory
19
20
{
@@ -53,16 +54,17 @@ public function replaceTextRole(TextRole $newTextRole): void
53
54
54
55
public function getTextRole (string $ name , string |null $ domain = null ): TextRole
55
56
{
56
- if ($ name === 'default ' ) {
57
+ $ normalizedName = strtolower ($ name );
58
+ if ($ normalizedName === 'default ' ) {
57
59
return $ this ->defaultTextRole ;
58
60
}
59
61
60
62
if ($ domain === null ) {
61
- return $ this ->findTextRole ($ this ->textRoles , $ name );
63
+ return $ this ->findTextRole ($ this ->textRoles , $ normalizedName );
62
64
}
63
65
64
66
if (isset ($ this ->domains [$ domain ])) {
65
- return $ this ->findTextRole ($ this ->domains [$ domain ], $ name );
67
+ return $ this ->findTextRole ($ this ->domains [$ domain ], $ normalizedName );
66
68
}
67
69
68
70
return $ this ->genericTextRole ;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public function setUp(): void
26
26
{
27
27
$ this ->logger = new Logger ('test ' );
28
28
$ this ->defaultTextRoleFactory = new DefaultTextRoleFactory (
29
- new GenericTextRole (self :: createMock (SettingsManager::class)),
29
+ new GenericTextRole ($ this -> createMock (SettingsManager::class)),
30
30
new LiteralTextRole (),
31
31
[],
32
32
[],
@@ -45,4 +45,11 @@ public function testRegisteredTextRoleIsReturned(): void
45
45
$ textRole = $ this ->defaultTextRoleFactory ->getTextRole ('abbreviation ' );
46
46
self ::assertInstanceOf (AbbreviationTextRole::class, $ textRole );
47
47
}
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
+ }
48
55
}
You can’t perform that action at this time.
0 commit comments