Page MenuHomeWickedGov Phorge

UrlInsertablesSuggesterTest.php
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

UrlInsertablesSuggesterTest.php

<?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&section=new Add new section]',
[
[
'display' => '//en.wikipedia.org/',
'pre' => '//en.wikipedia.org/w/index.php?title=Special:MyTalk&action=edit&section=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

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)

Event Timeline