Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7451743
RegexInsertablesSuggesterTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
RegexInsertablesSuggesterTest.php
View Options
<?php
/**
* @file
* @author Abijeet Patro
* @license GPL-2.0-or-later
*/
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Insertable
;
use
MediaWikiUnitTestCase
;
/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\RegexInsertablesSuggester */
class
RegexInsertablesSuggesterTest
extends
MediaWikiUnitTestCase
{
/** @dataProvider getTestRegexInsertableProvider */
public
function
testRegexInsertable
(
$text
,
$params
,
$expectedVals
)
{
$insertablesSuggester
=
new
RegexInsertablesSuggester
(
$params
);
$insertables
=
$insertablesSuggester
->
getInsertables
(
$text
);
$this
->
assertSameSize
(
$expectedVals
,
$insertables
,
'should return all the expected insertables.'
);
foreach
(
$expectedVals
as
$i
=>
$values
)
{
$this
->
assertEquals
(
$values
[
'display'
],
$insertables
[
$i
]->
getDisplayText
(),
'should return the correct display text.'
);
$this
->
assertEquals
(
$values
[
'pre'
],
$insertables
[
$i
]->
getPreText
(),
'should return the correct pre text.'
);
$this
->
assertEquals
(
$values
[
'post'
],
$insertables
[
$i
]->
getPostText
(),
'should return the correct post text.'
);
}
}
public
static
function
getTestRegexInsertableProvider
()
{
yield
[
'Hello $name! I
\'
m $myname'
,
[
'regex'
=>
'/
\$
[a-z0-9]+/'
],
[
[
'display'
=>
'$name'
,
'pre'
=>
'$name'
,
'post'
=>
''
],
[
'display'
=>
'$myname'
,
'pre'
=>
'$myname'
,
'post'
=>
''
],
]
];
yield
[
'<html> <rocks>'
,
[
'regex'
=>
'/(?<display>
\<
[a-z]+>)/'
,
'display'
=>
'$display'
,
],
[
[
'display'
=>
'<html>'
,
'pre'
=>
'<html>'
,
'post'
=>
''
],
[
'display'
=>
'<rocks>'
,
'pre'
=>
'<rocks>'
,
'post'
=>
''
]
]
];
yield
[
'[Hello]($1) [World]($2)'
,
[
'regex'
=>
'/(?<pre>
\[
)[^]]+(?<post>
\]\(
[^)]+
\)
)/'
,
'display'
=>
'$pre$post'
,
'pre'
=>
'$pre'
,
'post'
=>
'$post'
],
[
[
'display'
=>
'[]($1)'
,
'pre'
=>
'['
,
'post'
=>
']($1)'
],
[
'display'
=>
'[]($2)'
,
'pre'
=>
'['
,
'post'
=>
']($2)'
]
]
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 21:39 (2 d, 3 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b5/02/3921efaf09fd36bc6d189758b756
Default Alt Text
RegexInsertablesSuggesterTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment