| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Tests\Parser; |
| 6 |
|
| 7 |
use MediaWiki\Language\ILanguageConverter; |
| 8 |
use MediaWiki\MainConfigNames; |
| 9 |
use MediaWiki\Parser\LinkHolderArray; |
| 10 |
use MediaWiki\Parser\Parser; |
| 11 |
use MediaWiki\Title\Title; |
| 12 |
use MediaWikiLangTestCase; |
| 13 |
use Wikimedia\TestingAccessWrapper; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class LinkHolderArrayIntegrationTest extends MediaWikiLangTestCase { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function testIsBig( int $size, int $global, bool $expected ) { |
| 29 |
$this->overrideConfigValue( MainConfigNames::LinkHolderBatchSize, $global ); |
| 30 |
$linkHolderArray = new LinkHolderArray( |
| 31 |
$this->createMock( Parser::class ), |
| 32 |
$this->createMock( ILanguageConverter::class ), |
| 33 |
$this->createHookContainer() |
| 34 |
); |
| 35 |
|
| 36 |
$linkHolderArray = TestingAccessWrapper::newFromObject( $linkHolderArray ); |
| 37 |
$linkHolderArray->size = $size; |
| 38 |
|
| 39 |
$this->assertSame( $expected, $linkHolderArray->isBig() ); |
| 40 |
} |
| 41 |
|
| 42 |
public static function provideIsBig() { |
| 43 |
yield [ 0, 0, false ]; |
| 44 |
yield [ 0, 1, false ]; |
| 45 |
yield [ 1, 0, true ]; |
| 46 |
yield [ 1, 1, false ]; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function testMakeHolder_withNsText( |
| 57 |
bool $isExternal, |
| 58 |
string $expected |
| 59 |
) { |
| 60 |
$link = new LinkHolderArray( |
| 61 |
$this->createMock( Parser::class ), |
| 62 |
$this->createMock( ILanguageConverter::class ), |
| 63 |
$this->createHookContainer() |
| 64 |
); |
| 65 |
|
| 66 |
$link = TestingAccessWrapper::newFromObject( $link ); |
| 67 |
$parser = $this->createMock( Parser::class ); |
| 68 |
$parser->method( 'nextLinkID' )->willReturn( 9 ); |
| 69 |
$link->parent = $parser; |
| 70 |
$title = $this->createMock( Title::class ); |
| 71 |
$title->method( 'getPrefixedDBkey' )->willReturn( 'Talk:Dummy' ); |
| 72 |
$title->method( 'getNamespace' )->willReturn( 1234 ); |
| 73 |
$title->method( 'isExternal' )->willReturn( $isExternal ); |
| 74 |
|
| 75 |
$this->assertSame( 0, $link->size ); |
| 76 |
$result = $link->makeHolder( |
| 77 |
$title, |
| 78 |
'test1 text', |
| 79 |
'test2 trail', |
| 80 |
'test3 prefix' |
| 81 |
); |
| 82 |
$this->assertSame( $expected, $result ); |
| 83 |
$this->assertSame( 1, $link->size ); |
| 84 |
|
| 85 |
if ( $isExternal ) { |
| 86 |
$this->assertArrayEquals( |
| 87 |
[ |
| 88 |
9 => [ |
| 89 |
'title' => $title, |
| 90 |
'text' => 'test3 prefixtest1 texttest', |
| 91 |
'pdbk' => 'Talk:Dummy', |
| 92 |
], |
| 93 |
], |
| 94 |
$link->interwikis |
| 95 |
); |
| 96 |
$this->assertCount( 0, $link->internals ); |
| 97 |
} else { |
| 98 |
$this->assertArrayEquals( |
| 99 |
[ |
| 100 |
1234 => [ |
| 101 |
9 => [ |
| 102 |
'title' => $title, |
| 103 |
'text' => 'test3 prefixtest1 texttest', |
| 104 |
'pdbk' => 'Talk:Dummy', |
| 105 |
], |
| 106 |
], |
| 107 |
], |
| 108 |
$link->internals |
| 109 |
); |
| 110 |
$this->assertCount( 0, $link->interwikis ); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
public static function provideMakeHolder_withNsText() { |
| 115 |
yield [ |
| 116 |
false, |
| 117 |
'<!--LINK\'" 1234:9-->2 trail', |
| 118 |
]; |
| 119 |
yield [ |
| 120 |
true, |
| 121 |
'<!--IWLINK\'" 9-->2 trail', |
| 122 |
]; |
| 123 |
} |
| 124 |
} |