2019-11-22 17:28:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
|
|
|
use Cite\CiteErrorReporter;
|
|
|
|
use Cite\ReferenceStack;
|
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use StripState;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \Cite\ReferenceStack
|
2019-11-27 10:08:00 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
|
|
|
class ReferenceStackTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
/**
|
2019-11-27 10:08:00 +00:00
|
|
|
* @covers ::__construct
|
2019-11-22 17:28:51 +00:00
|
|
|
* @covers ::pushInvalidRef
|
|
|
|
*/
|
|
|
|
public function testPushInvalidRef() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
$stack->pushInvalidRef();
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertSame( [ false ], $stack->refCallStack );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::pushRef
|
|
|
|
* @dataProvider providePushRef
|
|
|
|
*/
|
|
|
|
public function testPushRefs(
|
|
|
|
array $refs,
|
2019-11-26 14:44:14 +00:00
|
|
|
array $expectedOutputs,
|
2019-11-22 17:28:51 +00:00
|
|
|
array $finalRefs,
|
|
|
|
array $finalCallStack
|
|
|
|
) {
|
|
|
|
$mockStripState = $this->createMock( StripState::class );
|
|
|
|
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
2019-11-27 23:27:11 +00:00
|
|
|
[ $text, $name, $group, $extends, $follow, $argv, $dir ] = $refs[$i];
|
2019-11-22 17:28:51 +00:00
|
|
|
$result = $stack->pushRef(
|
2019-11-27 23:27:11 +00:00
|
|
|
$text, $name, $group, $extends, $follow, $argv, $dir, $mockStripState );
|
2019-11-22 17:28:51 +00:00
|
|
|
|
2019-11-29 22:08:51 +00:00
|
|
|
$this->assertTrue( array_key_exists( $i, $expectedOutputs ),
|
|
|
|
'Bad test, not enough expected outputs in fixture.' );
|
2019-11-22 17:28:51 +00:00
|
|
|
$this->assertSame( $expectedOutputs[$i], $result );
|
|
|
|
}
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertSame( $finalRefs, $stack->refs );
|
|
|
|
$this->assertSame( $finalCallStack, $stack->refCallStack );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providePushRef() {
|
|
|
|
return [
|
|
|
|
'Anonymous ref in default group' => [
|
|
|
|
[
|
2019-11-29 22:08:51 +00:00
|
|
|
[ 'text', null, '', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-29 22:08:51 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 22:08:51 +00:00
|
|
|
[ 'new', [], 'text', null, null, '', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous ref in named group' => [
|
|
|
|
[
|
2019-11-29 22:08:51 +00:00
|
|
|
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-29 22:08:51 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 22:08:51 +00:00
|
|
|
[ 'new', [], 'text', null, null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Ref with text' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text', null, null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named ref with text' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text', 'name', 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'name',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'name' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'name',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text', 'name', null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow after base' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text-b', 'b', 'foo', null, 'a', [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-a text-b',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow with no base' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text', null, 'foo', null, 'a', [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'follow' => 'a',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text', null, null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow pointing to later ref' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text-b', null, 'foo', null, 'c', [], 'rtl' ],
|
|
|
|
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
null,
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => 'c',
|
|
|
|
'text' => 'text-c',
|
|
|
|
'number' => 2,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-22 17:28:51 +00:00
|
|
|
'follow' => 'c',
|
|
|
|
],
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
'c' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 3,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'c',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-c',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 2,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text-b', null, null, 'foo', 2 ],
|
|
|
|
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
|
|
|
|
[ 'new', [], 'text-c', 'c', null, 'foo', 3 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, text in first tag' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ null, 'a', 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text', 'a', null, 'foo', 1 ],
|
|
|
|
[ 'increment', [], null, 'a', null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, text in second tag' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ null, 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => null,
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], null, 'a', null, 'foo', 1 ],
|
|
|
|
[ 'assign', [], 'text', 'a', null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, mismatched text' => [
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'text-1', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text-2', 'a', 'foo', null, null, [], 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-1',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-1 cite_error_references_duplicate_key',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-1 cite_error_references_duplicate_key',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-27 23:27:11 +00:00
|
|
|
[ 'new', [], 'text-1', 'a', null, 'foo', 1 ],
|
|
|
|
[ 'increment', [], 'text-2', 'a', null, 'foo', 1 ]
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
'Named extends with no parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
2019-11-29 11:50:07 +00:00
|
|
|
'b' => [
|
|
|
|
'number' => 1,
|
|
|
|
'__placeholder__' => true,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 11:50:07 +00:00
|
|
|
[ 'new', [], 'text-a', 'a', 'b', 'foo', 1 ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named extends before parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
|
|
|
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 11:50:07 +00:00
|
|
|
[ 'new', [], 'text-a', 'a', 'b', 'foo', 1 ],
|
2019-11-18 14:49:51 +00:00
|
|
|
[ 'new', [], 'text-b', 'b', null, 'foo', 2 ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named extends after parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text-b', 'b', 'foo', 'a', null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
|
|
|
|
[ 'new', [], 'text-b', 'b', 'a', 'foo', 2 ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends with no parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
2019-11-29 11:50:07 +00:00
|
|
|
'b' => [
|
|
|
|
'number' => 1,
|
|
|
|
'__placeholder__' => true,
|
|
|
|
]
|
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 11:50:07 +00:00
|
|
|
[ 'new', [], 'text-a', null, 'b', 'foo', 1 ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends before parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
|
|
|
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 11:50:07 +00:00
|
|
|
[ 'new', [], 'text-a', null, 'b', 'foo', 1 ],
|
2019-11-18 14:49:51 +00:00
|
|
|
[ 'new', [], 'text-b', 'b', null, 'foo', 2 ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends after parent' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', 'a', 'foo', null, null, [], 'rtl' ],
|
|
|
|
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'new', [], 'text-a', 'a', null, 'foo', 1 ],
|
|
|
|
[ 'new', [], 'text-b', null, 'a', 'foo', 2 ],
|
|
|
|
]
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
// TODO: @covers ::rollbackRefs
|
|
|
|
// TODO: @covers ::rollbackRef
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::clear
|
|
|
|
* @covers ::deleteGroup
|
|
|
|
*/
|
|
|
|
public function testRemovals() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refs = [ 'group1' => [], 'group2' => [] ];
|
|
|
|
|
|
|
|
$stack->deleteGroup( 'group1' );
|
|
|
|
$this->assertSame( [ 'group2' => [] ], $stack->refs );
|
|
|
|
|
|
|
|
$stack->clear();
|
|
|
|
$this->assertSame( [], $stack->refs );
|
|
|
|
}
|
|
|
|
|
2019-11-22 17:28:51 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getGroups
|
|
|
|
*/
|
|
|
|
public function testGetGroups() {
|
|
|
|
$stack = $this->newStack();
|
2019-11-27 10:08:00 +00:00
|
|
|
$stack->refs = [ 'havenot' => [], 'have' => [ [ 'ref etc' ] ] ];
|
2019-11-22 17:28:51 +00:00
|
|
|
|
|
|
|
$this->assertSame( [ 'have' ], $stack->getGroups() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::hasGroup
|
|
|
|
*/
|
|
|
|
public function testHasGroup() {
|
|
|
|
$stack = $this->newStack();
|
2019-11-27 10:08:00 +00:00
|
|
|
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
2019-11-22 17:28:51 +00:00
|
|
|
|
|
|
|
$this->assertFalse( $stack->hasGroup( 'absent' ) );
|
|
|
|
$this->assertTrue( $stack->hasGroup( 'present' ) );
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertFalse( $stack->hasGroup( 'empty' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getGroupRefs
|
|
|
|
*/
|
|
|
|
public function testGetGroupRefs() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
|
|
|
|
|
|
|
$this->assertSame( [], $stack->getGroupRefs( 'absent' ) );
|
|
|
|
$this->assertSame( [ [ 'ref etc' ] ], $stack->getGroupRefs( 'present' ) );
|
|
|
|
$this->assertSame( [], $stack->getGroupRefs( 'empty' ) );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::setRefText
|
|
|
|
*/
|
|
|
|
public function testSetRefText() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
$stack->setRefText( 'group', 'name', 'the-text' );
|
|
|
|
|
|
|
|
$this->assertSame(
|
2019-11-27 10:08:00 +00:00
|
|
|
[ 'group' => [ 'name' => [ 'text' => 'the-text' ] ] ],
|
|
|
|
$stack->refs
|
|
|
|
);
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
/**
|
|
|
|
* @return ReferenceStack
|
|
|
|
*/
|
2019-11-22 17:28:51 +00:00
|
|
|
private function newStack() {
|
|
|
|
$errorReporter = $this->createMock( CiteErrorReporter::class );
|
|
|
|
$errorReporter->method( 'plain' )->willReturnArgument( 0 );
|
2019-11-27 10:08:00 +00:00
|
|
|
$stack = new ReferenceStack( $errorReporter );
|
|
|
|
return TestingAccessWrapper::newFromObject( $stack );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|