mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 16:30:12 +00:00
More function call argument unpacking
I hope this patch is not to horrifying and can be reviewed. It's possible to split this into a sequence of smaller patches. Please tell me. Change-Id: I4797fcd5612fcffb0df6c29ff575dd05f278bd4d
This commit is contained in:
parent
347ad9fb5f
commit
028424a682
48
src/Cite.php
48
src/Cite.php
|
@ -131,27 +131,27 @@ class Cite {
|
|||
}
|
||||
|
||||
$this->mInCite = true;
|
||||
$ret = $this->guardedRef( $text, $argv, $parser );
|
||||
$ret = $this->guardedRef( $parser, $text, $argv );
|
||||
$this->mInCite = false;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $text
|
||||
* @param string|null $name
|
||||
* @param string|null $group
|
||||
* @param string|null $follow
|
||||
* @param string|null $extends
|
||||
* @param string|null $dir
|
||||
* @param ?string $text
|
||||
* @param ?string $group
|
||||
* @param ?string $name
|
||||
* @param ?string $extends
|
||||
* @param ?string $follow
|
||||
* @param ?string $dir
|
||||
* @return StatusValue
|
||||
*/
|
||||
private function validateRef(
|
||||
?string $text,
|
||||
?string $name,
|
||||
?string $group,
|
||||
?string $follow,
|
||||
?string $name,
|
||||
?string $extends,
|
||||
?string $follow,
|
||||
?string $dir
|
||||
) : StatusValue {
|
||||
if ( ctype_digit( $name ) || ctype_digit( $follow ) || ctype_digit( $extends ) ) {
|
||||
|
@ -279,16 +279,16 @@ class Cite {
|
|||
* TODO: Looks like this should be split into a section insensitive to context, and the
|
||||
* special handling for each context.
|
||||
*
|
||||
* @param Parser $parser
|
||||
* @param string|null $text Raw content of the <ref> tag.
|
||||
* @param string[] $argv Arguments
|
||||
* @param Parser $parser
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
private function guardedRef(
|
||||
Parser $parser,
|
||||
?string $text,
|
||||
array $argv,
|
||||
Parser $parser
|
||||
array $argv
|
||||
) : string {
|
||||
// Tag every page where Book Referencing has been used, whether or not the ref tag is valid.
|
||||
// This code and the page property will be removed once the feature is stable. See T237531.
|
||||
|
@ -298,22 +298,17 @@ class Cite {
|
|||
|
||||
$status = $this->parseArguments(
|
||||
$argv,
|
||||
[ 'dir', self::BOOK_REF_ATTRIBUTE, 'follow', 'group', 'name' ]
|
||||
[ 'group', 'name', self::BOOK_REF_ATTRIBUTE, 'follow', 'dir' ]
|
||||
);
|
||||
[
|
||||
'dir' => $dir,
|
||||
self::BOOK_REF_ATTRIBUTE => $extends,
|
||||
'follow' => $follow,
|
||||
'group' => $group,
|
||||
'name' => $name
|
||||
] = $status->getValue();
|
||||
|
||||
$arguments = $status->getValue();
|
||||
// Use the default group, or the references group when inside one.
|
||||
if ( $group === null ) {
|
||||
$group = $this->inReferencesGroup ?? self::DEFAULT_GROUP;
|
||||
if ( $arguments['group'] === null ) {
|
||||
$arguments['group'] = $this->inReferencesGroup ?? self::DEFAULT_GROUP;
|
||||
}
|
||||
|
||||
$status->merge( $this->validateRef( $text, $name, $group, $follow, $extends, $dir ) );
|
||||
[ 'group' => $group, 'name' => $name ] = $arguments;
|
||||
|
||||
$status->merge( $this->validateRef( $text, ...array_values( $arguments ) ) );
|
||||
|
||||
// Validation cares about the difference between null and empty, but from here on we don't
|
||||
if ( $text !== null && trim( $text ) === '' ) {
|
||||
|
@ -369,7 +364,7 @@ class Cite {
|
|||
# if there's any content, regardless of name.
|
||||
|
||||
$ref = $this->referenceStack->pushRef(
|
||||
$parser, $text, $name, $group, $extends, $follow, $argv, $dir, $parser->getStripState() );
|
||||
$parser, $parser->getStripState(), $text, $argv, ...array_values( $arguments ) );
|
||||
return $ref
|
||||
? $this->footnoteMarkFormatter->linkRef( $parser, $group, $ref )
|
||||
: '';
|
||||
|
@ -453,8 +448,7 @@ class Cite {
|
|||
|
||||
# Rerun <ref> call now that mInReferences is set.
|
||||
foreach ( $redoStack as $call ) {
|
||||
[ $ref_argv, $ref_text ] = $call;
|
||||
$this->guardedRef( $ref_text, $ref_argv, $parser );
|
||||
$this->guardedRef( $parser, ...$call );
|
||||
}
|
||||
|
||||
# Parse $text to process any unparsed <ref> tags.
|
||||
|
|
|
@ -106,27 +106,27 @@ class ReferenceStack {
|
|||
* Populate $this->refs and $this->refCallStack based on input and arguments to <ref>
|
||||
*
|
||||
* @param Parser $parser
|
||||
* @param StripState $stripState
|
||||
* @param ?string $text Content from the <ref> tag
|
||||
* @param ?string $name
|
||||
* @param string[] $argv
|
||||
* @param string $group
|
||||
* @param ?string $name
|
||||
* @param ?string $extends
|
||||
* @param ?string $follow Guaranteed to not be a numeric string
|
||||
* @param string[] $argv
|
||||
* @param ?string $dir ref direction
|
||||
* @param StripState $stripState
|
||||
*
|
||||
* @return ?array ref structure, or null if nothing was pushed
|
||||
*/
|
||||
public function pushRef(
|
||||
Parser $parser,
|
||||
StripState $stripState,
|
||||
?string $text,
|
||||
?string $name,
|
||||
array $argv,
|
||||
string $group,
|
||||
?string $name,
|
||||
?string $extends,
|
||||
?string $follow,
|
||||
array $argv,
|
||||
?string $dir,
|
||||
StripState $stripState
|
||||
?string $dir
|
||||
) : ?array {
|
||||
if ( !isset( $this->refs[$group] ) ) {
|
||||
$this->refs[$group] = [];
|
||||
|
@ -165,7 +165,7 @@ class ReferenceStack {
|
|||
// array index is constant, preventing O(N) searches.
|
||||
array_splice( $this->refs[$group], $k, 0, [ $ref ] );
|
||||
array_splice( $this->refCallStack, $k, 0,
|
||||
[ [ 'new', $this->refSequence, $group, $name, $extends, $argv, $text ] ] );
|
||||
[ [ 'new', $this->refSequence, $group, $name, $extends, $text, $argv ] ] );
|
||||
|
||||
// A "follow" never gets its own footnote marker
|
||||
return null;
|
||||
|
@ -238,7 +238,7 @@ class ReferenceStack {
|
|||
}
|
||||
}
|
||||
|
||||
$this->refCallStack[] = [ $action, $ref['key'], $group, $name, $extends, $argv, $text ];
|
||||
$this->refCallStack[] = [ $action, $ref['key'], $group, $name, $extends, $text, $argv ];
|
||||
return $ref;
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ class ReferenceStack {
|
|||
* last few tags were actually inside of a references tag.
|
||||
*
|
||||
* @param int $count
|
||||
* @return array[] Refs to restore under the correct context, as a list of [ $argv, $text ]
|
||||
* @return array[] Refs to restore under the correct context, as a list of [ $text, $argv ]
|
||||
*/
|
||||
public function rollbackRefs( int $count ) : array {
|
||||
$redoStack = [];
|
||||
|
|
|
@ -51,7 +51,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
$cite->inReferencesGroup = $inReferencesGroup;
|
||||
$cite->isSectionPreview = $isSectionPreview;
|
||||
|
||||
$status = $cite->validateRef( $text, $name, $group, $follow, $extends, $dir );
|
||||
$status = $cite->validateRef( $text, $group, $name, $extends, $follow, $dir );
|
||||
if ( is_string( $expected ) ) {
|
||||
$this->assertSame( $expected, $status->getErrors()[0]['message'] );
|
||||
} else {
|
||||
|
@ -281,7 +281,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( $this->newCite() );
|
||||
$status = $cite->validateRef( 'text', 'name', '', null, 'a', null );
|
||||
$status = $cite->validateRef( 'text', '', 'name', 'a', null, null );
|
||||
$this->assertSame( 'cite_error_ref_too_many_keys', $status->getErrors()[0]['message'] );
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
||||
$spy->errorReporter->method( 'halfParsed' )->willReturnCallback(
|
||||
function ( $parser, ...$args ) {
|
||||
function ( Parser $parser, ...$args ) {
|
||||
return '(' . implode( '|', $args ) . ')';
|
||||
}
|
||||
);
|
||||
|
@ -381,12 +381,10 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
||||
$spy->referenceStack->method( 'popGroup' )
|
||||
->with( $expectedInReferencesGroup )->willReturn( [] );
|
||||
if ( $expectedRollbackCount === 0 ) {
|
||||
$spy->referenceStack->expects( $this->never() )->method( 'rollbackRefs' );
|
||||
} else {
|
||||
$spy->referenceStack->method( 'rollbackRefs' )
|
||||
->with( $expectedRollbackCount )->willReturn( [ [ [], 't' ] ] );
|
||||
}
|
||||
$spy->referenceStack->expects( $expectedRollbackCount ? $this->once() : $this->never() )
|
||||
->method( 'rollbackRefs' )
|
||||
->with( $expectedRollbackCount )
|
||||
->willReturn( [ [ 't', [] ] ] );
|
||||
|
||||
$output = $spy->guardedReferences( $text, $argv, $parser );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
|
@ -500,13 +498,9 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
);
|
||||
$spy->referenceStack->method( 'pushRef' )->willReturnCallback(
|
||||
function (
|
||||
$parser, $text, $name, $group, $extends, $follow, $argv, $dir, $_stripState
|
||||
) use ( &$pushedRefs ) {
|
||||
$pushedRefs[] = [ $text, $name, $group, $extends, $follow, $argv, $dir ];
|
||||
return [
|
||||
'name' => $name,
|
||||
];
|
||||
function ( Parser $parser, StripState $stripState, ...$arguments ) use ( &$pushedRefs ) {
|
||||
$pushedRefs[] = $arguments;
|
||||
return [ 'name' => $arguments[1] ];
|
||||
}
|
||||
);
|
||||
$spy->referenceStack->method( 'appendText' )->willReturnCallback(
|
||||
|
@ -515,7 +509,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
$result = $spy->guardedRef( $text, $argv, $mockParser );
|
||||
$result = $spy->guardedRef( $mockParser, $text, $argv );
|
||||
$this->assertSame( $expectOutput, $result );
|
||||
$this->assertSame( $expectedErrors, $spy->mReferencesErrors );
|
||||
$this->assertSame( $expectedRefs, $pushedRefs );
|
||||
|
@ -533,7 +527,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
'<foot />',
|
||||
[],
|
||||
[
|
||||
[ null, 'a', '', null, null, [ 'name' => 'a' ], null ]
|
||||
[ null, [ 'name' => 'a' ], '', 'a', null, null, null ]
|
||||
]
|
||||
],
|
||||
'Empty in default references' => [
|
||||
|
@ -572,7 +566,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
'<foot />',
|
||||
[],
|
||||
[
|
||||
[ 'text', 'a', '', null, null, [ 'name' => 'a' ], null ]
|
||||
[ 'text', [ 'name' => 'a' ], '', 'a', null, null, null ]
|
||||
]
|
||||
],
|
||||
'Invalid ref' => [
|
||||
|
@ -648,7 +642,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
||||
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
||||
|
||||
$spy->guardedRef( 'text', [ Cite::BOOK_REF_ATTRIBUTE => 'a' ], $mockParser );
|
||||
$spy->guardedRef( $mockParser, 'text', [ Cite::BOOK_REF_ATTRIBUTE => 'a' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,13 +40,15 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
) {
|
||||
$mockStripState = $this->createMock( StripState::class );
|
||||
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
||||
/** @var StripState $mockStripState */
|
||||
$stack = $this->newStack();
|
||||
|
||||
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
||||
[ $text, $name, $group, $extends, $follow, $argv, $dir ] = $refs[$i];
|
||||
$result = $stack->pushRef(
|
||||
$this->createMock( Parser::class ),
|
||||
$text, $name, $group, $extends, $follow, $argv, $dir, $mockStripState );
|
||||
$mockStripState,
|
||||
...$refs[$i]
|
||||
);
|
||||
|
||||
$this->assertTrue( array_key_exists( $i, $expectedOutputs ),
|
||||
'Bad test, not enough expected outputs in fixture.' );
|
||||
|
@ -61,7 +63,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
return [
|
||||
'Anonymous ref in default group' => [
|
||||
[
|
||||
[ 'text', null, '', null, null, [], 'rtl' ]
|
||||
[ 'text', [], '', null, null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -86,12 +88,12 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, '', null, null, [], 'text' ],
|
||||
[ 'new', 1, '', null, null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Anonymous ref in named group' => [
|
||||
[
|
||||
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text', [], 'foo', null, null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -116,12 +118,12 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Ref with text' => [
|
||||
[
|
||||
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text', [], 'foo', null, null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -146,12 +148,12 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Named ref with text' => [
|
||||
[
|
||||
[ 'text', 'name', 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text', [], 'foo', 'name', null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -176,13 +178,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'name', null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', 'name', null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Follow after base' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', 'b', 'foo', null, 'a', [], 'rtl' ]
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', 'b', null, 'a', 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -208,12 +210,12 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
]
|
||||
],
|
||||
'Follow with no base' => [
|
||||
[
|
||||
[ 'text', null, 'foo', null, 'a', [], 'rtl' ]
|
||||
[ 'text', [], 'foo', null, null, 'a', 'rtl' ]
|
||||
],
|
||||
[
|
||||
null
|
||||
|
@ -231,14 +233,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Follow pointing to later ref' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', null, 'foo', null, 'c', [], 'rtl' ],
|
||||
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', null, null, 'c', 'rtl' ],
|
||||
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -288,15 +290,15 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 2, 'foo', null, null, [], 'text-b' ],
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
|
||||
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
||||
]
|
||||
],
|
||||
'Repeated ref, text in first tag' => [
|
||||
[
|
||||
[ 'text', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ null, 'a', 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ null, [], 'foo', 'a', null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -329,14 +331,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text' ],
|
||||
[ 'increment', 1, 'foo', 'a', null, [], null ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text', [] ],
|
||||
[ 'increment', 1, 'foo', 'a', null, null, [] ],
|
||||
]
|
||||
],
|
||||
'Repeated ref, text in second tag' => [
|
||||
[
|
||||
[ null, 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
|
||||
[ null, [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text', [], 'foo', 'a', null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -369,14 +371,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], null ],
|
||||
[ 'assign', 1, 'foo', 'a', null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', 'a', null, null, [] ],
|
||||
[ 'assign', 1, 'foo', 'a', null, 'text', [] ],
|
||||
]
|
||||
],
|
||||
'Repeated ref, mismatched text' => [
|
||||
[
|
||||
[ 'text-1', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-2', 'a', 'foo', null, null, [], 'rtl' ]
|
||||
[ 'text-1', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-2', [], 'foo', 'a', null, null, 'rtl' ]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -409,13 +411,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-1' ],
|
||||
[ 'increment', 1, 'foo', 'a', null, [], 'text-2' ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-1', [] ],
|
||||
[ 'increment', 1, 'foo', 'a', null, 'text-2', [] ],
|
||||
]
|
||||
],
|
||||
'Named extends with no parent' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', 'b', null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -448,13 +450,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', 'b', [], 'text-a' ],
|
||||
[ 'new', 1, 'foo', 'a', 'b', 'text-a', [] ],
|
||||
]
|
||||
],
|
||||
'Named extends before parent' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
||||
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', 'b', null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', 'b', null, null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -499,14 +501,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', 'b', [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
|
||||
[ 'new', 1, 'foo', 'a', 'b', 'text-a', [] ],
|
||||
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
||||
]
|
||||
],
|
||||
'Named extends after parent' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', 'b', 'foo', 'a', null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', 'b', 'a', null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -551,13 +553,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', 'b', 'a', [], 'text-b' ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
[ 'new', 2, 'foo', 'b', 'a', 'text-b', [] ],
|
||||
]
|
||||
],
|
||||
'Anonymous extends with no parent' => [
|
||||
[
|
||||
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', null, 'b', null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -590,13 +592,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', null, 'b', [], 'text-a' ],
|
||||
[ 'new', 1, 'foo', null, 'b', 'text-a', [] ],
|
||||
]
|
||||
],
|
||||
'Anonymous extends before parent' => [
|
||||
[
|
||||
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
||||
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', null, 'b', null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', 'b', null, null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -641,14 +643,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', null, 'b', [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
|
||||
[ 'new', 1, 'foo', null, 'b', 'text-a', [] ],
|
||||
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
||||
]
|
||||
],
|
||||
'Anonymous extends after parent' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', null, 'a', null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -693,15 +695,15 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
||||
]
|
||||
],
|
||||
'Normal after extends' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
||||
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', null, 'a', null, 'rtl' ],
|
||||
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -762,16 +764,16 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
|
||||
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
||||
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
||||
]
|
||||
],
|
||||
'Two broken follows' => [
|
||||
[
|
||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
||||
[ 'text-b', null, 'foo', null, 'd', [], 'rtl' ],
|
||||
[ 'text-c', null, 'foo', null, 'd', [], 'rtl' ],
|
||||
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||
[ 'text-b', [], 'foo', null, null, 'd', 'rtl' ],
|
||||
[ 'text-c', [], 'foo', null, null, 'd', 'rtl' ],
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -814,9 +816,9 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
[ 'new', 2, 'foo', null, null, [], 'text-b' ],
|
||||
[ 'new', 3, 'foo', null, null, [], 'text-c' ],
|
||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
||||
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
||||
[ 'new', 3, 'foo', null, null, 'text-c', [] ],
|
||||
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
@ -850,18 +852,18 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
'Skip invalid refs' => [ [ false ], [], 1, [], [] ],
|
||||
'Missing group' => [
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
],
|
||||
[],
|
||||
1,
|
||||
[
|
||||
[ [], 'text' ]
|
||||
[ 'text', [] ]
|
||||
],
|
||||
[]
|
||||
],
|
||||
'Find anonymous ref by key' => [
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -872,13 +874,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
1,
|
||||
[
|
||||
[ [], 'text' ]
|
||||
[ 'text', [] ]
|
||||
],
|
||||
[]
|
||||
],
|
||||
'Missing anonymous ref' => [
|
||||
[
|
||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
||||
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -889,7 +891,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
1,
|
||||
[
|
||||
[ [], 'text' ]
|
||||
[ 'text', [] ]
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -901,7 +903,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
'Assign text' => [
|
||||
[
|
||||
[ 'assign', 1, 'foo', null, null, [], 'text-2' ],
|
||||
[ 'assign', 1, 'foo', null, null, 'text-2', [] ],
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -914,7 +916,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
1,
|
||||
[
|
||||
[ [], 'text-2' ]
|
||||
[ 'text-2', [] ]
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -928,7 +930,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
'Increment' => [
|
||||
[
|
||||
[ 'increment', 1, 'foo', null, null, [], null ],
|
||||
[ 'increment', 1, 'foo', null, null, null, [] ],
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -940,7 +942,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
1,
|
||||
[
|
||||
[ [], null ]
|
||||
[ null, [] ]
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -953,7 +955,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
'Safely ignore placeholder' => [
|
||||
[
|
||||
[ 'increment', 1, 'foo', null, null, [], null ],
|
||||
[ 'increment', 1, 'foo', null, null, null, [] ],
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -969,7 +971,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
],
|
||||
1,
|
||||
[
|
||||
[ [], null ]
|
||||
[ null, [] ]
|
||||
],
|
||||
[
|
||||
'foo' => [
|
||||
|
@ -998,10 +1000,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
/** @var StripState $mockStripState */
|
||||
$stack->pushRef(
|
||||
$this->createMock( Parser::class ),
|
||||
'text', null, 'foo', 'a', null, [], 'rtl', $mockStripState );
|
||||
$mockStripState,
|
||||
'text', [],
|
||||
'foo', null, 'a', null, 'rtl'
|
||||
);
|
||||
$this->assertSame( 1, $stack->extendsCount['foo']['a'] );
|
||||
|
||||
$redo = $stack->rollbackRefs( 1 );
|
||||
$stack->rollbackRefs( 1 );
|
||||
|
||||
$this->assertSame( 0, $stack->extendsCount['foo']['a'] );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue