Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7451455
UrlInsertablesSuggesterTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
UrlInsertablesSuggesterTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Insertable
;
use
MediaWikiUnitTestCase
;
/**
* @author Niklas Laxström
* @author Jon Harald Søby
* @license GPL-2.0-or-later
* @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\UrlInsertablesSuggester
*/
class
UrlInsertablesSuggesterTest
extends
MediaWikiUnitTestCase
{
/** @dataProvider getTestUrlInsertablesSuggesterProvider */
public
function
testUrlInsertablesSuggester
(
$text
,
$expected
,
$comment
=
''
)
{
$suggester
=
new
UrlInsertablesSuggester
();
$actual
=
$suggester
->
getInsertables
(
$text
);
$this
->
assertSameSize
(
$expected
,
$actual
,
'should return correct number of insertables '
.
$comment
);
foreach
(
$expected
as
$i
=>
$values
)
{
$this
->
assertEquals
(
$values
[
'display'
],
$actual
[
$i
]->
getDisplayText
(),
'should return the correct display text '
.
$comment
);
$this
->
assertEquals
(
$values
[
'pre'
],
$actual
[
$i
]->
getPreText
(),
'should return the correct pre text '
.
$comment
);
$this
->
assertEquals
(
$values
[
'post'
],
$actual
[
$i
]->
getPostText
(),
'should return the correct post text '
.
$comment
);
}
}
public
static
function
getTestUrlInsertablesSuggesterProvider
()
{
yield
[
'Visit http://wikipedia.org'
,
[
[
'display'
=>
'http://wikipedia.org/'
,
'pre'
=>
'http://wikipedia.org'
,
'post'
=>
''
],
],
'for simple domain URL'
];
yield
[
'See the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:API documentation page]'
,
[
[
'display'
=>
'https://www.mediawiki.org/'
,
'pre'
=>
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:API'
,
'post'
=>
''
],
],
'for URLs with slugs'
];
yield
[
'[//en.wikipedia.org/w/index.php?title=Special:MyTalk&action=edit§ion=new Add new section]'
,
[
[
'display'
=>
'//en.wikipedia.org/'
,
'pre'
=>
'//en.wikipedia.org/w/index.php?title=Special:MyTalk&action=edit§ion=new'
,
'post'
=>
''
],
],
'for URLs with parameters'
];
yield
[
'https://w.wiki/4nCc and https://www.mediawiki.org/wiki/Localisation are the same'
,
[
[
'display'
=>
'https://w.wiki/'
,
'pre'
=>
'https://w.wiki/4nCc'
,
'post'
=>
''
],
[
'display'
=>
'https://www.mediawiki.org/'
,
'pre'
=>
'https://www.mediawiki.org/wiki/Localisation'
,
'post'
=>
''
]
],
'for multiple URLs'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 21:27 (2 d, 3 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
16/d9/b3508efe8c3c9e23d18d3ddd1706
Default Alt Text
UrlInsertablesSuggesterTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment