wiki.techinc.nl/tests/phpunit/includes/parser/LinkHolderArrayIntegrationTest.php
James D. Forrester ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00

113 lines
2.5 KiB
PHP

<?php
declare( strict_types = 1 );
use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title;
/**
* @covers LinkHolderArray
*/
class LinkHolderArrayIntegrationTest extends MediaWikiLangTestCase {
/**
* @dataProvider provideIsBig
* @covers LinkHolderArray::isBig
*
* @param int $size
* @param int $global
* @param bool $expected
*/
public function testIsBig( int $size, int $global, bool $expected ) {
$this->overrideConfigValue( MainConfigNames::LinkHolderBatchSize, $global );
$linkHolderArray = new LinkHolderArray(
$this->createMock( Parser::class ),
$this->createMock( ILanguageConverter::class ),
$this->createHookContainer()
);
$linkHolderArray->size = $size;
$this->assertSame( $expected, $linkHolderArray->isBig() );
}
public function provideIsBig() {
yield [ 0, 0, false ];
yield [ 0, 1, false ];
yield [ 1, 0, true ];
yield [ 1, 1, false ];
}
/**
* @dataProvider provideMakeHolder_withNsText
* @covers LinkHolderArray::makeHolder
*
* @param bool $isExternal
* @param string $expected
*/
public function testMakeHolder_withNsText(
bool $isExternal,
string $expected
) {
$link = new LinkHolderArray(
$this->createMock( Parser::class ),
$this->createMock( ILanguageConverter::class ),
$this->createHookContainer()
);
$parser = $this->createMock( Parser::class );
$parser->method( 'nextLinkID' )->willReturn( 9 );
$link->parent = $parser;
$title = $this->createMock( Title::class );
$title->method( 'getPrefixedDBkey' )->willReturn( 'Talk:Dummy' );
$title->method( 'getNamespace' )->willReturn( 1234 );
$title->method( 'isExternal' )->willReturn( $isExternal );
$this->assertSame( 0, $link->size );
$result = $link->makeHolder(
$title,
'test1 text',
'test2 trail',
'test3 prefix'
);
$this->assertSame( $expected, $result );
$this->assertSame( 1, $link->size );
if ( $isExternal ) {
$this->assertArrayEquals(
[
9 => [
'title' => $title,
'text' => 'test3 prefixtest1 texttest',
'pdbk' => 'Talk:Dummy',
],
],
$link->interwikis
);
$this->assertCount( 0, $link->internals );
} else {
$this->assertArrayEquals(
[
1234 => [
9 => [
'title' => $title,
'text' => 'test3 prefixtest1 texttest',
'pdbk' => 'Talk:Dummy',
],
],
],
$link->internals
);
$this->assertCount( 0, $link->interwikis );
}
}
public function provideMakeHolder_withNsText() {
yield [
false,
'<!--LINK\'" 1234:9-->2 trail',
];
yield [
true,
'<!--IWLINK\'" 9-->2 trail',
];
}
}