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;
|
$this->mInCite = true;
|
||||||
$ret = $this->guardedRef( $text, $argv, $parser );
|
$ret = $this->guardedRef( $parser, $text, $argv );
|
||||||
$this->mInCite = false;
|
$this->mInCite = false;
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $text
|
* @param ?string $text
|
||||||
* @param string|null $name
|
* @param ?string $group
|
||||||
* @param string|null $group
|
* @param ?string $name
|
||||||
* @param string|null $follow
|
* @param ?string $extends
|
||||||
* @param string|null $extends
|
* @param ?string $follow
|
||||||
* @param string|null $dir
|
* @param ?string $dir
|
||||||
* @return StatusValue
|
* @return StatusValue
|
||||||
*/
|
*/
|
||||||
private function validateRef(
|
private function validateRef(
|
||||||
?string $text,
|
?string $text,
|
||||||
?string $name,
|
|
||||||
?string $group,
|
?string $group,
|
||||||
?string $follow,
|
?string $name,
|
||||||
?string $extends,
|
?string $extends,
|
||||||
|
?string $follow,
|
||||||
?string $dir
|
?string $dir
|
||||||
) : StatusValue {
|
) : StatusValue {
|
||||||
if ( ctype_digit( $name ) || ctype_digit( $follow ) || ctype_digit( $extends ) ) {
|
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
|
* TODO: Looks like this should be split into a section insensitive to context, and the
|
||||||
* special handling for each context.
|
* special handling for each context.
|
||||||
*
|
*
|
||||||
|
* @param Parser $parser
|
||||||
* @param string|null $text Raw content of the <ref> tag.
|
* @param string|null $text Raw content of the <ref> tag.
|
||||||
* @param string[] $argv Arguments
|
* @param string[] $argv Arguments
|
||||||
* @param Parser $parser
|
|
||||||
*
|
*
|
||||||
* @return string HTML
|
* @return string HTML
|
||||||
*/
|
*/
|
||||||
private function guardedRef(
|
private function guardedRef(
|
||||||
|
Parser $parser,
|
||||||
?string $text,
|
?string $text,
|
||||||
array $argv,
|
array $argv
|
||||||
Parser $parser
|
|
||||||
) : string {
|
) : string {
|
||||||
// Tag every page where Book Referencing has been used, whether or not the ref tag is valid.
|
// 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.
|
// 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(
|
$status = $this->parseArguments(
|
||||||
$argv,
|
$argv,
|
||||||
[ 'dir', self::BOOK_REF_ATTRIBUTE, 'follow', 'group', 'name' ]
|
[ 'group', 'name', self::BOOK_REF_ATTRIBUTE, 'follow', 'dir' ]
|
||||||
);
|
);
|
||||||
[
|
$arguments = $status->getValue();
|
||||||
'dir' => $dir,
|
|
||||||
self::BOOK_REF_ATTRIBUTE => $extends,
|
|
||||||
'follow' => $follow,
|
|
||||||
'group' => $group,
|
|
||||||
'name' => $name
|
|
||||||
] = $status->getValue();
|
|
||||||
|
|
||||||
// Use the default group, or the references group when inside one.
|
// Use the default group, or the references group when inside one.
|
||||||
if ( $group === null ) {
|
if ( $arguments['group'] === null ) {
|
||||||
$group = $this->inReferencesGroup ?? self::DEFAULT_GROUP;
|
$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
|
// Validation cares about the difference between null and empty, but from here on we don't
|
||||||
if ( $text !== null && trim( $text ) === '' ) {
|
if ( $text !== null && trim( $text ) === '' ) {
|
||||||
|
@ -369,7 +364,7 @@ class Cite {
|
||||||
# if there's any content, regardless of name.
|
# if there's any content, regardless of name.
|
||||||
|
|
||||||
$ref = $this->referenceStack->pushRef(
|
$ref = $this->referenceStack->pushRef(
|
||||||
$parser, $text, $name, $group, $extends, $follow, $argv, $dir, $parser->getStripState() );
|
$parser, $parser->getStripState(), $text, $argv, ...array_values( $arguments ) );
|
||||||
return $ref
|
return $ref
|
||||||
? $this->footnoteMarkFormatter->linkRef( $parser, $group, $ref )
|
? $this->footnoteMarkFormatter->linkRef( $parser, $group, $ref )
|
||||||
: '';
|
: '';
|
||||||
|
@ -453,8 +448,7 @@ class Cite {
|
||||||
|
|
||||||
# Rerun <ref> call now that mInReferences is set.
|
# Rerun <ref> call now that mInReferences is set.
|
||||||
foreach ( $redoStack as $call ) {
|
foreach ( $redoStack as $call ) {
|
||||||
[ $ref_argv, $ref_text ] = $call;
|
$this->guardedRef( $parser, ...$call );
|
||||||
$this->guardedRef( $ref_text, $ref_argv, $parser );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse $text to process any unparsed <ref> tags.
|
# 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>
|
* Populate $this->refs and $this->refCallStack based on input and arguments to <ref>
|
||||||
*
|
*
|
||||||
* @param Parser $parser
|
* @param Parser $parser
|
||||||
|
* @param StripState $stripState
|
||||||
* @param ?string $text Content from the <ref> tag
|
* @param ?string $text Content from the <ref> tag
|
||||||
* @param ?string $name
|
* @param string[] $argv
|
||||||
* @param string $group
|
* @param string $group
|
||||||
|
* @param ?string $name
|
||||||
* @param ?string $extends
|
* @param ?string $extends
|
||||||
* @param ?string $follow Guaranteed to not be a numeric string
|
* @param ?string $follow Guaranteed to not be a numeric string
|
||||||
* @param string[] $argv
|
|
||||||
* @param ?string $dir ref direction
|
* @param ?string $dir ref direction
|
||||||
* @param StripState $stripState
|
|
||||||
*
|
*
|
||||||
* @return ?array ref structure, or null if nothing was pushed
|
* @return ?array ref structure, or null if nothing was pushed
|
||||||
*/
|
*/
|
||||||
public function pushRef(
|
public function pushRef(
|
||||||
Parser $parser,
|
Parser $parser,
|
||||||
|
StripState $stripState,
|
||||||
?string $text,
|
?string $text,
|
||||||
?string $name,
|
array $argv,
|
||||||
string $group,
|
string $group,
|
||||||
|
?string $name,
|
||||||
?string $extends,
|
?string $extends,
|
||||||
?string $follow,
|
?string $follow,
|
||||||
array $argv,
|
?string $dir
|
||||||
?string $dir,
|
|
||||||
StripState $stripState
|
|
||||||
) : ?array {
|
) : ?array {
|
||||||
if ( !isset( $this->refs[$group] ) ) {
|
if ( !isset( $this->refs[$group] ) ) {
|
||||||
$this->refs[$group] = [];
|
$this->refs[$group] = [];
|
||||||
|
@ -165,7 +165,7 @@ class ReferenceStack {
|
||||||
// array index is constant, preventing O(N) searches.
|
// array index is constant, preventing O(N) searches.
|
||||||
array_splice( $this->refs[$group], $k, 0, [ $ref ] );
|
array_splice( $this->refs[$group], $k, 0, [ $ref ] );
|
||||||
array_splice( $this->refCallStack, $k, 0,
|
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
|
// A "follow" never gets its own footnote marker
|
||||||
return null;
|
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;
|
return $ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ class ReferenceStack {
|
||||||
* last few tags were actually inside of a references tag.
|
* last few tags were actually inside of a references tag.
|
||||||
*
|
*
|
||||||
* @param int $count
|
* @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 {
|
public function rollbackRefs( int $count ) : array {
|
||||||
$redoStack = [];
|
$redoStack = [];
|
||||||
|
|
|
@ -51,7 +51,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
$cite->inReferencesGroup = $inReferencesGroup;
|
$cite->inReferencesGroup = $inReferencesGroup;
|
||||||
$cite->isSectionPreview = $isSectionPreview;
|
$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 ) ) {
|
if ( is_string( $expected ) ) {
|
||||||
$this->assertSame( $expected, $status->getErrors()[0]['message'] );
|
$this->assertSame( $expected, $status->getErrors()[0]['message'] );
|
||||||
} else {
|
} else {
|
||||||
|
@ -281,7 +281,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
|
|
||||||
/** @var Cite $cite */
|
/** @var Cite $cite */
|
||||||
$cite = TestingAccessWrapper::newFromObject( $this->newCite() );
|
$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'] );
|
$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 = TestingAccessWrapper::newFromObject( $cite );
|
||||||
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
||||||
$spy->errorReporter->method( 'halfParsed' )->willReturnCallback(
|
$spy->errorReporter->method( 'halfParsed' )->willReturnCallback(
|
||||||
function ( $parser, ...$args ) {
|
function ( Parser $parser, ...$args ) {
|
||||||
return '(' . implode( '|', $args ) . ')';
|
return '(' . implode( '|', $args ) . ')';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -381,12 +381,10 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
||||||
$spy->referenceStack->method( 'popGroup' )
|
$spy->referenceStack->method( 'popGroup' )
|
||||||
->with( $expectedInReferencesGroup )->willReturn( [] );
|
->with( $expectedInReferencesGroup )->willReturn( [] );
|
||||||
if ( $expectedRollbackCount === 0 ) {
|
$spy->referenceStack->expects( $expectedRollbackCount ? $this->once() : $this->never() )
|
||||||
$spy->referenceStack->expects( $this->never() )->method( 'rollbackRefs' );
|
->method( 'rollbackRefs' )
|
||||||
} else {
|
->with( $expectedRollbackCount )
|
||||||
$spy->referenceStack->method( 'rollbackRefs' )
|
->willReturn( [ [ 't', [] ] ] );
|
||||||
->with( $expectedRollbackCount )->willReturn( [ [ [], 't' ] ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = $spy->guardedReferences( $text, $argv, $parser );
|
$output = $spy->guardedReferences( $text, $argv, $parser );
|
||||||
$this->assertSame( $expectedOutput, $output );
|
$this->assertSame( $expectedOutput, $output );
|
||||||
|
@ -500,13 +498,9 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$spy->referenceStack->method( 'pushRef' )->willReturnCallback(
|
$spy->referenceStack->method( 'pushRef' )->willReturnCallback(
|
||||||
function (
|
function ( Parser $parser, StripState $stripState, ...$arguments ) use ( &$pushedRefs ) {
|
||||||
$parser, $text, $name, $group, $extends, $follow, $argv, $dir, $_stripState
|
$pushedRefs[] = $arguments;
|
||||||
) use ( &$pushedRefs ) {
|
return [ 'name' => $arguments[1] ];
|
||||||
$pushedRefs[] = [ $text, $name, $group, $extends, $follow, $argv, $dir ];
|
|
||||||
return [
|
|
||||||
'name' => $name,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$spy->referenceStack->method( 'appendText' )->willReturnCallback(
|
$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( $expectOutput, $result );
|
||||||
$this->assertSame( $expectedErrors, $spy->mReferencesErrors );
|
$this->assertSame( $expectedErrors, $spy->mReferencesErrors );
|
||||||
$this->assertSame( $expectedRefs, $pushedRefs );
|
$this->assertSame( $expectedRefs, $pushedRefs );
|
||||||
|
@ -533,7 +527,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
'<foot />',
|
'<foot />',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
[ null, 'a', '', null, null, [ 'name' => 'a' ], null ]
|
[ null, [ 'name' => 'a' ], '', 'a', null, null, null ]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Empty in default references' => [
|
'Empty in default references' => [
|
||||||
|
@ -572,7 +566,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
'<foot />',
|
'<foot />',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
[ 'text', 'a', '', null, null, [ 'name' => 'a' ], null ]
|
[ 'text', [ 'name' => 'a' ], '', 'a', null, null, null ]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Invalid ref' => [
|
'Invalid ref' => [
|
||||||
|
@ -648,7 +642,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||||
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
||||||
$spy->referenceStack = $this->createMock( ReferenceStack::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 = $this->createMock( StripState::class );
|
||||||
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
||||||
|
/** @var StripState $mockStripState */
|
||||||
$stack = $this->newStack();
|
$stack = $this->newStack();
|
||||||
|
|
||||||
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
||||||
[ $text, $name, $group, $extends, $follow, $argv, $dir ] = $refs[$i];
|
|
||||||
$result = $stack->pushRef(
|
$result = $stack->pushRef(
|
||||||
$this->createMock( Parser::class ),
|
$this->createMock( Parser::class ),
|
||||||
$text, $name, $group, $extends, $follow, $argv, $dir, $mockStripState );
|
$mockStripState,
|
||||||
|
...$refs[$i]
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertTrue( array_key_exists( $i, $expectedOutputs ),
|
$this->assertTrue( array_key_exists( $i, $expectedOutputs ),
|
||||||
'Bad test, not enough expected outputs in fixture.' );
|
'Bad test, not enough expected outputs in fixture.' );
|
||||||
|
@ -61,7 +63,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
return [
|
return [
|
||||||
'Anonymous ref in default group' => [
|
'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' => [
|
'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' => [
|
'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' => [
|
'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' => [
|
'Follow after base' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', 'b', 'foo', null, 'a', [], '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' => [
|
'Follow with no base' => [
|
||||||
[
|
[
|
||||||
[ 'text', null, 'foo', null, 'a', [], 'rtl' ]
|
[ 'text', [], 'foo', null, null, 'a', 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
null
|
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' => [
|
'Follow pointing to later ref' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', null, 'foo', null, 'c', [], 'rtl' ],
|
[ 'text-b', [], 'foo', null, null, 'c', 'rtl' ],
|
||||||
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
|
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
@ -288,15 +290,15 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'new', 2, 'foo', null, null, [], 'text-b' ],
|
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
||||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||||
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
|
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Repeated ref, text in first tag' => [
|
'Repeated ref, text in first tag' => [
|
||||||
[
|
[
|
||||||
[ 'text', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ null, 'a', 'foo', null, null, [], 'rtl' ]
|
[ null, [], 'foo', 'a', null, null, 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
@ -329,14 +331,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'new', 1, 'foo', 'a', null, [], 'text' ],
|
[ 'new', 1, 'foo', 'a', null, 'text', [] ],
|
||||||
[ 'increment', 1, 'foo', 'a', null, [], null ],
|
[ 'increment', 1, 'foo', 'a', null, null, [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Repeated ref, text in second tag' => [
|
'Repeated ref, text in second tag' => [
|
||||||
[
|
[
|
||||||
[ null, 'a', 'foo', null, null, [], 'rtl' ],
|
[ null, [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
|
[ 'text', [], 'foo', 'a', null, null, 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
@ -369,14 +371,14 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'new', 1, 'foo', 'a', null, [], null ],
|
[ 'new', 1, 'foo', 'a', null, null, [] ],
|
||||||
[ 'assign', 1, 'foo', 'a', null, [], 'text' ],
|
[ 'assign', 1, 'foo', 'a', null, 'text', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Repeated ref, mismatched text' => [
|
'Repeated ref, mismatched text' => [
|
||||||
[
|
[
|
||||||
[ 'text-1', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-1', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-2', 'a', 'foo', 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' ],
|
[ 'new', 1, 'foo', 'a', null, 'text-1', [] ],
|
||||||
[ 'increment', 1, 'foo', 'a', null, [], 'text-2' ],
|
[ 'increment', 1, 'foo', 'a', null, 'text-2', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Named extends with no parent' => [
|
'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' => [
|
'Named extends before parent' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', 'b', null, 'rtl' ],
|
||||||
[ 'text-b', 'b', 'foo', null, 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', 1, 'foo', 'a', 'b', 'text-a', [] ],
|
||||||
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
|
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Named extends after parent' => [
|
'Named extends after parent' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', 'b', 'foo', 'a', 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', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||||
[ 'new', 2, 'foo', 'b', 'a', [], 'text-b' ],
|
[ 'new', 2, 'foo', 'b', 'a', 'text-b', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Anonymous extends with no parent' => [
|
'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' => [
|
'Anonymous extends before parent' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', null, 'b', null, 'rtl' ],
|
||||||
[ 'text-b', 'b', 'foo', null, 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', 1, 'foo', null, 'b', 'text-a', [] ],
|
||||||
[ 'new', 2, 'foo', 'b', null, [], 'text-b' ],
|
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Anonymous extends after parent' => [
|
'Anonymous extends after parent' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', null, 'foo', 'a', 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', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||||
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
|
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Normal after extends' => [
|
'Normal after extends' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
[ 'text-b', [], 'foo', null, 'a', null, 'rtl' ],
|
||||||
[ 'text-c', 'c', 'foo', null, 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', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||||
[ 'new', 2, 'foo', null, 'a', [], 'text-b' ],
|
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
||||||
[ 'new', 3, 'foo', 'c', null, [], 'text-c' ],
|
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Two broken follows' => [
|
'Two broken follows' => [
|
||||||
[
|
[
|
||||||
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
||||||
[ 'text-b', null, 'foo', null, 'd', [], 'rtl' ],
|
[ 'text-b', [], 'foo', null, null, 'd', 'rtl' ],
|
||||||
[ 'text-c', null, 'foo', 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', 2, 'foo', null, null, 'text-b', [] ],
|
||||||
[ 'new', 3, 'foo', null, null, [], 'text-c' ],
|
[ 'new', 3, 'foo', null, null, 'text-c', [] ],
|
||||||
[ 'new', 1, 'foo', 'a', null, [], 'text-a' ],
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -850,18 +852,18 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
'Skip invalid refs' => [ [ false ], [], 1, [], [] ],
|
'Skip invalid refs' => [ [ false ], [], 1, [], [] ],
|
||||||
'Missing group' => [
|
'Missing group' => [
|
||||||
[
|
[
|
||||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], 'text' ]
|
[ 'text', [] ]
|
||||||
],
|
],
|
||||||
[]
|
[]
|
||||||
],
|
],
|
||||||
'Find anonymous ref by key' => [
|
'Find anonymous ref by key' => [
|
||||||
[
|
[
|
||||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -872,13 +874,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], 'text' ]
|
[ 'text', [] ]
|
||||||
],
|
],
|
||||||
[]
|
[]
|
||||||
],
|
],
|
||||||
'Missing anonymous ref' => [
|
'Missing anonymous ref' => [
|
||||||
[
|
[
|
||||||
[ 'new', 1, 'foo', null, null, [], 'text' ],
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -889,7 +891,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], 'text' ]
|
[ 'text', [] ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -901,7 +903,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
'Assign text' => [
|
'Assign text' => [
|
||||||
[
|
[
|
||||||
[ 'assign', 1, 'foo', null, null, [], 'text-2' ],
|
[ 'assign', 1, 'foo', null, null, 'text-2', [] ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -914,7 +916,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], 'text-2' ]
|
[ 'text-2', [] ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -928,7 +930,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
'Increment' => [
|
'Increment' => [
|
||||||
[
|
[
|
||||||
[ 'increment', 1, 'foo', null, null, [], null ],
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -940,7 +942,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], null ]
|
[ null, [] ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -953,7 +955,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
'Safely ignore placeholder' => [
|
'Safely ignore placeholder' => [
|
||||||
[
|
[
|
||||||
[ 'increment', 1, 'foo', null, null, [], null ],
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -969,7 +971,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
[ [], null ]
|
[ null, [] ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -998,10 +1000,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||||
/** @var StripState $mockStripState */
|
/** @var StripState $mockStripState */
|
||||||
$stack->pushRef(
|
$stack->pushRef(
|
||||||
$this->createMock( Parser::class ),
|
$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'] );
|
$this->assertSame( 1, $stack->extendsCount['foo']['a'] );
|
||||||
|
|
||||||
$redo = $stack->rollbackRefs( 1 );
|
$stack->rollbackRefs( 1 );
|
||||||
|
|
||||||
$this->assertSame( 0, $stack->extendsCount['foo']['a'] );
|
$this->assertSame( 0, $stack->extendsCount['foo']['a'] );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue